|
| 1 | +name: 👽 Atmos Terraform Apply |
| 2 | +run-name: 👽 Atmos Terraform Apply |
| 3 | + |
| 4 | + |
| 5 | +on: |
| 6 | + push: |
| 7 | + branches: |
| 8 | + - main |
| 9 | + |
| 10 | +permissions: |
| 11 | + id-token: write |
| 12 | + contents: read |
| 13 | + issues: write |
| 14 | + pull-requests: write |
| 15 | + |
| 16 | +jobs: |
| 17 | + pr: |
| 18 | + name: PR Context |
| 19 | + runs-on: |
| 20 | + - "self-hosted" |
| 21 | + - "amd64" |
| 22 | + - "common" |
| 23 | + steps: |
| 24 | + - uses: cloudposse-github-actions/get-pr@v2 |
| 25 | + id: pr |
| 26 | + |
| 27 | + outputs: |
| 28 | + base: ${{ fromJSON(steps.pr.outputs.json).base.sha }} |
| 29 | + head: ${{ fromJSON(steps.pr.outputs.json).head.sha }} |
| 30 | + auto-apply: ${{ contains( fromJSON(steps.pr.outputs.json).labels.*.name, 'auto-apply') }} |
| 31 | + no-apply: ${{ contains( fromJSON(steps.pr.outputs.json).labels.*.name, 'no-apply') }} |
| 32 | + |
| 33 | + atmos-affected: |
| 34 | + name: Determine Affected Stacks |
| 35 | + if: needs.pr.outputs.no-apply == 'false' |
| 36 | + needs: ["pr"] |
| 37 | + runs-on: |
| 38 | + - "runs-on=${{ github.run_id }}" |
| 39 | + - "runner=terraform" |
| 40 | + - "tag=${{ inputs.component }}-${{ inputs.stack }}" |
| 41 | + - "private=false" |
| 42 | + steps: |
| 43 | + - id: affected |
| 44 | + uses: cloudposse/github-action-atmos-affected-stacks@v4 |
| 45 | + with: |
| 46 | + base-ref: ${{ needs.pr.outputs.base }} |
| 47 | + head-ref: ${{ needs.pr.outputs.head }} |
| 48 | + atmos-version: ${{ vars.ATMOS_VERSION }} |
| 49 | + atmos-config-path: ${{ vars.ATMOS_CONFIG_PATH }} |
| 50 | + outputs: |
| 51 | + stacks: ${{ steps.affected.outputs.matrix }} |
| 52 | + has-affected-stacks: ${{ steps.affected.outputs.has-affected-stacks }} |
| 53 | + |
| 54 | + plan-atmos-components: |
| 55 | + needs: ["atmos-affected", "pr"] |
| 56 | + if: | |
| 57 | + needs.atmos-affected.outputs.has-affected-stacks == 'true' && needs.pr.outputs.auto-apply != 'true' |
| 58 | + name: Validate plan (${{ matrix.name }}) |
| 59 | + uses: ./.github/workflows/atmos-terraform-plan-matrix.yaml |
| 60 | + strategy: |
| 61 | + matrix: ${{ fromJson(needs.atmos-affected.outputs.stacks) }} |
| 62 | + max-parallel: 1 # This is important to avoid ddos GHA API |
| 63 | + fail-fast: false # Don't fail fast to avoid locking TF State |
| 64 | + with: |
| 65 | + stacks: ${{ matrix.items }} |
| 66 | + drift-detection-mode-enabled: "true" |
| 67 | + continue-on-error: 'true' |
| 68 | + atmos-version: ${{ vars.ATMOS_VERSION }} |
| 69 | + atmos-config-path: ${{ vars.ATMOS_CONFIG_PATH }} |
| 70 | + sha: ${{ needs.pr.outputs.head }} |
| 71 | + secrets: inherit |
| 72 | + |
| 73 | + drift-detection: |
| 74 | + needs: ["atmos-affected", "plan-atmos-components", "pr"] |
| 75 | + if: | |
| 76 | + always() && needs.atmos-affected.outputs.has-affected-stacks == 'true' && needs.pr.outputs.auto-apply != 'true' |
| 77 | + name: Reconcile issues |
| 78 | + runs-on: |
| 79 | + - "self-hosted" |
| 80 | + - "amd64" |
| 81 | + - "common" |
| 82 | + steps: |
| 83 | + - name: Drift Detection |
| 84 | + uses: cloudposse/github-action-atmos-terraform-drift-detection@v2 |
| 85 | + with: |
| 86 | + max-opened-issues: '-1' |
| 87 | + process-all: 'false' |
| 88 | + |
| 89 | + auto-apply: |
| 90 | + needs: ["atmos-affected", "pr"] |
| 91 | + if: | |
| 92 | + needs.atmos-affected.outputs.has-affected-stacks == 'true' && needs.pr.outputs.auto-apply == 'true' |
| 93 | + name: Apply (${{ matrix.name }}) |
| 94 | + uses: ./.github/workflows/atmos-terraform-apply-matrix.yaml |
| 95 | + strategy: |
| 96 | + max-parallel: 1 |
| 97 | + fail-fast: false # Don't fail fast to avoid locking TF State |
| 98 | + matrix: ${{ fromJson(needs.atmos-affected.outputs.stacks) }} |
| 99 | + with: |
| 100 | + stacks: ${{ matrix.items }} |
| 101 | + sha: ${{ needs.pr.outputs.head }} |
| 102 | + atmos-version: ${{ vars.ATMOS_VERSION }} |
| 103 | + atmos-config-path: ${{ vars.ATMOS_CONFIG_PATH }} |
| 104 | + secrets: inherit |
0 commit comments