Add spot tags as resource tags of instances and volumes in launch template

According to the APIReference:
<https://docs.aws.amazon.com/AWSEC2/latest/APIReference/API_LaunchTemplateTagSpecificationRequest.html>,
the resource types `instance` and `volume` support tagging on creation.
It is useful to add the spot tags here as it should be more reliable
than tagging them after the spot request is fulfilled as we currently
do.
This commit is contained in:
Narthana Epa 2021-01-09 23:58:23 +11:00
parent 4b0de7263e
commit f7e68f1d71
No known key found for this signature in database
GPG Key ID: 7ABC460881544B69
1 changed files with 10 additions and 0 deletions

View File

@ -260,6 +260,16 @@ func (s *StepRunSpotInstance) Run(ctx context.Context, state multistep.StateBag)
Tags: spotTags,
},
}
launchTemplate.LaunchTemplateData.TagSpecifications = []*ec2.LaunchTemplateTagSpecificationRequest{
{
ResourceType: aws.String("instance"),
Tags: spotTags,
},
{
ResourceType: aws.String("volume"),
Tags: spotTags,
},
}
}
// Tell EC2 to create the template