@@ -243,82 +243,17 @@ runs:
243243
244244 rm -f ${TERRAFORM_OUTPUT_FILE}
245245
246- - name : Convert PLANFILE to JSON
247- if : ${{ steps.atmos-plan.outputs.changes == 'true' }}
248- shell : bash
249- working-directory : ./${{ steps.vars.outputs.component_path }}
250- run : |
251- terraform show -json "${{ steps.vars.outputs.plan_file }}" > "${{ steps.vars.outputs.plan_file }}.json"
252-
253246 - name : Configure State AWS Credentials
254- if : ${{ steps.atmos-plan.outputs.changes == 'true ' }}
247+ if : ${{ steps.atmos-plan.outputs.error == 'false ' }}
255248 uses : aws-actions/configure-aws-credentials@v4.0.1
256249 with :
257250 aws-region : ${{ steps.config.outputs.aws-region }}
258251 role-to-assume : ${{ steps.config.outputs.terraform-state-role }}
259252 role-session-name : " atmos-terraform-state-gitops"
260253 mask-aws-account-id : " no"
261254
262- - name : Retrieve Plan
263- if : ${{ steps.atmos-plan.outputs.changes == 'true' }}
264- uses : cloudposse/github-action-terraform-plan-storage@v1
265- id : retrieve-plan
266- continue-on-error : true
267- with :
268- action : getPlan
269- planPath : " ${{ steps.vars.outputs.plan_file }}.stored"
270- commitSHA : ${{ inputs.sha }}
271- component : ${{ inputs.component }}
272- stack : ${{ inputs.stack }}
273- tableName : ${{ steps.config.outputs.terraform-state-table }}
274- bucketName : ${{ steps.config.outputs.terraform-state-bucket }}
275- failOnMissingPlan : " false"
276-
277- - name : Compare Current and Stored PLANFILEs
278- if : ${{ steps.atmos-plan.outputs.changes == 'true' }}
279- id : new-plan
280- shell : bash
281- working-directory : ./${{ steps.vars.outputs.component_path }}
282- run : |
283- PLAN_FILE="${{ steps.vars.outputs.plan_file }}"
284- PLAN_FILE_STORED="${{ steps.vars.outputs.plan_file }}.stored"
285-
286- NEW_PLAN_FOUND=false
287- if [ -f "$PLAN_FILE_STORED" ]; then
288- set +e
289- terraform show -json "$PLAN_FILE_STORED" > "$PLAN_FILE_STORED.json"
290-
291- TERRAFORM_RESULT=$?
292-
293- set -e
294-
295- if [[ "${TERRAFORM_RESULT}" == "0" ]]; then
296- # sort and remove timestamp
297- jq 'if has("relevant_attributes") then .relevant_attributes |= sort_by(.resource, .attribute) else . end' "$PLAN_FILE.json" | jq 'del(.timestamp)' > current.json
298- jq 'if has("relevant_attributes") then .relevant_attributes |= sort_by(.resource, .attribute) else . end' "$PLAN_FILE_STORED.json" | jq 'del(.timestamp)' > stored.json
299-
300- # calculate checksums of stored and current plans
301- MD5_CURRENT=$(md5sum current.json | awk '{ print $1 }')
302- MD5_STORED=$(md5sum stored.json | awk '{ print $1 }')
303-
304- if [ "$MD5_CURRENT" == "$MD5_STORED" ]; then
305- echo "Current plan is equal to stored plan"
306- else
307- echo "Current plan is different from stored plan"
308- NEW_PLAN_FOUND=true
309- fi
310- else
311- # If terraform show failed that means old plan is wrong
312- NEW_PLAN_FOUND=true
313- fi
314- else
315- echo "New plan found"
316- NEW_PLAN_FOUND=true
317- fi
318- echo "found=${NEW_PLAN_FOUND}" >> $GITHUB_OUTPUT
319-
320255 - name : Store New Plan
321- if : ${{ steps.new -plan.outputs.found == 'true ' }}
256+ if : ${{ steps.atmos -plan.outputs.error == 'false ' }}
322257 uses : cloudposse/github-action-terraform-plan-storage@v1
323258 id : store-plan
324259 with :
@@ -331,7 +266,7 @@ runs:
331266 bucketName : ${{ steps.config.outputs.terraform-state-bucket }}
332267
333268 - name : Store Lockfile for New Plan
334- if : ${{ steps.new -plan.outputs.found == 'true ' }}
269+ if : ${{ steps.atmos -plan.outputs.error == 'false ' }}
335270 uses : cloudposse/github-action-terraform-plan-storage@v1
336271 with :
337272 action : storePlan
@@ -348,6 +283,13 @@ runs:
348283 with :
349284 api-key : ${{ inputs.infracost-api-key }}
350285
286+ - name : Convert PLANFILE to JSON
287+ if : ${{ steps.config.outputs.enable-infracost == 'true' && steps.atmos-plan.outputs.changes == 'true' }}
288+ shell : bash
289+ working-directory : ./${{ steps.vars.outputs.component_path }}
290+ run : |
291+ terraform show -json "${{ steps.vars.outputs.plan_file }}" > "${{ steps.vars.outputs.plan_file }}.json"
292+
351293 - name : Generate Infracost Diff
352294 if : ${{ steps.config.outputs.enable-infracost == 'true' && steps.atmos-plan.outputs.changes == 'true' }}
353295 id : infracost
0 commit comments