diff --git a/pkg/provider/aws/aws.go b/pkg/provider/aws/aws.go index d833cfd0..60799b0c 100644 --- a/pkg/provider/aws/aws.go +++ b/pkg/provider/aws/aws.go @@ -19,6 +19,7 @@ package aws import ( "context" "os" + "strings" "github.com/NVIDIA/holodeck/api/holodeck/v1alpha1" "github.com/NVIDIA/holodeck/internal/logger" @@ -87,6 +88,20 @@ func New(log *logger.FunLogger, env v1alpha1.Environment, cacheFile string) (*Pr if envRegion := os.Getenv("AWS_REGION"); envRegion != "" { region = envRegion } + sha := os.Getenv("GITHUB_SHA") + // short sha + if len(sha) > 8 { + sha = sha[:8] + } + actor := os.Getenv("GITHUB_ACTOR") + branch := os.Getenv("GITHUB_REF_NAME") + repo_name := os.Getenv("GITHUB_REPOSITORY") + parts := strings.Split(repo_name, "/") + repoName := parts[len(parts)-1] + githubRunId := os.Getenv("GITHUB_RUN_ID") + githubRunNumber := os.Getenv("GITHUB_RUN_NUMBER") + githubJob := os.Getenv("GITHUB_JOB") + cfg, err := config.LoadDefaultConfig(context.TODO(), config.WithRegion(region)) if err != nil { return nil, err @@ -100,6 +115,13 @@ 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("Sha"), Value: aws.String(sha)}, + {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)}, }, client, r53, diff --git a/pkg/provider/aws/create.go b/pkg/provider/aws/create.go index 184225a6..5b274d36 100644 --- a/pkg/provider/aws/create.go +++ b/pkg/provider/aws/create.go @@ -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() @@ -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 }