Skip to content
$ lynuxpro

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 16–30 of 42 questions

Learn Terraform →
16.What is the difference between a precondition, a postcondition and a check block?Mid

A precondition is tested before a resource is made and stops the run if false. A postcondition is tested after and also stops the run. A check block tests anything in the whole setup and only prints a warning, so it suits health checks.

17.How do you replace a resource that is broken without touching others?Mid

Use terraform apply -replace=ADDRESS. It is shown in the plan, so it can be reviewed. The older terraform taint command changed state before any review and is deprecated.

18.How do you make resources in two regions?Mid

Add a second provider block with an alias and a different region. Pick it on a resource with provider = aws.alias. For modules, pass it in with the providers argument.

19.Two engineers run terraform apply at the same time. What happens?Mid

With a locking backend, the second run fails with a lock error until the first finishes; that is what the lock is for. Without locking, both can write state at once and corrupt it or create duplicates. Use a backend with locking and run applies only from CI so there is one path to change.

20.What happens if you delete a resource block from your code?Mid

The next apply destroys the real resource. If you want to keep it but stop managing it with Terraform, use a removed block with destroy = false (or terraform state rm on older versions).

21.How do you roll back a Terraform change?Mid

There is no rollback button. Revert the commit and apply again so the code puts things back. If the state file itself is broken, restore an earlier version from the backend's versioning (for example S3 versioning).

22.Why does my plan show a change every time even though nothing changed?Mid

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.

23.terraform apply says the resource already exists. Why?Mid

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.

24.What is drift and how do you find it?Senior

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.

25.How would you run Terraform safely in CI/CD?Senior

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.

26.How do you test Terraform code?Senior

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.

27.What is policy as code, and how does it fit with Terraform?Senior

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.

28.How do you version and release a shared module?Senior

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.

29.A password is marked sensitive. Is it safe in state?Senior

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.

30.How should CI log in to the cloud?Senior

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.