Skip to content

Detect drift

Detect drift #2175

# This workflow is optional.
name: Detect drift
on:
workflow_dispatch:
inputs: {}
schedule:
# hourly
- cron: "0 * * * *"
jobs:
pick-out-drift-issues:
timeout-minutes: 30
runs-on: ubuntu-latest
permissions:
contents: read
issues: write # To close issues
outputs:
issues: ${{steps.pick-out-drift-issues.outputs.issues}}
has_issues: ${{steps.pick-out-drift-issues.outputs.has_issues}}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- uses: aquaproj/aqua-installer@f13c5d2f0357708d85477aabe50fd3f725528745 # v3.1.0
with:
aqua_version: v2.42.1
env:
AQUA_GITHUB_TOKEN: ${{github.token}}
- run: tfaction pick-out-drift-issues
id: pick-out-drift-issues
env:
GITHUB_TOKEN: ${{github.token}}
detect-drift:
timeout-minutes: 30
name: "detect-drift (${{matrix.issue.target}})"
runs-on: ${{matrix.issue.runs_on}}
needs: pick-out-drift-issues
permissions:
issues: write # For github-comment and tfcmt
contents: write # To push commits
id-token: write # For OIDC
if: fromJSON(needs.pick-out-drift-issues.outputs.has_issues)
strategy:
fail-fast: false
matrix:
issue: ${{fromJSON(needs.pick-out-drift-issues.outputs.issues)}}
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
persist-credentials: false
- name: Generate token
id: generate_token
uses: tibdex/github-app-token@3beb63f4bd073e61482598c45c71c1019b59b73a # v2.1.0
with:
app_id: ${{secrets.APP_ID}}
private_key: ${{secrets.APP_PRIVATE_KEY}}
# issues:write - Create and update issues
permissions: >-
{
"issues": "write"
}
# issues of Drift Detection
repositories: >-
[
"tfaction-example"
]
- uses: aquaproj/aqua-installer@f13c5d2f0357708d85477aabe50fd3f725528745 # v3.1.0
with:
aqua_version: v2.42.1
env:
GITHUB_TOKEN: ${{github.token}}
- uses: suzuki-shunsuke/tfaction/set-drift-env@d4b16993b0b434b36c1a94c25c2fcb0c18d867d4 # v1.15.0
with:
issue: ${{toJSON(matrix.issue)}}
- uses: suzuki-shunsuke/tfaction/setup@d4b16993b0b434b36c1a94c25c2fcb0c18d867d4 # v1.15.0
with:
github_token: ${{steps.generate_token.outputs.token}}
env:
GITHUB_TOKEN: ${{steps.generate_token.outputs.token}}
TF_TOKEN_app_terraform_io: ${{secrets.TFE_TOKEN}} # For Hashicorp Cloud Backend
- uses: suzuki-shunsuke/tfaction/test@d4b16993b0b434b36c1a94c25c2fcb0c18d867d4 # v1.15.0
with:
github_token: ${{steps.generate_token.outputs.token}}
env:
GITHUB_TOKEN: ${{steps.generate_token.outputs.token}}
- uses: suzuki-shunsuke/tfaction/terraform-plan@d4b16993b0b434b36c1a94c25c2fcb0c18d867d4 # v1.15.0
with:
github_token: ${{steps.generate_token.outputs.token}}
env:
GITHUB_TOKEN: ${{steps.generate_token.outputs.token}}
TF_TOKEN_app_terraform_io: ${{secrets.TFE_TOKEN}} # For Hashicorp Cloud Backend
TFE_TOKEN: ${{secrets.TFE_TOKEN}} # For tfe provider
- uses: suzuki-shunsuke/tfaction/update-drift-issue@d4b16993b0b434b36c1a94c25c2fcb0c18d867d4 # v1.15.0
if: always()
with:
status: ${{job.status}}
github_token: ${{steps.generate_token.outputs.token}}