Last active
July 7, 2021 07:35
-
-
Save t04glovern/f711ccf27f59b4d0cbcd150aac29b4ca to your computer and use it in GitHub Desktop.
AWS CloudFormation Stackset Update/Create 1-click deploy - w/ ControlTower support
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
STACKSET_NAME="template-us-west-2-shared-services" | |
STACKSET_REGION="us-west-2" | |
STACKSET_DEPLOYMENT_REGIONS="us-west-2" | |
STACKSET_DEPLOYMENT_ACCOUNTS="123456789012" | |
ACCOUNT_ID=$(aws sts get-caller-identity --query Account --output text) | |
STACK_STATE=$(aws cloudformation describe-stack-set --stack-set-name "$STACKSET_NAME" --region "$STACKSET_REGION" --query "StackSet.StackSetName" 2>/dev/null) | |
if [ -z "$STACK_STATE" ] | |
then | |
aws cloudformation create-stack-set \ | |
--stack-set-name $STACKSET_NAME \ | |
--template-body file://template.yml \ | |
--parameters file://template-parameters.json \ | |
--capabilities "CAPABILITY_AUTO_EXPAND" "CAPABILITY_NAMED_IAM" \ | |
--administration-role-arn "arn:aws:iam::$ACCOUNT_ID:role/service-role/AWSControlTowerStackSetRole" \ | |
--execution-role-name "AWSControlTowerExecution" \ | |
--permission-model "SELF_MANAGED" \ | |
--region "$STACKSET_REGION" | |
aws cloudformation create-stack-instances --stack-set-name "$STACKSET_NAME" \ | |
--regions "$STACKSET_DEPLOYMENT_REGIONS" \ | |
--accounts "$STACKSET_DEPLOYMENT_ACCOUNTS" | |
else | |
aws cloudformation update-stack-set \ | |
--stack-set-name $STACKSET_NAME \ | |
--template-body file://template.yml \ | |
--parameters file://template-parameters.json \ | |
--capabilities "CAPABILITY_AUTO_EXPAND" "CAPABILITY_NAMED_IAM" \ | |
--administration-role-arn "arn:aws:iam::$ACCOUNT_ID:role/service-role/AWSControlTowerStackSetRole" \ | |
--execution-role-name "AWSControlTowerExecution" \ | |
--permission-model "SELF_MANAGED" \ | |
--region "$STACKSET_REGION" | |
if $(aws cloudformation update-stack-instances --stack-set-name "$STACKSET_NAME" --region "$STACKSET_REGION" \ | |
--regions "$STACKSET_DEPLOYMENT_REGIONS" \ | |
--accounts "$STACKSET_DEPLOYMENT_ACCOUNTS") ; then | |
: | |
else | |
aws cloudformation create-stack-instances --stack-set-name "$STACKSET_NAME" --region "$STACKSET_REGION" \ | |
--regions "$STACKSET_DEPLOYMENT_REGIONS" \ | |
--accounts "$STACKSET_DEPLOYMENT_ACCOUNTS" | |
fi | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment