Terraform Interview Questions With State and Module Scenarios
Prepare for Terraform interview questions by explaining how configuration, state and the selected environment determine a proposed change. For module scenarios, trace the input contract, resource addresses and outputs before discussing refactoring. Review what a plan establishes and how an authorised change would be verified.
Prepare for Terraform interview questions by explaining how configuration, state and the selected environment determine a proposed change. For module scenarios, trace the input contract, resource addresses and outputs before discussing refactoring. Review what a plan establishes and how an authorised change would be verified.
This guide contains original interview practice scenarios. Documentation was checked on 17 November 2026; the local-module configuration and commands were documentation-reviewed and were not executed. Use a new private practice directory and an existing authorised Terraform installation for any rehearsal.
Keep the change context explicit
- Identify the backend, workspace and configuration.
- Protect state and plan artifacts.
- Trace module inputs and instance addresses.
- Separate validation, proposed changes and observed results.
State questions: bindings and recovery
1. Why does Terraform need state?
State connects configured resource instances with the remote objects Terraform manages. HashiCorp documents an expected one-to-one mapping between those instances and objects. Explain that relationship before proposing any manual state operation. [1]
2. Is a source repository enough to recover a project?
Ask which recovery problem is being discussed. Configuration describes intended management; state records bindings and other operational information. A repository copy alone does not establish that those bindings, backend access or recovery records are available.
Identify the state owner and approved backup or recovery process. Keep state contents private when discussing a real project. In an interview, explain which evidence you would request without inventing a successful restoration.
For broader revision, see the WebAsha Terraform question guide. Use your actual project scope when discussing personal experience.
Scenario: remote state is assumed to be isolated
3. Does marking a variable sensitive keep it out of state?
The sensitive argument redacts values in supported output, but those values are still stored in state and plan files. HashiCorp distinguishes redaction from mechanisms that omit values from those artifacts. [2] Protect access to the artifacts as well as the configuration.
4. Do CLI workspaces provide separate access controls?
CLI workspaces provide separate state instances within a configuration’s backend arrangement. HashiCorp says they are not appropriate for deployments requiring separate credentials and access controls. [3]
Ask how the actual environment separates access and ownership. A workspace name by itself does not establish a production boundary. Distinguish CLI workspaces from the workspace concepts used by other Terraform services.
Scenario: a pipeline cannot acquire a lock
5. What do you inspect first?
Identify the backend, selected state, operation and potential active owner. On backends that support it, Terraform locks state for operations that could write it. HashiCorp warns against bypassing locking. [4]
A long-running operation and a failed unlock need different responses. Check the run records and coordinate with the owner before deciding what happened. A lock message alone does not prove that the lock is stale.
6. When is force unlocking appropriate?
HashiCorp limits force unlocking to your own lock when automatic unlocking failed and warns that releasing another active writer’s lock can permit multiple writers. [4]
Explain how you would establish that condition and what state verification would follow. No unlock command is provided or executed in this article. Do not treat removing a lock as proof that an interrupted infrastructure change completed correctly.
Module questions: interface and responsibility
7. What is the relationship between a root and child module?
A module call selects source code and supplies inputs to a child module. The caller uses the child’s exposed outputs rather than assuming arbitrary internal details are part of its interface. Review the actual source and input contract before describing its behaviour. [5]
8. How would you make an input error clearer?
Use an appropriate type and a validation rule for the module’s intended contract. HashiCorp documents input-variable types and validation conditions as ways to constrain supplied values. [6]
Keep the validation focused on what the module can establish. A permitted environment label can be checked locally. Whether a remote account is the intended account needs additional context and verification.
A local-module exercise without resource provisioning
9. How would you explain this input contract?
In a new private directory, save the first block as modules/labels/main.tf and the second as the root main.tf. These are the complete example files. They define a local child module and outputs, with no resources, providers or configured remote backend.
variable "environment" {
type = string
validation {
condition = contains(["dev", "test"], var.environment)
error_message = "Use dev or test for this practice module."
}
}
output "label" {
value = "app-${var.environment}"
}
module "labels" {
source = "./modules/labels"
environment = "dev"
}
output "project_label" {
value = module.labels.label
}
Explain why the child accepts only the two named labels and how the root supplies its input. With the shown input, the expression is intended to produce app-dev. That value is derived by reading the example, not reported as executed Terraform output.
10. What does validation establish?
Terraform validate checks configuration consistency and requires an initialised directory with referenced modules and plugins available. HashiCorp documents init with backend disabled for configuration validation. [7]
For this new example directory only, the commands below prepare local module metadata and validate the configuration. Init writes local working-directory data; it is not a no-change filesystem operation.
terraform init -backend=false
terraform validate
The intended outcome is a validation result for the supplied files. No command was executed here. Validation does not prove that a real provider account, infrastructure plan or application deployment is correct. Do not copy the exercise into a directory that contains an existing project or state.
Scenario: changing a module source or provider selection
11. Can you use version with a local module source?
The module version argument applies to registry modules. HashiCorp states that local-path modules do not support it because they share the source repository version with the caller. [5] In the exercise, review and version the source files together.
12. What else would you inspect before a module upgrade?
Check the selected source, change notes, input/output contract and provider requirements, then review the proposed changes in the intended environment. Record the previous selection so a reviewer can understand the change.
If the scenario involves multiple provider configurations, identify which configuration the module call receives. A module name or region-like input is not sufficient evidence of the account or provider configuration actually used.
Keep the answer within the module’s documented compatibility and the installed Terraform release. A successful upgrade in one lab does not establish that every caller’s state follows the same path.
Scenario: count or for_each changes instance identity
13. How do count and for_each identify instances?
Count uses numerical instance indexes. For_each uses keys from its collection, so the chosen keys become part of instance identity. Explain the addresses before discussing how a collection change affects the plan. [8] [9]
14. What if a for_each key depends on a value available only after apply?
The map keys or set members that identify for_each instances must be known before remote operations. An apply-generated identifier is therefore not a suitable basis for determining those instance keys. [9]
Look for a stable configuration-defined identity and keep remote-generated attributes as values where appropriate. Do not promise that changing from count to for_each is automatically harmless; the old and new addresses need to be accounted for.
In a rehearsal, change a key or list order and explain which address relationship needs review. Describe the proposed effect without pretending an unexecuted plan was observed.
Scenario: moving a resource into a module
15. Why could a rename appear as replacement work?
Terraform tracks configured addresses, so a refactor needs to preserve the relationship between the old and new addresses. HashiCorp documents moved blocks with from and to addresses to record supported resource or module moves. [10]
Inspect the existing bindings, intended destination and full plan before deciding the change is only structural. Other configuration or provider changes may still introduce real infrastructure work.
16. Can old moved blocks always be removed?
HashiCorp describes removing historical moved blocks as a breaking change because callers that still use old addresses can lose the recorded upgrade path. [10]
Ask which callers have upgraded and what evidence confirms that history. A module maintainer should preserve the supported migration path rather than assuming every user applied each intermediate version.
Scenario: validate passes but the plan is unexpected
17. What is different about a plan?
A plan evaluates proposed changes in a run context. The plan command itself does not carry out those changes. It can still inspect existing infrastructure through providers, and plan artifacts need appropriate protection. [11]
Check the selected configuration, input values, workspace, backend and provider context. A valid configuration can target an unintended environment. Establish those inputs before changing resource arguments to make an unexpected plan disappear.
18. How do you review a proposed change?
Read the affected addresses and operations, including removals and replacements. Ask whether each operation matches the intended task and what downstream service checks are required. A summary count alone leaves important details unresolved.
| Check | Question |
|---|---|
| Target | Which backend, state, workspace and provider context apply? |
| Inputs | Which values and module sources were selected? |
| Identity | Do old and new addresses describe the intended objects? |
| Operations | What would be created, changed, replaced or removed? |
| Permission | Who owns the decision to proceed? |
| Verification | Which infrastructure and service observations are needed afterward? |
A plan is proposed work. Report an applied change only when it was authorised, performed and checked in the actual environment.
Practise explaining the evidence and the limits
19. How would you present a real Terraform project?
Describe its purpose, your contribution, the authorised environment and the records supporting the result. Distinguish a reviewed plan from an applied change and an infrastructure result from application health.
The WebAsha automation workflow guide provides broader context. Keep private state and credentials out of the interview material.
20. What if the scenario is incomplete?
State the missing information and the next check that would clarify it. A lock, input error and unexpected replacement have different evidence. Keep a proposed correction separate from one you executed.
Use the WebAsha Terraform revision guide for additional prompts, then rehearse a changed version of the scenario using your own words.
Discuss Terraform and DevOps training with WebAsha Technologies. Contact WebAsha with your starting skills and the state or module scenarios you want to practise.
Official references
- HashiCorp: Terraform state
- HashiCorp: Manage sensitive data
- HashiCorp: State workspaces
- HashiCorp: State locking
- HashiCorp: Module block reference
- HashiCorp: Input variables
- HashiCorp: Validate command
- HashiCorp: count reference
- HashiCorp: for_each reference
- HashiCorp: Refactor modules
- HashiCorp: Plan command
Frequently Asked Questions
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Wow
0
Sad
0
Angry
0