Skip to content

Instantly share code, notes, and snippets.

@tom-butler
Created December 20, 2017 01:26
Show Gist options
  • Select an option

  • Save tom-butler/d5d0a07b0c5f972bcfb9fc4f48c80aa5 to your computer and use it in GitHub Desktop.

Select an option

Save tom-butler/d5d0a07b0c5f972bcfb9fc4f48c80aa5 to your computer and use it in GitHub Desktop.
blue / green update.sh
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