Skip to content

Commit

Permalink
Return with correct status code when using Terraform
Browse files Browse the repository at this point in the history
  • Loading branch information
kocsismate committed Sep 2, 2024
1 parent aac9b50 commit 3d03c4f
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions bin/provision.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#!/usr/bin/env bash
set -e

if [[ "$INFRA_ENVIRONMENT" == "local" ]]; then
$PROJECT_ROOT/bin/benchmark.sh
Expand All @@ -9,30 +8,33 @@ elif [[ "$INFRA_ENVIRONMENT" == "aws" ]]; then
cd $PROJECT_ROOT/build/infrastructure/aws/

terraform init -backend=true -get=true -upgrade
if [ $? -ne 0 ]; then
exit 1
fi

terraform plan \
-input=false \
-out="$PROJECT_ROOT/build/infrastructure/aws/aws.tfplan" \
-refresh=true \
-var-file="$PROJECT_ROOT/build/infrastructure/config/aws.tfvars" \
-var-file="$PROJECT_ROOT/build/infrastructure/config/custom.tfvars"
if [ $? -ne 0 ]; then
exit 1
fi

terraform apply \
-auto-approve \
-input=false \
"$PROJECT_ROOT/build/infrastructure/aws/aws.tfplan" || true
"$PROJECT_ROOT/build/infrastructure/aws/aws.tfplan"

if [[ "$N" == "1" ]]; then
arg="-auto-approve"
else
arg="-auto-approve"
fi
status_code="$?"

terraform destroy \
$arg \
-auto-approve \
-var-file="$PROJECT_ROOT/build/infrastructure/config/aws.tfvars" \
-var-file="$PROJECT_ROOT/build/infrastructure/config/custom.tfvars"

cd $PROJECT_ROOT

exit $status_code
fi

0 comments on commit 3d03c4f

Please sign in to comment.