From 6659ab58ad886aeb6402fea14aa10608951ce3ab Mon Sep 17 00:00:00 2001 From: Major Hayden Date: Tue, 18 Aug 2020 12:45:27 -0500 Subject: [PATCH] awsupload: Apply tags to imported snapshot Applying a `Name` tag to the snapshot makes the name of the image appear in the snapshot listing in EC2's console. It also makes it easier to remove a snapshot after deregistering the AMI. Signed-off-by: Major Hayden --- internal/upload/awsupload/awsupload.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/internal/upload/awsupload/awsupload.go b/internal/upload/awsupload/awsupload.go index cd737d897..caeb69112 100644 --- a/internal/upload/awsupload/awsupload.go +++ b/internal/upload/awsupload/awsupload.go @@ -167,6 +167,24 @@ func (a *AWS) Register(name, bucket, key string) (*string, error) { } snapshotID := importOutput.ImportSnapshotTasks[0].SnapshotTaskDetail.SnapshotId + + // Tag the snapshot with the image name. + req, _ := a.importer.CreateTagsRequest( + &ec2.CreateTagsInput{ + Resources: []*string{snapshotID}, + Tags: []*ec2.Tag{ + { + Key: aws.String("Name"), + Value: aws.String(name), + }, + }, + }, + ) + err = req.Send() + if err != nil { + return nil, err + } + log.Printf("[AWS] 📋 Registering AMI from imported snapshot: %s", *snapshotID) registerOutput, err := a.importer.RegisterImage( &ec2.RegisterImageInput{