Skip to content

Commit

Permalink
Merge pull request #24 from XenitAB/tf_select_workspace
Browse files Browse the repository at this point in the history
Add select_workspace to validate
  • Loading branch information
simongottschlag authored May 3, 2021
2 parents f36fee3 + 7e44bee commit c73ba41
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions docker/terraform.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,7 @@ plan () {
rm -f .terraform/plans/${ENVIRONMENT}
terraform init -input=false -backend-config="key=${BACKEND_KEY}" -backend-config="resource_group_name=${BACKEND_RG}" -backend-config="storage_account_name=${BACKEND_NAME}" -backend-config="container_name=${CONTAINER_NAME}" -backend-config="snapshot=true"

set +e
terraform workspace select ${ENVIRONMENT} 2> /dev/null
if [ $? -ne 0 ]; then
terraform workspace new ${ENVIRONMENT}
terraform workspace select ${ENVIRONMENT}
fi
set -e
select_workspace

mkdir -p .terraform/plans
terraform plan -input=false -var-file="variables/${ENVIRONMENT}.tfvars" -var-file="variables/common.tfvars" -var-file="../global.tfvars" -out=".terraform/plans/${ENVIRONMENT}"
Expand Down Expand Up @@ -152,14 +146,24 @@ state_remove () {

validate () {
terraform init -input=false -backend-config="key=${BACKEND_KEY}" -backend-config="resource_group_name=${BACKEND_RG}" -backend-config="storage_account_name=${BACKEND_NAME}" -backend-config="container_name=${CONTAINER_NAME}" -backend-config="snapshot=true"
terraform workspace select ${ENVIRONMENT}
select_workspace
terraform validate
terraform fmt .
terraform fmt variables/
tflint --config="/home/${USER}/.tflint.d/.tflint.hcl" --var-file="variables/${ENVIRONMENT}.tfvars" --var-file="variables/common.tfvars" --var-file="../global.tfvars" .
tfsec .
}

select_workspace() {
set +e
terraform workspace select ${ENVIRONMENT} 2> /dev/null
if [ $? -ne 0 ]; then
terraform workspace new ${ENVIRONMENT}
terraform workspace select ${ENVIRONMENT}
fi
set -e
}

envup() {
if [ -f ${ENVIRONMENT_FILE} ]; then
set -a
Expand Down

0 comments on commit c73ba41

Please sign in to comment.