Infrastructure as Code Interview Questions: Terraform Reasoning
Infrastructure as code interviews test whether you can review a proposed infrastructure change safely. Explain the roles of configuration, state and providers, then distinguish a plan from an applied result. Terraform locking and secret protection depend on the chosen backend and features. In the worked review below, a database replacement blocks approval even though the source change looks small.
Topic: DevOps & Platform Engineering in IT Infrastructure · Interview preparation
Quick answer: Infrastructure as code interviews test whether you can review a proposed infrastructure change safely. Explain the roles of configuration, state and providers, then distinguish a plan from an applied result. Terraform locking and secret protection depend on the chosen backend and features. In the worked review below, a database replacement blocks approval even though the source change looks small. Use the questions to practise explaining that decision without running infrastructure commands.
Key takeaways
- Separate configuration, state and observed remote objects.
- Read replacement and deletion actions before approving a plan.
- Check backend locking separately from the provider dependency lock file.
- Treat saved state and plan files as potentially sensitive.
- Review lifecycle protections together with configuration removal and external permissions.
Table of Contents
- What does infrastructure as code actually manage?
- Why does Terraform need state?
- What would make you reject an apparently small plan?
- How do state locking and dependency locking differ?
- Does marking a value sensitive keep it out of state?
- What can prevent_destroy and drift checks prove?
- How would you bring an existing resource under code?
- What should a complete review handoff contain?
- References
What does infrastructure as code actually manage?
Infrastructure as code expresses infrastructure intent in files that can be reviewed and versioned. A declarative tool works toward a described result; an imperative script specifies actions. Both still need correct credentials, clear ownership and suitable failure handling.
An interview follow-up might ask whether version control makes a change safe. It gives a history and a review mechanism, but a reviewed file can still target the wrong account or replace a critical database. Name the execution context as well as the code revision.
For a small team, a reusable network module can reduce repeated configuration. The module interface should expose the choices the team needs, while its outputs make dependencies explicit. Copying a module without understanding its provider requirements or resource ownership can reproduce the same mistake across several environments.
Why does Terraform need state?
The Terraform state guide explains how Terraform binds resource instances in configuration to remote objects. State supports comparisons and dependency handling; it is not the same thing as the configuration repository.
If two teams independently manage the same remote database through different state files, each can make decisions without seeing the other's ownership intent. Ask who owns the object and which state contains its binding before proposing an import or removal.
A useful answer also distinguishes a missing state binding from a missing remote object. An object may still exist after its binding is removed. Conversely, a state record can refer to an object that was changed or deleted elsewhere. Review the evidence through supported tooling and keep an audit trail rather than casually editing the stored representation.
What would make you reject an apparently small plan?
A plan describes proposed actions, including changes that a small source edit can cause indirectly. The Terraform plan reference explains that planning alone does not execute those proposed infrastructure changes, while normal planning can read remote object information.
Consider this invented review. A colleague changes the database storage setting, expecting an in-place update. The supplied plan summary instead shows replacement of the database, an updated application connection value and no migration evidence. Reject approval until the owner explains the replacement and demonstrates the agreed data-preservation approach.
Do not approve from action totals alone. One destructive action on a critical database can outweigh dozens of harmless changes. Compare resource addresses, target environment, provider context and relevant attributes. A speculative plan can become outdated before a later execution.
| Supplied review item | Interpretation | Decision |
|---|---|---|
| Database marked for replacement | Existing object may be destroyed and recreated | Hold for data and availability review |
| Connection value changes | Applications may need coordinated configuration | Require dependent application acceptance |
| No approved migration evidence | Continuity has not been established | Do not treat a clean syntax check as approval |
How do state locking and dependency locking differ?
State locking coordinates writers when the backend supports it. The Terraform state locking guide explicitly says that not all backends provide locking. A remote location alone is insufficient evidence that concurrent writes are protected.
The Terraform dependency lock file guide describes a different lock file: it records provider selections and checksums. It does not serve as a distributed mutex for state, and it does not lock every remote module version.
In an interview, explain how you would investigate a lock conflict: establish the run owner and whether an operation is still active. Disabling the lock or forcing an unlock without that context risks competing writers. A cancelled pipeline display also needs reconciliation with the actual execution status before another run proceeds.
Does marking a value sensitive keep it out of state?
The Terraform sensitive data guide distinguishes redaction from omission. The sensitive setting hides ordinary display of values, but those values can remain in state and saved plans. Restrict access to those files and their retained copies.
Current Terraform also has ephemeral and write-only mechanisms under specific version, context and provider requirements. Explain the feature you intend to use and confirm its support, rather than claiming that a single sensitive flag prevents storage everywhere.
For the database review, exclude passwords and full connection secrets from the approval comment. Reviewers can refer to protected evidence by an access-controlled identifier. The review still needs to establish how the application receives its credential and how its access is scoped; omitting the secret text does not remove that design responsibility.
What can prevent_destroy and drift checks prove?
The Terraform lifecycle reference says prevent_destroy rejects relevant destructive plans while its configuration is present. Removing the resource configuration also removes that protection from Terraform's decision. It is not a universal safeguard against deletion through other tools or identities.
Drift means observed remote properties differ from recorded or intended configuration. First establish why: an authorised emergency change may need reconciliation into code, while an accidental change may need reversal. Reapplying automatically can erase an intentional correction.
Provider visibility and lifecycle rules influence what a plan reports. An unchanged plan is useful evidence within that scope, not proof that every operational or security property of the environment is correct. Review identity, data protection and application behaviour separately.
How would you bring an existing resource under code?
First establish its current owner, exact provider identity and whether another state already manages it. The Terraform import resources guide describes import blocks and workflows that can generate configuration for review. Import is an ownership and configuration exercise, not permission to accept every discovered setting.
Consider an existing audit bucket created during an emergency. The new team proposes declaring a bucket with the same display name and assuming Terraform will adopt it. Ask for its actual provider identity and an approved destination resource address. A display name alone is insufficient to establish the intended binding.
Review the resulting configuration and proposed actions before allowing ongoing management. If the configuration proposes changing access or retention, separate those changes from the adoption decision. The object already contains operational data, so a successful import would not justify unreviewed policy changes. Record which team will own future drift decisions and remove any conflicting management arrangement through the agreed process.
What should a complete review handoff contain?
Give the reviewer the source revision, execution context, dependency selections and final plan identifier. Explain resource ownership, expected changes and the observations that must pass afterward. Name the person who can approve a consequential deviation.
In the database case, approval remains held until the database owner provides the migration method, application owner confirms connection handling and operations agrees how service acceptance will be measured. A revised plan must be reviewed if the proposed actions or execution context change.
Rolling back a Git commit can restore configuration intent, but it cannot automatically reverse deleted records or an incompatible data migration. Say what can be recreated and what requires recovery. This makes the answer useful during both an interview and an actual change review.
| Evidence to retain | Why the next reviewer needs it |
|---|---|
| Configuration revision and provider selections | Identify exactly what was evaluated |
| Final plan and environment identity | Avoid approving an unrelated or outdated proposal |
| Data and application acceptance criteria | Distinguish completed execution from a usable service |
Related reading: Cloud native development questions; Cloud automation questions.
References
Frequently Asked Questions
What's Your Reaction?
Like
0
Dislike
0
Love
0
Funny
0
Wow
0
Sad
0
Angry
0