Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save scottnixonjr/f8af1603a67ce601454aef1ac540668e to your computer and use it in GitHub Desktop.
Save scottnixonjr/f8af1603a67ce601454aef1ac540668e to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -o errexit
set -o nounset
set -o pipefail
CFN_FILE=file://$(pwd)/github_service_account.yaml
STACK='github-service-account'
REGION='us-east-1'
if ! (aws cloudformation describe-stacks --region ${REGION} --stack-name ${STACK}) ; then
echo "Creating stack"
aws cloudformation create-stack --stack-name ${STACK} --template-body ${CFN_FILE} --region ${REGION} --capabilities CAPABILITY_NAMED_IAM
echo "Waiting for stack to be created ..."
aws cloudformation wait stack-create-complete --stack-name ${STACK} --region ${REGION}
else
echo "Stack exists, attempting to update."
set +e
update=$(aws cloudformation update-stack --stack-name ${STACK} --template-body $CFN_FILE --region ${REGION} --capabilities CAPABILITY_NAMED_IAM)
status=$?
set -e
echo "$update"
if [ $status -ne 0 ] ; then
# Don't fail for no-op update
if [[ $update == *"ValidationError"* && $update == *"No updates"* ]] ; then
echo -e "\nFinished create/update - no updates to be performed"
exit 0
else
exit $status
fi
fi
echo "Waiting on ${STACK} to update..."
aws cloudformation wait stack-update-complete --stack-name ${STACK} --region ${REGION}
fi
echo "Finished create/update successfully!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment