Skip to content

Commit

Permalink
Set tags on instance when using a new Launch Template (#89)
Browse files Browse the repository at this point in the history
This includes both Simple-EC2 default tags and user-specified tags. Note
that some default launch template tags are already being included; we
make no effort to remove those.
  • Loading branch information
snay2 authored Aug 10, 2022
1 parent 3175a22 commit 87bac4d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ type RequestInstanceInfo struct {
LaunchTemplateBlockMappings []*ec2.LaunchTemplateBlockDeviceMappingRequest
InstanceInitiatedShutdownBehavior *string
UserData *string
LaunchTemplateTagSpecs []*ec2.LaunchTemplateTagSpecificationRequest
}

func NewSimpleInfo() *SimpleInfo {
Expand Down
11 changes: 11 additions & 0 deletions pkg/ec2helper/ec2helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -1329,6 +1329,7 @@ func (h *EC2Helper) CreateLaunchTemplate(simpleConfig *config.SimpleInfo, detail
BlockDeviceMappings: dataConfig.LaunchTemplateBlockMappings,
InstanceInitiatedShutdownBehavior: dataConfig.InstanceInitiatedShutdownBehavior,
UserData: dataConfig.UserData,
TagSpecifications: dataConfig.LaunchTemplateTagSpecs,
},
LaunchTemplateName: aws.String(fmt.Sprintf("SimpleEC2LaunchTemplate-%s", launchIdentifier)),
VersionDescription: aws.String(fmt.Sprintf("Launch Template %s", launchIdentifier)),
Expand Down Expand Up @@ -1365,6 +1366,16 @@ func createRequestInstanceConfig(simpleConfig *config.SimpleInfo, detailedConfig
Name: aws.String(simpleConfig.IamInstanceProfile),
}
}
if detailedConfig.TagSpecs != nil {
requestInstanceConfig.LaunchTemplateTagSpecs = []*ec2.LaunchTemplateTagSpecificationRequest{}
for _, tagSpec := range detailedConfig.TagSpecs {
ltTagSpec := ec2.LaunchTemplateTagSpecificationRequest{
ResourceType: aws.String("instance"),
Tags: tagSpec.Tags,
}
requestInstanceConfig.LaunchTemplateTagSpecs = append(requestInstanceConfig.LaunchTemplateTagSpecs, &ltTagSpec)
}
}

setAutoTermination := false
if detailedConfig != nil {
Expand Down

0 comments on commit 87bac4d

Please sign in to comment.