Skip to content

Commit

Permalink
Fix atmos config path (#45)
Browse files Browse the repository at this point in the history
* Fix atmos config path

* Test plan

* Test plan

* Test plan

* Test plan

* Test plan

* Test plan

* Test plan

* Test plan

* Fix env vars
  • Loading branch information
goruha authored Nov 20, 2023
1 parent 7ce5db8 commit f69e92f
Show file tree
Hide file tree
Showing 11 changed files with 38 additions and 17 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test-changes-exists-drift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-changes-exists.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-failed-plan-drift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-failed-plan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-infra-cost.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-no-changes-drift-more.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-no-changes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-settings-action-disabled-drift.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/test-settings-action-disabled.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
46 changes: 29 additions & 17 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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

Expand All @@ -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 }}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
File renamed without changes.

0 comments on commit f69e92f

Please sign in to comment.