Skip to content
This repository has been archived by the owner on Aug 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #47 from gwright99/gwright99/fix-typo
Browse files Browse the repository at this point in the history
Fixing typo I introduced with my previous PR and making logic tighter.
  • Loading branch information
wleepang authored Mar 12, 2022
2 parents ab760db + 1083c7f commit 4d044c4
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions bin/create-ebs-volume
Original file line number Diff line number Diff line change
Expand Up @@ -257,14 +257,18 @@ 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


# The $instance_tags variable could be empty and will cause a TagSpecifications[0].Tags[0] error if
# it is passed as an empty value because it must be comma-separated from the other key-value pairs.
# Use a Shell Parameter Expansion to determine if the variable contains a value or not. If it has a value,
# append a comma at the end so the aws cli syntax is compliant when it is subbed into the tag_specification variable.
local instance_tags=${instance_tags:+${instance_tags},}
local tag_specification="ResourceType=volume,Tags=[$instance_tags{Key=source-instance,Value=$instance_id},{Key=amazon-ebs-autoscale-creation-time,Value=$timestamp}]"

# Note: Shellcheck says the $vars in this command should be double quoted to prevent globbing and word-splitting,
# but this ends up making the '--encrypted' argument to fail during the execution of the install script. Conversely, NOT putting double-quotes
# around $tag_specification causes a parsing error due to the space in the $timestamp value (added to $tag_specification above).

local volume=$(\
aws ec2 create-volume \
--region $region \
Expand Down

0 comments on commit 4d044c4

Please sign in to comment.