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.

Aug 13, 2024 - 14:08
Updated: 
105.1k

DevOps & Platform Engineering in IT Infrastructure · Interview preparation

Infrastructure as Code Interview Questions: Terraform Reasoning

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?

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 itemInterpretationDecision
Database marked for replacementExisting object may be destroyed and recreatedHold for data and availability review
Connection value changesApplications may need coordinated configurationRequire dependent application acceptance
No approved migration evidenceContinuity has not been establishedDo 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 retainWhy the next reviewer needs it
Configuration revision and provider selectionsIdentify exactly what was evaluated
Final plan and environment identityAvoid approving an unrelated or outdated proposal
Data and application acceptance criteriaDistinguish completed execution from a usable service

Related reading: Cloud native development questions; Cloud automation questions.

References

Frequently Asked Questions

No. Locking depends on the backend and its configuration, so verify its documented behaviour before relying on concurrent-write protection.

No. It records provider dependency selections and checksums, while state locking coordinates operations that could write the same state.

The command previews proposed changes rather than applying them, but ordinary planning can read remote resources and requires appropriate access.

Yes. Provider rules and changed attributes can require replacement, so inspect the actual resource actions and data implications.

The sensitive flag primarily controls display; stored state and plan files can still contain values that require access protection.

Its protection must remain in configuration; removing the resource block can permit destruction, so review deletion intent explicitly.

Investigate its owner and reason first, since an emergency correction may need to be incorporated into the intended configuration.

No deployment was run; the supplied review case teaches plan interpretation and approval evidence without exercising a provider or backend.

What's Your Reaction?

Like Like 0
Dislike Dislike 0
Love Love 0
Funny Funny 0
Wow Wow 0
Sad Sad 0
Angry Angry 0
Anjali

I am passionate about technology, invention and big challenging tasks on my to- do list. In terms of the work I am doing also at Bunnyshell, I am most passionate about the technologies that we are using., I'm devoted to delivering content that not only informs but also inspires. Whether you need in- depth analysis pieces, educational attendants, or study- provoking opinion pieces, I draft content that resonates with tech suckers and professionals likewise.