From 6e88326d0084217aa06f9d0eb44057a07cf10be1 Mon Sep 17 00:00:00 2001 From: Graham Wright Date: Tue, 22 Feb 2022 15:23:27 -0500 Subject: [PATCH] Check instance_tags not null Added check to `aws ec2 create-volume` command to ensure that $instance_tags will only be passed if it is not empty. --- bin/create-ebs-volume | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/bin/create-ebs-volume b/bin/create-ebs-volume index 6857564..df99af6 100755 --- a/bin/create-ebs-volume +++ b/bin/create-ebs-volume @@ -257,12 +257,20 @@ function create_and_attach_volume() { local volume="" for i in $(eval echo "{0..$max_attempts}") ; do + # If only tags on resource are prefixed with `aws:` they will all be deleted and cause a parameter validation on + # TagSpecifications[0].Tags[0] error to be thrown since the payload is determined to be a string, not dictionary. + if [ ! -z $instance_tags ]; then + local tag_specification="ResourceType=volume,Tags=[$instance_tags,{Key=source-instance,Value=$instance_id},{Key=amazon-ebs-autoscale-creation-time,Value=$timestamp}]" + else: + local tag_specification="ResourceType=volume,Tags=[{Key=source-instance,Value=$instance_id},{Key=amazon-ebs-autoscale-creation-time,Value=$timestamp}]" + fi + local volume=$(\ aws ec2 create-volume \ --region $region \ --availability-zone $availability_zone \ $volume_opts \ - --tag-specification "ResourceType=volume,Tags=[$instance_tags,{Key=source-instance,Value=$instance_id},{Key=amazon-ebs-autoscale-creation-time,Value=$timestamp}]" \ + --tag-specification "$tag_specification" \ 2> $tmpfile )