Interview Q&A · questions with model answers
Terraform Interview Questions
Part of the study plan for: DevOps Engineer · Cloud Engineer · Site Reliability Engineer (SRE)
Ordered by how often they're asked. Most-asked answers are free to read in full; members see every answer and can rate their confidence on each.
-
Most asked Walk through terraform init, plan and apply. What does each do?
init configures the backend and downloads providers and modules (recording provider versions in .terraform.lock.hcl); plan refreshes the state from real infrastructure, compares it with the…
-
Most asked How do you handle secrets in Terraform?
Keep secrets out of code and version control: read them at runtime from a secret manager (AWS Secrets Manager, Vault) through data sources or let services generate and store them (for example…
-
Most asked A terraform plan wants to destroy and recreate a database. What do you do?
Stop and find out why before applying. Look at which attribute is marked # forces replacement: a changed immutable attribute (engine version major, subnet group, identifier), a renamed resource or…
-
Most asked Workspaces, separate state files, or separate directories: how do you manage multiple environments?
Terraform CLI workspaces give one configuration several state files (dev, staging, prod) selected at runtime, which is convenient but makes environments look identical and easy to confuse. Many…
-
Most asked How do sensitive variables and outputs work in Terraform, and what are their limitations?
Marking a variable or output as sensitive = true redacts its value from CLI output and plan diffs, but the value is still stored in plain text in the state file. Sensitive does not encrypt — it only…
-
How does Terraform determine the order in which it creates resources?
It builds a dependency graph from references between resources: if one resource uses another's attribute (subnet_id = aws_subnet.private.id), Terraform creates the referenced resource first.…
-
How do you handle large-scale changes, such as a provider major version upgrade across many stacks?
Read the upgrade guide, upgrade in one non-production stack first, fix deprecations and changed defaults, and confirm the plan shows no unintended changes; then roll out stack by stack and…
-
How do you roll back a bad Terraform change?
There is no built-in rollback: revert the configuration change in Git and apply again, which moves infrastructure back to the previous declared state where possible. Destructive changes (a deleted…