diff --git a/pkg/config/config.go b/pkg/config/config.go index 6a19a8b..0babcd7 100644 --- a/pkg/config/config.go +++ b/pkg/config/config.go @@ -74,6 +74,7 @@ type RequestInstanceInfo struct { LaunchTemplateBlockMappings []*ec2.LaunchTemplateBlockDeviceMappingRequest InstanceInitiatedShutdownBehavior *string UserData *string + LaunchTemplateTagSpecs []*ec2.LaunchTemplateTagSpecificationRequest } func NewSimpleInfo() *SimpleInfo { diff --git a/pkg/ec2helper/ec2helper.go b/pkg/ec2helper/ec2helper.go index c4f0a33..3df0aac 100644 --- a/pkg/ec2helper/ec2helper.go +++ b/pkg/ec2helper/ec2helper.go @@ -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)), @@ -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, <TagSpec) + } + } setAutoTermination := false if detailedConfig != nil {