-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtf-plan.sh
executable file
·33 lines (25 loc) · 1.02 KB
/
tf-plan.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/bin/bash
set +e
terraform plan -detailed-exitcode -input=false -no-color -refresh=true -out=plan.out
PLAN_EXIT=$?
set -e
echo "Plan exit code: $PLAN_EXIT"
if [ $PLAN_EXIT -eq 0 ]; then
echo "No changes to be applied. Stopping pipeline execution."
PIPELINE_NAME=${CODEBUILD_INITIATOR#codepipeline/}
echo "Pipeline name is $PIPELINE_NAME"
EXECUTION_ID=$(aws codepipeline get-pipeline-state --name ${PIPELINE_NAME} --query 'stageStates[?actionStates[?latestExecution.externalExecutionId==`'${CODEBUILD_BUILD_ID}'`]].latestExecution.pipelineExecutionId' --output text)
echo "Execution ID is $EXECUTION_ID"
aws codepipeline stop-pipeline-execution \
--pipeline-name $PIPELINE_NAME \
--pipeline-execution-id $EXECUTION_ID \
--no-abandon \
--reason "No changes to be applied. Stopping pipeline execution."
elif [ $PLAN_EXIT -eq 2 ]; then
terraform show plan.out > plan.txt
echo "Changes need to be applied."
exit 0
else
echo "Error"
exit $PLAN_EXIT
fi