diff --git a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/helpers/terraform/adf_terraform.sh b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/helpers/terraform/adf_terraform.sh index 89f91ea88..9df861b4e 100644 --- a/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/helpers/terraform/adf_terraform.sh +++ b/src/lambda_codebase/initial_commit/bootstrap_repository/adf-build/shared/helpers/terraform/adf_terraform.sh @@ -41,6 +41,12 @@ tfplan(){ tfapply(){ terraform apply "${ADF_PROJECT_NAME}-${TF_VAR_TARGET_ACCOUNT_ID}" } +tfplandestroy(){ + terraform plan -destroy -out "$ADF_PROJECT_NAME"-"$TF_VAR_TARGET_ACCOUNT_ID"-destroy +} +tfdestroy(){ + terraform apply "$ADF_PROJECT_NAME"-"$TF_VAR_TARGET_ACCOUNT_ID"-destroy +} tfrun(){ export TF_VAR_TARGET_ACCOUNT_ID=$ACCOUNT_ID echo "Running terraform $TF_STAGE on account $ACCOUNT_ID and region $REGION" @@ -62,6 +68,13 @@ tfrun(){ tfplan tfapply set +e + elif [[ "$TF_STAGE" = "destroy" ]] + then + set -e + tfinit + tfplandestroy + tfdestroy + set +e else echo "Invalid Terraform stage: TF_STAGE = $TF_STAGE" exit 1