Skip to content

Commit

Permalink
Add GitHub metadata as AWS Tags
Browse files Browse the repository at this point in the history
Signed-off-by: shiva kumar <shivaku@nvidia.com>
  • Loading branch information
shivakunv committed Dec 19, 2024
1 parent f478ba5 commit f1a0a0f
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
21 changes: 21 additions & 0 deletions pkg/provider/aws/aws.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,19 @@ func New(log *logger.FunLogger, env v1alpha1.Environment, cacheFile string) (*Pr
if envRegion := os.Getenv("AWS_REGION"); envRegion != "" {
region = envRegion
}
commitSHA := os.Getenv("GITHUB_SHA")
// short sha
if len(commitSHA) > 8 {
commitSHA = commitSHA[:8]
}
actor := os.Getenv("GITHUB_ACTOR")
branch := os.Getenv("GITHUB_REF_NAME")
repoName := os.Getenv("GITHUB_REPOSITORY")
gitHubRunId := os.Getenv("GITHUB_RUN_ID")
gitHubRunNumber := os.Getenv("GITHUB_RUN_NUMBER")
gitHubJob := os.Getenv("GITHUB_JOB")
gitHubRunAttempt := os.Getenv("GITHUB_RUN_ATTEMPT")

cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion(region))
if err != nil {
return nil, err
Expand All @@ -100,6 +113,14 @@ func New(log *logger.FunLogger, env v1alpha1.Environment, cacheFile string) (*Pr
{Key: aws.String("Name"), Value: aws.String(env.Name)},
{Key: aws.String("Project"), Value: aws.String("holodeck")},
{Key: aws.String("Environment"), Value: aws.String("cicd")},
{Key: aws.String("CommitSHA"), Value: aws.String(commitSHA)},
{Key: aws.String("Actor"), Value: aws.String(actor)},
{Key: aws.String("Branch"), Value: aws.String(branch)},
{Key: aws.String("GitHubRepository"), Value: aws.String(repoName)},
{Key: aws.String("GitHubRunId"), Value: aws.String(gitHubRunId)},
{Key: aws.String("GitHubRunNumber"), Value: aws.String(gitHubRunNumber)},
{Key: aws.String("GitHubJob"), Value: aws.String(gitHubJob)},
{Key: aws.String("GitHubRunAttempt"), Value: aws.String(gitHubRunAttempt)},
},
client,
r53,
Expand Down
20 changes: 19 additions & 1 deletion pkg/provider/aws/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,14 @@ func (p *Provider) createInternetGateway(cache *AWS) error {
p.log.Wg.Add(1)
go p.log.Loading("Creating Internet Gateway")

gwInput := &ec2.CreateInternetGatewayInput{}
gwInput := &ec2.CreateInternetGatewayInput{
TagSpecifications: []types.TagSpecification{
{
ResourceType: types.ResourceTypeInternetGateway,
Tags: p.Tags,
},
},
}
gwOutput, err := p.ec2.CreateInternetGateway(context.TODO(), gwInput)
if err != nil {
p.fail()
Expand Down Expand Up @@ -357,6 +364,17 @@ func (p *Provider) createEC2Instance(cache *AWS) error {
}
cache.PublicDnsName = *instanceRunning.Reservations[0].Instances[0].PublicDnsName

// tag network interface
instance := instanceOut.Instances[0]
networkInterfaceId := *instance.NetworkInterfaces[0].NetworkInterfaceId
_, err = p.ec2.CreateTags(context.TODO(), &ec2.CreateTagsInput{
Resources: []string{networkInterfaceId},
Tags: p.Tags,
})
if err != nil {
p.fail()
return fmt.Errorf("Fail to tag network to instance: %v", err)
}
p.done()
return nil
}

0 comments on commit f1a0a0f

Please sign in to comment.