Apply tags to registered AMI
Adding the tag called `Name` to the AMI ensures that the name appears in the *Name* column inside AWS' web console. Fixes #1171. Signed-off-by: Major Hayden <major@redhat.com>
This commit is contained in:
parent
15969e0adc
commit
2618e11bfe
2 changed files with 23 additions and 0 deletions
|
|
@ -243,6 +243,23 @@ func (a *AWS) Register(name, bucket, key string, shareWith []string, rpmArch str
|
|||
|
||||
log.Printf("[AWS] 🎉 AMI registered: %s", *registerOutput.ImageId)
|
||||
|
||||
// Tag the image with the image name.
|
||||
req, _ = a.ec2.CreateTagsRequest(
|
||||
&ec2.CreateTagsInput{
|
||||
Resources: []*string{registerOutput.ImageId},
|
||||
Tags: []*ec2.Tag{
|
||||
{
|
||||
Key: aws.String("Name"),
|
||||
Value: aws.String(name),
|
||||
},
|
||||
},
|
||||
},
|
||||
)
|
||||
err = req.Send()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if len(shareWith) > 0 {
|
||||
log.Println("[AWS] 💿 Sharing ec2 AMI")
|
||||
var launchPerms []*ec2.LaunchPermission
|
||||
|
|
|
|||
|
|
@ -263,6 +263,12 @@ for LOOP_COUNTER in {0..10}; do
|
|||
sleep 5
|
||||
done
|
||||
|
||||
# Ensure the image was properly tagged.
|
||||
IMAGE_TAG=$($AWS_CMD ec2 describe-images --image-ids "${AMI_IMAGE_ID}" | jq -r '.Images[0].Tags[] | select(.Key=="Name") | .Value')
|
||||
if [[ ! $IMAGE_TAG == "${IMAGE_KEY}" ]]; then
|
||||
RESULTS=0
|
||||
fi
|
||||
|
||||
# Clean up our mess.
|
||||
greenprint "🧼 Cleaning up"
|
||||
SNAPSHOT_ID=$(jq -r '.Images[].BlockDeviceMappings[].Ebs.SnapshotId' "$AMI_DATA")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue