Skip to content

Commit feda5a1

Browse files
Merge pull request #3663 from nhsuk/improve_terraform_plan_validation
Improve plan validation in pipeline
2 parents 744c2d5 + d8f77ad commit feda5a1

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

.github/workflows/deploy-infrastructure.yml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,13 @@ jobs:
156156
run: |
157157
set -e
158158
terraform init -backend-config="env/${{ inputs.environment }}-backend.hcl" -upgrade
159-
terraform plan -var="image_digest=$DIGEST" -var="app_version=$APP_VERSION" -var-file="env/${{ inputs.environment }}.tfvars" \
160-
-out ${{ runner.temp }}/tfplan | tee ${{ runner.temp }}/tf_stdout
161-
- name: Validate the changes
162-
run: |
163-
set -e
159+
terraform plan -var="image_digest=$DIGEST" -var-file="env/${{ inputs.environment }}.tfvars" \
160+
-out ${{ runner.temp }}/tfplan &> ${{ runner.temp }}/tf_stdout
161+
TF_EXIT_CODE=$?
162+
cat ${{ runner.temp }}/tf_stdout
163+
if [ $TF_EXIT_CODE -eq 1 ]; then
164+
exit $TF_EXIT_CODE
165+
fi
164166
../scripts/validate_plan.sh ${{ runner.temp }}/tf_stdout
165167
- name: Upload artifact
166168
uses: actions/upload-artifact@v4

terraform/scripts/validate_plan.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,11 @@ tfstdout=$1
3838

3939
for resource in "${down_time_if_destroyed[@]}"; do
4040
if [[ $(grep -cE "$resource.*(replaced|destroyed)" "$tfstdout") -ne 0 ]]; then
41-
echo "A resource is being destroyed:"
41+
echo -e "\e[41mPOTENTIALLY CRITICAL RESOURCES ARE BEING DESTROYED:\e[0m"
4242
grep -E "$resource.*(replaced|destroyed)" "$tfstdout"
43-
echo "This would cause a downtime. Aborting"
44-
exit 1
43+
echo "Check carefully if this would cause a downtime"
44+
exit 0
4545
fi
4646
done
4747

48-
echo "No obvious downtime-relevant changes detected. Proceeding with the plan."
48+
echo -e "\e[32mNo obvious downtime-relevant changes detected.\e[0m"

0 commit comments

Comments
 (0)