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 46–60 of 126 questions
46.What is a module?MidTerraform
A folder of Terraform files used as a reusable package, with variables as inputs and outputs as results. Call it with a module block and different values per environment. Pin the version when it comes from a registry or Git.
47.Workspaces or separate folders for environments?MidTerraform
Workspaces keep several states in one backend and are quick to start, but it is easy to run in the wrong one and the code is shared exactly. Separate folders give each environment its own backend, variables and access rules, which is safer for production. Many teams choose folders or separate pipelines.
48.A plan wants to destroy and recreate a resource you only renamed. What do you do?MidTerraform
Add a moved block (or run terraform state mv) so Terraform knows the new address is the same object. Plan again and confirm that it shows no destroy.
49.How do you bring an existing, hand-made resource under Terraform?MidTerraform
Write an import block with the resource address and the real id, run plan (optionally with -generate-config-out to get draft code), fix the code until the plan shows no changes, then apply to record it in state.
50.What does the cidrsubnet function do?MidTerraform
It cuts a smaller network out of a bigger one. cidrsubnet("10.0.0.0/16", 8, 1) gives 10.0.1.0/24: it adds 8 bits to the mask and picks network number 1. It lets you build subnets from one base range with no hand math.
51.When do you use templatefile?MidTerraform
When you need a text file, such as a startup script or config, with values filled in. You write the file with placeholders and call templatefile with a map of values.
52.What is the difference between a precondition, a postcondition and a check block?MidTerraform
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.
53.How do you replace a resource that is broken without touching others?MidTerraform
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.
54.How do you make resources in two regions?MidTerraform
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.
55.Two engineers run terraform apply at the same time. What happens?MidTerraform
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.
56.What happens if you delete a resource block from your code?MidTerraform
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).
57.How do you roll back a Terraform change?MidTerraform
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).
58.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.
59.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.
60.Why prefer modules over command or shell?MidAnsible
Modules check the current state and only change what is needed, and they report changed correctly. command and shell run blindly, so you must add creates or changed_when to make them safe.