How do you add a nightly drift detection job in CI?
IntermediateScenarioPipelines Terraform Cloud and OpenTofu
Answer
Situation read → Scheduled, read-only comparison.
What I'd do →
on:
schedule: [{ cron: "0 2 * * *" }]
jobs:
drift:
steps:
- run: terraform init -input=false
- run: |
set +e
terraform plan -detailed-exitcode -lock=false -input=false
rc=$?
[ $rc -eq 2 ] && ./notify-slack.sh "Drift detected in ${{ github.workflow }}"
[ $rc -eq 1 ] && exit 1
exit 0
Why → Exit code 2 signals pending changes without parsing text; a read-only role makes it safe.
Interview tip → Mention -lock=false is acceptable only for read-only plans.
More on Pipelines Terraform Cloud and OpenTofu
Build a basic GitHub Actions pipeline: plan on pull request, apply on merge to main.BeginnerReviewers can't read raw plan logs. How do you present the plan in the PR?IntermediateTwo PRs merge close together and both apply to the same stack. What prevents trouble?IntermediateHow do you add a manual approval before prod applies?IntermediateCompare Atlantis, HCP Terraform and a hand-built GitHub Actions pipeline.IntermediateA saved plan was approved yesterday and apply fails because main changed. How do you avoid dead approvals?Intermediate