Last active
October 9, 2019 07:02
-
-
Save Ameausoone/addec3d6190292bc571dfdbe7e15937b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Check if there is some delete actions in plan, and apply it if not | |
# In Docker image : | |
# FROM hashicorp/terraform:0.12.9 | |
# RUN apk add jq | |
set -eo pipefail | |
# Output tfplan | |
terraform plan -out=tfplan -input=false | |
# Convert to json and prettify it | |
terraform show -json tfplan | jq > tfplan.json | |
# Check if there is some delete actions | |
if jq --exit-status --raw-output -c '.resource_changes[] | select( (.change.actions[] | contains ("delete")))' tfplan.json >/dev/null; then | |
echo "There is some delete actions, terraform apply has to be apply manually" | |
else | |
echo "Could apply terraform plan" | |
terraform apply -input=false -auto-approve tfplan | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment