diff --git a/.github/workflows/test-changes-exists-drift.yml b/.github/workflows/test-changes-exists-drift.yml index cc6f8b7e..b79e1800 100644 --- a/.github/workflows/test-changes-exists-drift.yml +++ b/.github/workflows/test-changes-exists-drift.yml @@ -41,6 +41,7 @@ jobs: aws-region: ${{ env.AWS_REGION }} sha: da39a3ee5e6b4b0d3255bfef95601890afd80709 drift-detection-mode-enabled: true + atmos-config-path: ./test/configs/ outputs: result: ${{ steps.current.outcome }} diff --git a/.github/workflows/test-changes-exists.yml b/.github/workflows/test-changes-exists.yml index cd91ab31..b9b859d2 100644 --- a/.github/workflows/test-changes-exists.yml +++ b/.github/workflows/test-changes-exists.yml @@ -40,6 +40,7 @@ jobs: terraform-state-table: ${{ secrets.TERRAFORM_STATE_TABLE }} aws-region: ${{ env.AWS_REGION }} sha: da39a3ee5e6b4b0d3255bfef95601890afd80709 + atmos-config-path: ./test/configs/ outputs: result: ${{ steps.current.outcome }} diff --git a/.github/workflows/test-failed-plan-drift.yml b/.github/workflows/test-failed-plan-drift.yml index adff9f04..f011bea6 100644 --- a/.github/workflows/test-failed-plan-drift.yml +++ b/.github/workflows/test-failed-plan-drift.yml @@ -41,6 +41,7 @@ jobs: aws-region: ${{ env.AWS_REGION }} sha: da39a3ee5e6b4b0d3255bfef95601890afd80709 drift-detection-mode-enabled: true + atmos-config-path: ./test/configs/ outputs: result: ${{ steps.current.outcome }} diff --git a/.github/workflows/test-failed-plan.yml b/.github/workflows/test-failed-plan.yml index 983ab77e..bbe5e17c 100644 --- a/.github/workflows/test-failed-plan.yml +++ b/.github/workflows/test-failed-plan.yml @@ -40,6 +40,7 @@ jobs: terraform-state-table: ${{ secrets.TERRAFORM_STATE_TABLE }} aws-region: ${{ env.AWS_REGION }} sha: da39a3ee5e6b4b0d3255bfef95601890afd80709 + atmos-config-path: ./test/configs/ outputs: result: ${{ steps.current.outcome }} diff --git a/.github/workflows/test-infra-cost.yml b/.github/workflows/test-infra-cost.yml index b24b81a7..4eb082bb 100644 --- a/.github/workflows/test-infra-cost.yml +++ b/.github/workflows/test-infra-cost.yml @@ -43,6 +43,7 @@ jobs: enable-infracost: true infracost-api-key: ${{ secrets.INFRACOST_API_KEY }} debug: true + atmos-config-path: ./test/configs/ outputs: result: ${{ steps.current.outcome }} diff --git a/.github/workflows/test-no-changes-drift-more.yml b/.github/workflows/test-no-changes-drift-more.yml index fb10f38a..96bb673d 100644 --- a/.github/workflows/test-no-changes-drift-more.yml +++ b/.github/workflows/test-no-changes-drift-more.yml @@ -41,6 +41,7 @@ jobs: aws-region: ${{ env.AWS_REGION }} sha: da39a3ee5e6b4b0d3255bfef95601890afd80709 drift-detection-mode-enabled: true + atmos-config-path: ./test/configs/ outputs: result: ${{ steps.current.outcome }} diff --git a/.github/workflows/test-no-changes.yml b/.github/workflows/test-no-changes.yml index 2b8a3ad8..c4697ac5 100644 --- a/.github/workflows/test-no-changes.yml +++ b/.github/workflows/test-no-changes.yml @@ -40,6 +40,7 @@ jobs: terraform-state-table: ${{ secrets.TERRAFORM_STATE_TABLE }} aws-region: ${{ env.AWS_REGION }} sha: da39a3ee5e6b4b0d3255bfef95601890afd80709 + atmos-config-path: ./test/configs/ outputs: result: ${{ steps.current.outcome }} diff --git a/.github/workflows/test-settings-action-disabled-drift.yml b/.github/workflows/test-settings-action-disabled-drift.yml index a43f52f1..813581f1 100644 --- a/.github/workflows/test-settings-action-disabled-drift.yml +++ b/.github/workflows/test-settings-action-disabled-drift.yml @@ -41,6 +41,7 @@ jobs: aws-region: ${{ env.AWS_REGION }} sha: da39a3ee5e6b4b0d3255bfef95601890afd80709 drift-detection-mode-enabled: true + atmos-config-path: ./test/configs/ outputs: result: ${{ steps.current.outcome }} diff --git a/.github/workflows/test-settings-action-disabled.yml b/.github/workflows/test-settings-action-disabled.yml index 73f857ea..361ccea9 100644 --- a/.github/workflows/test-settings-action-disabled.yml +++ b/.github/workflows/test-settings-action-disabled.yml @@ -40,6 +40,7 @@ jobs: terraform-state-table: ${{ secrets.TERRAFORM_STATE_TABLE }} aws-region: ${{ env.AWS_REGION }} sha: da39a3ee5e6b4b0d3255bfef95601890afd80709 + atmos-config-path: ./test/configs/ outputs: result: ${{ steps.current.outcome }} diff --git a/action.yml b/action.yml index 97ae2958..e2b9122d 100644 --- a/action.yml +++ b/action.yml @@ -45,7 +45,7 @@ inputs: atmos-config-path: description: "The path to the atmos.yaml file" required: false - default: atmos.yaml + default: ./ terraform-version: description: 'The version of Terraform CLI to install. Instead of full version string you can also specify constraint string starting with "<" (for example `<1.13.0`) to install the latest version satisfying the constraint. A value of `latest` will install the latest version of Terraform CLI. Defaults to `latest`.' default: 'latest' @@ -87,6 +87,12 @@ outputs: runs: using: "composite" steps: + - name: Set vars + shell: bash + run: |- + echo "ATMOS_CLI_CONFIG_PATH=${{inputs.atmos-config-path}}" >> $GITHUB_ENV + echo "ATMOS_BASE_PATH=${{ github.workspace }}" >> $GITHUB_ENV + - name: Checkout uses: actions/checkout@v4 @@ -98,8 +104,6 @@ runs: - name: Install Atmos uses: cloudposse/github-action-setup-atmos@v1 - env: - ATMOS_CLI_CONFIG_PATH: ${{inputs.atmos-config-path}} with: atmos-version: ${{ inputs.atmos-version }} token: ${{ inputs.token }} @@ -170,8 +174,6 @@ runs: if: ${{ steps.atmos-github-actions-enabled.outputs.value == 'true' }} id: atmos-plan shell: bash - env: - ATMOS_BASE_PATH: ${{ github.workspace }} run: | set +e @@ -280,21 +282,31 @@ runs: PLAN_FILE_STORED="${{ steps.vars.outputs.plan_file }}.stored" NEW_PLAN_FOUND=false - if [ -f "$PLAN_FILE_STORED" ]; then + if [ -f "$PLAN_FILE_STORED" ]; then + set +e terraform show -json "$PLAN_FILE_STORED" > "$PLAN_FILE_STORED.json" - - # sort and remove timestamp - jq 'if has("relevant_attributes") then .relevant_attributes |= sort_by(.resource, .attribute) else . end' "$PLAN_FILE.json" | jq 'del(.timestamp)' > current.json - jq 'if has("relevant_attributes") then .relevant_attributes |= sort_by(.resource, .attribute) else . end' "$PLAN_FILE_STORED.json" | jq 'del(.timestamp)' > stored.json - - # calculate checksums of stored and current plans - MD5_CURRENT=$(md5sum current.json | awk '{ print $1 }') - MD5_STORED=$(md5sum stored.json | awk '{ print $1 }') - if [ "$MD5_CURRENT" == "$MD5_STORED" ]; then - echo "Current plan is equal to stored plan" + TERRAFORM_RESULT=$? + + set -e + + if [[ "${TERRAFORM_RESULT}" == "0" ]]; then + # sort and remove timestamp + jq 'if has("relevant_attributes") then .relevant_attributes |= sort_by(.resource, .attribute) else . end' "$PLAN_FILE.json" | jq 'del(.timestamp)' > current.json + jq 'if has("relevant_attributes") then .relevant_attributes |= sort_by(.resource, .attribute) else . end' "$PLAN_FILE_STORED.json" | jq 'del(.timestamp)' > stored.json + + # calculate checksums of stored and current plans + MD5_CURRENT=$(md5sum current.json | awk '{ print $1 }') + MD5_STORED=$(md5sum stored.json | awk '{ print $1 }') + + if [ "$MD5_CURRENT" == "$MD5_STORED" ]; then + echo "Current plan is equal to stored plan" + else + echo "Current plan is different from stored plan" + NEW_PLAN_FOUND=true + fi else - echo "Current plan is different from stored plan" + # If terraform show failed that means old plan is wrong NEW_PLAN_FOUND=true fi else diff --git a/atmos.yaml b/test/configs/atmos.yaml similarity index 100% rename from atmos.yaml rename to test/configs/atmos.yaml