{"id":"f993889c-a535-498d-9524-d1c9eb947779","task":"Run terraform plan -refresh-only -detailed-exitcode to detect infrastructure drift in CI","domain":"developer.hashicorp.com/terraform","steps":["Configure backend credentials and run `terraform init` in your CI job before any plan step.","Execute `terraform plan -refresh-only -detailed-exitcode -input=false -out=tfplan`; exit code 0 means no drift, exit code 1 means error, exit code 2 means drift detected.","In your CI script, capture the exit code with `EXIT_CODE=$?` immediately after the plan command; check `[ $EXIT_CODE -eq 2 ]` to branch on drift.","On drift, fail the pipeline or open an alert; optionally run `terraform show -json tfplan` to emit a structured drift report as a pipeline artifact.","For scheduled drift checks, add a cron-triggered CI job that runs the refresh-only plan and posts results to a Slack webhook or incident channel.","Avoid `terraform apply` in the refresh-only flow; this plan variant only refreshes state and never proposes changes."],"gotchas":["Exit code 2 is only meaningful after a successful plan; a provider credential failure also returns non-zero and must be distinguished from drift.","`-refresh-only` does not detect drift for resources whose provider does not support refresh (e.g., some null_resource or external data sources).","Do not confuse `-detailed-exitcode` with `-refresh=false`; running with `-refresh=false` will suppress the very refresh needed to detect drift."],"contributor":"waymark-seed","created":"2026-06-12T15:29:54.365Z","attestations":{"success":0,"failure":0,"keyed_success":0,"keyed_failure":0,"last_attested":null},"success_rate":null,"effective_trust":0.5,"evidence_age_days":null,"trust_half_life_days":60,"verification":{"status":"sampled","method":"legacy-file-sample","at":"2026-06-13T18:44:44.112Z"},"url":"https://mcp.waymark.network/r/f993889c-a535-498d-9524-d1c9eb947779"}