diff --git a/pkg/provider/aws/aws.go b/pkg/provider/aws/aws.go index d833cfd0..abd2806c 100644 --- a/pkg/provider/aws/aws.go +++ b/pkg/provider/aws/aws.go @@ -87,6 +87,19 @@ 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") + 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 @@ -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(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)}, + {Key: aws.String("GitHubRunAttempt"), Value: aws.String(gitHubRunAttempt)}, }, 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 }