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 What is Terraform, and how does it work at a high level?
Terraform is an infrastructure-as-code tool: you declare resources in HCL configuration files, and Terraform builds a dependency graph, compares the configuration with the recorded state and the…
-
Most asked What is Terraform state, why is it needed, and where should it be stored?
State maps resources in your configuration to real objects (IDs, attributes), records dependencies and metadata, and lets Terraform compute plans quickly. For teams it must be stored remotely in a…
-
Most asked What are Terraform modules, and how do you design good ones?
A module is a directory of Terraform configuration with input variables and outputs that can be called repeatedly; every configuration is a root module that may call child modules from local paths,…
-
Most asked What are the main terraform state subcommands, and when do you use them?
terraform state list shows all resources in state, show prints one resource's attributes, mv renames or moves a resource without destroying it, rm removes a resource from state without deleting the…
-
Most asked What lifecycle settings does Terraform offer, and when do you use them?
create_before_destroy creates the replacement before deleting the old resource (avoiding downtime for things like certificates or launch templates); prevent_destroy makes any plan that would destroy…
-
Most asked What is drift, and how do you detect and handle it?
Drift is a difference between the real infrastructure and what Terraform's configuration and state say, usually from manual console changes, other tools or scripts, or provider-side defaults…
-
Most asked What are the most common Terraform mistakes you have seen in teams?
Local state or state in Git; no locking; one giant state for everything; using count for collections; unpinned providers; secrets in variables files committed to Git; manual console changes causing…
-
Most asked What does terraform plan -target do, and why is it risky?
-target tells Terraform to plan and apply only the named resource (and its dependencies). It is meant for exceptional recovery situations, not normal workflow, because it leaves state partially…
-
What is policy as code for Terraform, and which tools are used?
Policy as code checks Terraform changes against rules automatically before they are applied: no public S3 buckets, required tags, encryption on, approved instance types or regions. Tools include…
-
What do dynamic blocks, for expressions and conditionals give you, and when do they hurt?
for expressions transform lists and maps, conditionals (cond ? a : b) choose values, and dynamic blocks generate repeated nested blocks (such as security group rules or tags) from a collection. They…
-
What are provisioners, and why are they considered a last resort?
Provisioners (local-exec, remote-exec, file) run scripts during resource creation or destruction. HashiCorp recommends them only as a last resort because their effects are not tracked in state, they…
-
What does 'known after apply' mean, and why can it cause problems?
Some values are only known once a resource is created (IDs, generated passwords, IP addresses). During plan, Terraform shows them as (known after apply). Anything depending on them is also unknown,…
-
What are check blocks and pre/postconditions used for?
Preconditions and postconditions (in lifecycle blocks of resources, data sources and outputs) assert assumptions and fail the plan or apply with a clear message when they are violated; check blocks…
-
What is Terragrunt, and when is it useful?
Terragrunt is a thin wrapper around Terraform/OpenTofu that keeps configurations DRY across many environments and accounts: it generates backend and provider configuration, passes common inputs from…
-
What is HCP Terraform (Terraform Cloud), and what does it add?
HCP Terraform is HashiCorp's managed service for running Terraform: remote state storage with locking, remote plan and apply runs, VCS-driven workflows, team permissions, a private module and…
-
What is Terraform's resource graph parallelism, and when would you change it?
Terraform walks the dependency graph and performs up to 10 independent operations at once by default (-parallelism=n). Lowering it helps when a provider or API rate-limits you (many resources…