11#! /usr/bin/env bash
22# This script automates the cold-start process of provisioning the Terraform state backend using terraform
33
4- DISABLE_ROLE_ARN=${DISABLE_ROLE_ARN:- 0}
4+ set -e
5+
6+ # We use this variable consistently to pass the role we wish to assume in our root modules
7+ export TF_VAR_aws_assume_role_arn=" ${TF_VAR_aws_assume_role_arn:- false} "
8+
9+ DISABLE_ROLE_ARN=${DISABLE_ROLE_ARN:- false}
510
611# Start from a clean slate
712rm -rf .terraform terraform.tfstate
813
9- # Disable S3 backend
14+ # Disable S3 backend. We'll import state afterwards.
1015sed -Ei ' s/^(\s+backend\s+)/#\1/' main.tf
1116
1217# Disable Role ARN (necessary for root account on cold-start)
13- [ " ${DISABLE_ROLE_ARN} " == " 0 " ] || sed -Ei ' s/^(\s+role_arn\s+)/#\1/' main.tf
18+ [ " ${DISABLE_ROLE_ARN} " == " true " ] || sed -Ei ' s/^(\s+role_arn\s+)/#\1/' main.tf
1419
1520# Initialize terraform modules and providers
1621init-terraform
1722
1823# Provision S3 bucket and dynamodb tables
19- terraform apply -auto-approve
24+ terraform apply -auto-approve -input=false
2025
21- export TF_BUCKET=$( terraform output -json | jq -r . tfstate_backend_s3_bucket_id.value )
22- export TF_DYNAMODB_TABLE=$( terraform output -json | jq -r . tfstate_backend_dynamodb_table_id.value )
26+ export TF_BUCKET=$( terraform output tfstate_backend_s3_bucket_id)
27+ export TF_DYNAMODB_TABLE=$( terraform output tfstate_backend_dynamodb_table_id)
2328export TF_BUCKET_REGION=${TF_VAR_region}
2429
2530# Re-enable S3 backend
@@ -29,7 +34,7 @@ sed -Ei 's/^#(\s+backend\s+)/\1/' main.tf
2934echo " yes" | init-terraform
3035
3136# Re-enable Role ARN
32- [ " ${DISABLE_ROLE_ARN} " == " 0 " ] || sed -Ei ' s/^#(\s+role_arn\s+)/\1/' main.tf
37+ [ " ${DISABLE_ROLE_ARN} " == " true " ] || sed -Ei ' s/^#(\s+role_arn\s+)/\1/' main.tf
3338
3439# Describe how to use the S3/DynamoDB resources with Geodesic
3540echo " Add the following to the Geodesic Module's Dockerfile:"
0 commit comments