#!/usr/bin/env bash
set -euo pipefail
if [[ "${#}" -lt "1" ]]; then
echo "usage: $(basename "${0}") <environment>
Provide the folder name of the stack,
and the environment inorder to initialize terraform
environment:
dev,qa,qatemp,test,uat,testnet,production,sandbox
"
exit 0
fi
STACK_NAME=${PWD##*/}
ENVIRONMENT=${1}
S3_BUCKET=diginex-infrastructure-${ENVIRONMENT}
DYNAMODB_TABLE=diginex-infrastructure-${ENVIRONMENT}
if [ "$ENVIRONMENT" = "sandbox" ]; then
terraform init -reconfigure -backend-config=bucket="${S3_BUCKET}" \
-backend-config=workspace_key_prefix="${STACK_NAME}"/state
else
echo "INFO:COMMAND: terraform init -reconfigure -backend-config=bucket=${S3_BUCKET} -backend-config=workspace_key_prefix="${STACK_NAME}"/state"
terraform init -reconfigure -backend-config=bucket="${S3_BUCKET}" \
-backend-config=workspace_key_prefix="${STACK_NAME}"/state
fi
if [[ $(terraform workspace new "${ENVIRONMENT}" && terraform workspace select "${ENVIRONMENT}") ]]
then
echo "INFO:MESSAGE: New workspace ${ENVIRONMENT} created and selected"
else
terraform workspace select "${ENVIRONMENT}"
echo "INFO:MESSAGE: Selected ${ENVIRONMENT}"
fi