Skip to content
This repository was archived by the owner on Jul 28, 2024. It is now read-only.

Commit d1181e6

Browse files
committed
adding template to validate state on redeploy
1 parent cfcc14b commit d1181e6

File tree

4 files changed

+37
-0
lines changed

4 files changed

+37
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@
1010

1111
# Thumbnails
1212
._*
13+
14+
.terraform
15+
*.tfstate
16+
*.tfstate.backup

misc/validate-state/env0.yml

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
version: 1
2+
3+
deploy:
4+
steps:
5+
terraformPlan:
6+
after:
7+
- ./validate.sh

misc/validate-state/main.tf

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
terraform {
2+
required_version = "0.12.24"
3+
}
4+
5+
resource "null_resource" "null1" {
6+
}
7+
8+
resource "null_resource" "null2" {
9+
}

misc/validate-state/validate.sh

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
#!/usr/bin/env bash
2+
set -e
3+
if [[ "$IS_REDEPLOY" == "true" ]];
4+
then
5+
EXPECTED_PLAN_OUTPUT="Plan: 0 to add, 0 to change, 0 to destroy."
6+
PLAN_OUTPUT=$(terraform show -no-color .tf-plan | tail -1)
7+
if [[ "$PLAN_OUTPUT" == "$EXPECTED_PLAN_OUTPUT" ]];
8+
then
9+
echo "Redeploy plan is OK"
10+
exit 0
11+
else
12+
echo "Validation Failed, Redeploy plan is $PLAN_OUTPUT";
13+
exit 1
14+
fi
15+
else
16+
echo "Not Redeploy so not validating"
17+
fi

0 commit comments

Comments
 (0)