INTERVIEW PREP
Interview questions
570 questions from real DevOps, SRE, platform engineering and MLOps interviews, with the answer an interviewer wants to hear. Try answering out loud first, then open the model answer.
Showing 256–270 of 490 questions
256.Why does my plan show a change every time even though nothing changed?MidTerraform
Something differs on every run: a value like timestamp() in tags, another tool editing the same field, or the provider formatting a value differently (common with JSON policies). Fix the code, use jsonencode, or add ignore_changes for fields another system owns.
257.terraform apply says the resource already exists. Why?MidTerraform
The resource exists in the cloud but not in state, because it was created by hand or the state was lost. Import it with an import block instead of creating it again.
258.What is drift and how do you find it?SeniorTerraform
Drift is when real infrastructure differs from state and code, usually because someone changed it by hand. terraform plan -refresh-only shows it, and a scheduled pipeline with -detailed-exitcode can alert you. Then decide whether to copy the change into code or let apply undo it.
259.How would you run Terraform safely in CI/CD?SeniorTerraform
Run fmt, validate and plan on every merge request and show the plan to reviewers. Save the plan file. Apply only from the main branch, from that saved plan, in a manual or approved job, using short-lived cloud credentials and a locked remote state.
260.How do you test Terraform code?SeniorTerraform
From cheap to costly: fmt and validate, a linter such as tflint, security scans such as Checkov or Trivy, terraform test with plan or apply runs and assertions, and Terratest for real deployments that are destroyed afterward. Run the fast ones on every push.
261.What is policy as code, and how does it fit with Terraform?SeniorTerraform
You write rules, such as no public buckets or required tags, in a policy language like Rego (OPA/Conftest) or Sentinel. The pipeline converts the plan to JSON and checks it. A failed rule stops the pipeline before anything changes.
262.How do you version and release a shared module?SeniorTerraform
Use semantic versions and Git tags or a registry. Patch means fixes, minor means backward-compatible additions, major means breaking changes. Consumers pin ranges like ~> 1.2. Keep tests, docs, examples and upgrade notes with each release.
263.A password is marked sensitive. Is it safe in state?SeniorTerraform
No. Sensitive hides the value in plan and output, but it is still stored in state in plain text. Encrypt and restrict the state, read secrets at run time from a secrets service, and use ephemeral values or write-only attributes where the provider supports them.
264.How should CI log in to the cloud?SeniorTerraform
With OIDC. The CI job gets a short-lived token and exchanges it for temporary cloud credentials. Nothing long-lived is stored, so there is nothing to leak or rotate.
265.A plan fails with an unclear error. How do you debug it?SeniorTerraform
Read the full message, then use TF_LOG=DEBUG with TF_LOG_PATH to see the API calls, test the failing expression in terraform console, and check what state holds with state list and state show. Fix, then plan again until it reports no changes.
266.What is a good way to test that a module's variable validation works?SeniorTerraform
Write a terraform test file with a run block that uses command = plan and expect_failures = [var.NAME]. The test passes when the validation rejects the bad value.
267.What does a Terraform provider need to implement for each resource?SeniorTerraform
A schema that describes its fields, plus Create, Read, Update and Delete functions that call the service API. Read also removes the resource from state if the API says it no longer exists.
268.The state lock is stuck. What do you do?SeniorTerraform
Read the error to see the lock ID and who holds it, then check that no pipeline is still running for that stack. Only when you are sure the job died, run terraform force-unlock LOCK_ID, then terraform plan to confirm state is healthy. Prevent it with CI-only applies and job timeouts that let Terraform exit cleanly.
269.An apply failed halfway. What state are you in?SeniorTerraform
Terraform saves state after each resource, so what succeeded is recorded and what failed is not. Fix the cause (permissions, quota, a bad value, an API timeout) and run plan again: it shows only the remaining work. Resources created but left broken are marked tainted and replaced on the next apply.
270.A plan says your production database will be replaced. What do you do?SeniorTerraform
Stop and don't apply. Find the attribute marked # forces replacement. A rename needs a moved block; a value changed outside Terraform needs the code aligned or ignore_changes; a change that truly needs replacement needs a planned migration (snapshot, new instance, cutover). Add prevent_destroy and the database's own deletion protection so this fails loudly next time.