Created
December 20, 2017 01:26
-
-
Save tom-butler/d5d0a07b0c5f972bcfb9fc4f48c80aa5 to your computer and use it in GitHub Desktop.
blue / green update.sh
This file contains hidden or 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
| export zone_name="app.com." | |
| export address="staging.app.com." | |
| zoneid=$(aws route53 list-hosted-zones | jq -r '.HostedZones[] | select(.Name == env.zone_name) | .Id') | |
| staging=$(aws route53 list-resource-record-sets --hosted-zone-id "$zoneid" | jq -r '.ResourceRecordSets[] | select(.Name == env.address) | select(.AliasTarget.DNSName != null) | .AliasTarget.DNSName | split(".") | first') | |
| if [ -z "$staging" ];then | |
| echo "Error: Could not accurately determine staging" | |
| exit 1 | |
| fi | |
| echo "$staging is staging" | |
| export REGION=ap-southeast-2 | |
| export TF_VAR_application=app | |
| export TF_VAR_environment=dev | |
| export STATE_BUCKET=app-name-$TF_VAR_environment | |
| export STATE_TABLE=terraform-state-lock | |
| pushd stack | |
| export TF_VAR_stack="$staging" | |
| terraform init \ | |
| -backend-config "bucket=$TF_VAR_tf_state_bucket" \ | |
| -backend-config "dynamodb_table=$TF_VAR_tf_state_table" \ | |
| -backend-config "region=$TF_VAR_region" \ | |
| -backend-config "key=$TF_VAR_application-$TF_VAR_stack/terraform.tfstate"\ | |
| -reconfigure | |
| terraform get | |
| terraform plan | |
| terraform apply | |
| popd |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment