Scheduled Terraform Drift Detection #5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Scheduled Terraform Drift Detection | |
on: | |
schedule: | |
- cron: '0 2 * * *' | |
jobs: | |
drift-detection: | |
name: Check Drift | |
permissions: | |
id-token: write | |
contents: read | |
pull-requests: read | |
checks: read | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.head_ref }} | |
fetch-depth: 0 | |
- name: Install Terramate | |
uses: terramate-io/terramate-action@v2 | |
- name: Install Terraform | |
uses: hashicorp/setup-terraform@v3 | |
with: | |
terraform_version: 1.7.4 | |
terraform_wrapper: false | |
- name: Authenticate to Google Cloud via OIDC | |
id: auth | |
uses: google-github-actions/auth@v2 | |
with: | |
# see: https://github.com/google-github-actions/auth?tab=readme-ov-file#preferred-direct-workload-identity-federation | |
project_id: 'gen-ai-hironow' | |
workload_identity_provider: 'projects/189612961347/locations/global/workloadIdentityPools/github/providers/my-repo' | |
- name: Run Terraform init on all stacks | |
id: init | |
run: terramate run -C stacks -- terraform init | |
- name: Run drift detection | |
id: drift | |
run: | | |
terramate run \ | |
--sync-drift-status \ | |
--terraform-plan-file=drift.tfplan \ | |
--continue-on-error \ | |
--parallel 5 \ | |
-- \ | |
terraform plan -out drift.tfplan -detailed-exitcode -lock=false | |
env: | |
GITHUB_TOKEN: ${{ github.token }} |