@@ -358,7 +358,7 @@ func (e EC2Client) ValidateSecurityGroupsConfig(securityGroups []*string, primar
358358}
359359
360360// CreateNewLaunchTemplate creates a new launch template
361- func (e EC2Client ) CreateNewLaunchTemplate (name , ami , instanceType , keyName , iamProfileName , userdata string , ebsOptimized , mixedInstancePolicyEnabled bool , securityGroups []* string , blockDevices []* ec2.LaunchTemplateBlockDeviceMappingRequest , instanceMarketOptions * schemas.InstanceMarketOptions , detailedMonitoringEnabled bool , primaryENI * schemas.ENIConfig , secondaryENIs []* schemas.ENIConfig ) error {
361+ func (e EC2Client ) CreateNewLaunchTemplate (name , ami , instanceType , keyName , iamProfileName , userdata string , ebsOptimized , mixedInstancePolicyEnabled bool , securityGroups []* string , blockDevices []* ec2.LaunchTemplateBlockDeviceMappingRequest , instanceMarketOptions * schemas.InstanceMarketOptions , detailedMonitoringEnabled bool , primaryENI * schemas.ENIConfig , secondaryENIs []* schemas.ENIConfig , tags [] string ) error {
362362 // Validate security group configuration
363363 if err := e .ValidateSecurityGroupsConfig (securityGroups , primaryENI , secondaryENIs ); err != nil {
364364 return err
@@ -385,6 +385,26 @@ func (e EC2Client) CreateNewLaunchTemplate(name, ami, instanceType, keyName, iam
385385 LaunchTemplateName : aws .String (name ),
386386 }
387387
388+ // Add resource tags if provided
389+ if len (tags ) > 0 {
390+ var tagSpecs []* ec2.LaunchTemplateTagSpecificationRequest
391+ var ec2Tags []* ec2.Tag
392+ for _ , tag := range tags {
393+ parts := strings .Split (tag , "=" )
394+ if len (parts ) == 2 {
395+ ec2Tags = append (ec2Tags , & ec2.Tag {
396+ Key : aws .String (parts [0 ]),
397+ Value : aws .String (parts [1 ]),
398+ })
399+ }
400+ }
401+ tagSpecs = append (tagSpecs , & ec2.LaunchTemplateTagSpecificationRequest {
402+ ResourceType : aws .String ("volume" ),
403+ Tags : ec2Tags ,
404+ })
405+ input .LaunchTemplateData .SetTagSpecifications (tagSpecs )
406+ }
407+
388408 if len (blockDevices ) > 0 {
389409 input .LaunchTemplateData .SetBlockDeviceMappings (blockDevices )
390410 }
@@ -539,7 +559,7 @@ func (e EC2Client) MakeBlockDevices(blocks []schemas.BlockDevice) []*autoscaling
539559
540560 for _ , block := range blocks {
541561 enabledEBSEncrypted := block .Encrypted
542-
562+ Logger . Infof ( "Encrypt ebs %t" , enabledEBSEncrypted )
543563 var ebsDevice * autoscaling.Ebs
544564
545565 if enabledEBSEncrypted {
@@ -556,6 +576,7 @@ func (e EC2Client) MakeBlockDevices(blocks []schemas.BlockDevice) []*autoscaling
556576 DeleteOnTermination : aws .Bool (block .DeleteOnTermination ),
557577 }
558578 }
579+ Logger .Infof ("ebs %s" , ebsDevice )
559580
560581 if len (block .SnapshotID ) > 0 {
561582 if ! isValidSnapshotID (block .SnapshotID ) {
@@ -569,6 +590,7 @@ func (e EC2Client) MakeBlockDevices(blocks []schemas.BlockDevice) []*autoscaling
569590 DeviceName : aws .String (block .DeviceName ),
570591 Ebs : ebsDevice ,
571592 }
593+ Logger .Infof ("tmp %s" , tmp )
572594
573595 if block .VolumeType == "io1" || block .VolumeType == "io2" {
574596 tmp .Ebs .Iops = aws .Int64 (block .Iops )
@@ -590,18 +612,16 @@ func (e EC2Client) MakeLaunchTemplateBlockDeviceMappings(blocks []schemas.BlockD
590612 var LaunchTemplateEbsBlockDevice * ec2.LaunchTemplateEbsBlockDeviceRequest
591613
592614 if enabledEBSEncrypted {
593- if len (block .KmsAlias ) > 0 {
594- keyId , err := e .getKmsKeyIdByAlias (block .KmsAlias )
595- if err != nil {
596- Logger .Fatal (fmt .Sprintf ("Error: %s" , err .Error ()))
597- }
598- LaunchTemplateEbsBlockDevice = & ec2.LaunchTemplateEbsBlockDeviceRequest {
599- VolumeSize : aws .Int64 (block .VolumeSize ),
600- VolumeType : aws .String (block .VolumeType ),
601- Encrypted : aws .Bool (enabledEBSEncrypted ),
602- KmsKeyId : aws .String (keyId ),
603- DeleteOnTermination : aws .Bool (block .DeleteOnTermination ),
604- }
615+ keyId , err := e .getKmsKeyIdByAlias (block .KmsAlias )
616+ if err != nil {
617+ Logger .Fatal (fmt .Sprintf ("Error: %s" , err .Error ()))
618+ }
619+ LaunchTemplateEbsBlockDevice = & ec2.LaunchTemplateEbsBlockDeviceRequest {
620+ VolumeSize : aws .Int64 (block .VolumeSize ),
621+ VolumeType : aws .String (block .VolumeType ),
622+ Encrypted : aws .Bool (enabledEBSEncrypted ),
623+ KmsKeyId : aws .String (keyId ),
624+ DeleteOnTermination : aws .Bool (block .DeleteOnTermination ),
605625 }
606626 } else {
607627 LaunchTemplateEbsBlockDevice = & ec2.LaunchTemplateEbsBlockDeviceRequest {
0 commit comments