# Check for and exit on errors set -e # Script to implement some functions to standardize the workflow for TerraformA In CI/CD Pipelines # # ## Global Variables ## PS4='LINENO:' # Set line numbers on error output to ease debugging if [ -z $TF_BACKEND_BUCKET ]; then die 127 "No TF_BACKEND_BUCKET variable specified or empty variable" fi if [ -z $TF_BACKEND_DYNDB_TABLE ]; then die 127 "No TF_BACKEND_DYNDB_TABLE variable specified or empty variable" fi if [ -z $TF_BACKEND_REGION ]; then die 127 "No TF_BACKEND_REGION variable specified or empty variable" fi if [ -z $TF_BACKEND_KEY ]; then die 127 "No TF_BACKEND_KEY variable specified or empty variable" fi if [ -z $TF_VAR_api_key ]; then die 127 "No TF_VAR_api_key variable specified or empty variable" fi if [ -z $TF_VAR_app_key ]; then die 127 "No TF_VAR_app_key variable specified or empty variable" fi echo "Planning for deployment of API and APP keys" terraform init -backend-config="encrypt=true" \ -backend-config="bucket=$TF_BACKEND_BUCKET" \ -backend-config="dynamodb_table=$TF_BACKEND_DYNDB_TABLE" \ -backend-config="region=$TF_BACKEND_REGION" \ -backend-config="key=$TF_BACKEND_KEY" \ -input=false 2>&1 | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" # ; test ${PIPESTATUS[0]} -eq 0 terraform validate 2>&1 | \ sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" ; #\ #test ${PIPESTATUS[0]} -eq 0 terraform plan -out=tfplan -input=false -detailed-exitcode \ -var-file=terraform.tfvars 2>&1 | \ sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" ; #\ #test ${PIPESTATUS[0]} -ne 1 #terraform plan -out=tfplan -input=false -detailed-exitcode \ # -var-file=terraform.tfvars \ # -var="datadog_api_key=${TF_VAR_datadog_api_key}" \ # -var="datadog_app_key=${TF_VAR_datadog_api_key}" 2>&1 | \ # sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g" ; #\ # #test ${PIPESTATUS[0]} -ne 1 ls -la