Terraform Drift Detection #2
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: Terraform Drift Detection | |
on: | |
workflow_dispatch: | |
schedule: | |
- cron: '0 3 * * *' | |
env: | |
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }} | |
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }} | |
AWS_REGION: ${{ secrets.AWS_BASE_REGION }} | |
TFSTATE_BUCKET: ${{ secrets.TFSTATE_BUCKET }} | |
TFSTATE_KEY: ${{ secrets.TFSTATE_KEY }} | |
GRAFANA_ADMIN_PASSWORD: ${{ secrets.GRAFANA_ADMIN_PASSWORD }} | |
ECR_REPOSITORY: ${{ secrets.ECR_REPOSITORY }} | |
EKS_CLUSTER_NAME: ${{ secrets.EKS_CLUSTER_NAME }} | |
CLOUDFLARE_ZONE_ID: ${{ secrets.CLOUDFLARE_ZONE_ID }} | |
CLOUDFLARE_TOKEN: ${{ secrets.CLOUDFLARE_TOKEN }} | |
CLOUDFLARE_EMAIL: ${{ secrets.CLOUDFLARE_EMAIL }} | |
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} | |
TAILSCALE_CLIENT_ID: ${{ secrets.TAILSCALE_CLIENT_ID }} | |
TAILSCALE_CLIENT_SECRET: ${{ secrets.TAILSCALE_CLIENT_SECRET }} | |
CROWDSEC_ENROLL_KEY: ${{ secrets.CROWDSEC_ENROLL_KEY }} | |
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@v1 | |
- name: Install Terraform | |
uses: hashicorp/setup-terraform@v3 | |
with: | |
terraform_version: 1.9.8 | |
terraform_wrapper: false | |
- name: Configure AWS Credentials | |
uses: aws-actions/configure-aws-credentials@v4 | |
with: | |
aws-access-key-id: ${{ env.AWS_ACCESS_KEY_ID }} | |
aws-secret-access-key: ${{ env.AWS_SECRET_ACCESS_KEY }} | |
aws-region: ${{ env.AWS_REGION }} | |
- name: Run Terraform init on all stacks | |
id: init | |
run: terramate run -- 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 }} |