Skip to content

Instantly share code, notes, and snippets.

@jyrkiput
Created September 21, 2017 06:21
Show Gist options
  • Save jyrkiput/6f412a254c01c6cba732b9453f861dbe to your computer and use it in GitHub Desktop.
Save jyrkiput/6f412a254c01c6cba732b9453f861dbe to your computer and use it in GitHub Desktop.
#!/bin/bash
set -o errexit
set -o nounset
STACK_NAME=$1
STACKJSON=$(aws cloudformation describe-stacks --stack-name $STACK_NAME)
PARAMS=$(echo $STACKJSON | jq '.Stacks[0].Parameters | del( .[].ParameterValue) | .[]["UsePreviousValue"] = true')
PROJECT=$(echo $STACKJSON | jq -r '.Stacks[0].Parameters[] | select(.ParameterKey == "TagApplication") | .ParameterValue')
ENVIRONMENT=$(echo $STACKJSON | jq -r '.Stacks[0].Parameters[] | select(.ParameterKey == "TagEnvironment") | .ParameterValue')
WORKORDER=$(echo $STACKJSON | jq -r '.Stacks[0].Parameters[] | select(.ParameterKey == "TagWorkOrder") | .ParameterValue')
COSTCENTER=$(echo $STACKJSON | jq -r '.Stacks[0].Parameters[] | select(.ParameterKey == "TagCostCenter") | .ParameterValue')
PROJECT_TAG="Key=Application,Value=$PROJECT"
ENVIRONMENT_TAG="Key=Environment,Value=$ENVIRONMENT"
WORKORDER_TAG="Key=WorkOrder,Value=$WORKORDER"
COSTCENTER_TAG="Key=CostCenter,Value=$COSTCENTER"
aws cloudformation update-stack --stack-name $STACK_NAME --use-previous-template --tags $PROJECT_TAG $ENVIRONMENT_TAG $WORKORDER_TAG $COSTCENTER_TAG --parameters "$PARAMS"
@jyrkiput
Copy link
Author

Bash script for updating tags in cloudformation stack.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment