How do you handle secrets as environment variables in CI for Terraform?
IntermediateScenarioPipelines Terraform Cloud and OpenTofu
Answer
Situation read → Providers like Datadog or Cloudflare need API tokens.
What I'd do →
- Store them in the CI secret store, exposed only to the apply job and protected branches.
- Pass them as provider environment variables (
DD_API_KEY) orTF_VAR_*markedsensitive. - Prefer OIDC or dynamic credentials where the provider supports them.
Why → Secrets never appear in code, and PR jobs from forks never see them.
Interview tip → Never echo env in debug steps.
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