From f69e92fa537e91bec5a663f42237630d7aa5d8d0 Mon Sep 17 00:00:00 2001 From: Igor Rodionov Date: Mon, 20 Nov 2023 15:47:58 +0300 Subject: [PATCH] Fix atmos config path (#45) * Fix atmos config path * Test plan * Test plan * Test plan * Test plan * Test plan * Test plan * Test plan * Test plan * Fix env vars --- .../workflows/test-changes-exists-drift.yml | 1 + .github/workflows/test-changes-exists.yml | 1 + .github/workflows/test-failed-plan-drift.yml | 1 + .github/workflows/test-failed-plan.yml | 1 + .github/workflows/test-infra-cost.yml | 1 + .../workflows/test-no-changes-drift-more.yml | 1 + .github/workflows/test-no-changes.yml | 1 + .../test-settings-action-disabled-drift.yml | 1 + .../test-settings-action-disabled.yml | 1 + action.yml | 46 ++++++++++++------- atmos.yaml => test/configs/atmos.yaml | 0 11 files changed, 38 insertions(+), 17 deletions(-) rename atmos.yaml => test/configs/atmos.yaml (100%) diff --git a/.github/workflows/test-changes-exists-drift.yml b/.github/workflows/test-changes-exists-drift.yml index cc6f8b7ee..b79e1800f 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 cd91ab315..b9b859d2b 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 adff9f049..f011bea61 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 983ab77ed..bbe5e17c5 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 b24b81a7f..4eb082bb9 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 fb10f38a5..96bb673dc 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 2b8a3ad8c..c4697ac5e 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 a43f52f1d..813581f1b 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 73f857ea1..361ccea90 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 97ae2958a..e2b9122d3 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