Skip to content
>_ StartupJobList_

Interview questions · Worked answers

Terraform interview questions and production answers

A strong Terraform answer traces configuration address to state identity to the real remote object, then examines the plan before any change. It distinguishes code review from apply authority and explains how to recover when state or an external API disagrees.

For: Infrastructure engineers responsible for Terraform-managed environments and delivery workflows

Guide scope and versions

Terraform 1.15 language and CLI concepts with remote platform behavior kept explicit. The worked state move uses Terraform's built-in terraform_data resource and disposable local state; it does not create cloud infrastructure or prove a remote backend's locking or recovery behavior.

Question 1 of 9

What does Terraform state own, and why is one-to-one identity important?

State binds each configured resource instance to one real object and retains metadata Terraform needs to plan future changes. One remote object should not be bound to multiple Terraform addresses, or later updates and destroys become ambiguous.

A resource address is Terraform's identity in configuration; a provider ID is the remote system's identity. State connects them. Losing the mapping can make Terraform propose a duplicate create, while binding the same object twice can make one address destroy an object still expected by another.

Keep state in an access-controlled backend with locking and recovery support for a team. State may contain secrets even when the configuration marks them sensitive. Treat state readers as privileged and avoid committing state files to source control.

Follow-up: Can Terraform discover everything from provider tags instead of keeping state?

Not reliably. Providers and remote objects do not share a universal identity or query interface; state also records dependency and metadata needed for planning.

Read the source: Terraform: Purpose of State · Terraform: State

↑ Back to questions

Question 2 of 9

How do remote state and locking protect a team workflow?

A remote backend gives collaborators a shared state location; a backend that supports locking prevents overlapping writers from corrupting it. Locking is backend-dependent and is not a substitute for access control, state backups or an approval process.

Two pipelines plan from the same old state. A backend lock serializes state-writing operations, but it does not refresh a previously saved plan or make that artifact safe to apply after another run changes state. Let the stale-plan check reject it, then create and review a new plan. If lock acquisition fails, stop and identify the actual owner; do not disable locking merely to get a green pipeline.

Force-unlock only the exact lock you own after confirming the original operation is gone and automatic release failed. A stale-looking lock can still protect an active writer. Record the lock ID and recovery evidence in the operational procedure.

Follow-up: Does every backend support locking?

No. Check the selected backend's documented behavior and constraints. If it cannot provide locking, add another reliable serialization boundary or choose a backend that can.

Read the source: Terraform: State Locking · Terraform: Backends

↑ Back to questions

Question 3 of 9

What does a plan prove, and what can change before apply?

A plan describes proposed changes from configuration, current state and provider observations at plan time. It is review evidence, not a guarantee that the remote world remains unchanged; saved plans can become stale and providers can fail or observe new drift.

A console edit changes a security group after plan creation. Out-of-band drift by itself does not guarantee every saved plan will detect it. If drift is suspected, refresh or create a new plan against current remote state, inspect the proposed changes, and decide whether configuration should restore the declared value or adopt the external change. A saved plan can also be rejected as stale after state changes.

For controlled deployment, pin Terraform and provider versions, review the complete plan including destroy/replace markers, and apply the reviewed artifact under the same workspace and credentials. Separate plan and apply permissions where the risk warrants it.

Follow-up: Can a successful plan guarantee a successful apply?

No. The remote API, permissions, quotas, locks and external state can change. Apply is a separate operation with its own partial-failure and recovery behavior.

Read the source: Terraform: Planning and Applying · Terraform: Resource Drift

↑ Back to questions

Question 4 of 9

How do you rename a resource without destroying the remote object?

Change the Terraform address with a moved block so Terraform can translate the old state address to the new one. Review the plan for a move rather than create-and-destroy, keep the move declaration through the migration window, and test against the actual prior state shape.

Renaming a resource label changes its address even if its arguments are identical. Without a move declaration, Terraform can interpret the old address as removed and the new one as created. The remote object may then be destroyed and recreated, causing downtime or data loss.

A moved block is a state-refactor instruction, not a magic fix for incompatible provider changes or a mistaken object binding. For a module move, test every workspace and representative state before removing the migration declaration.

Terraform HCL · Worked example
terraform {
  required_version = "~> 1.15.0"
}

moved {
  from = terraform_data.worker
  to   = terraform_data.processor
}

resource "terraform_data" "processor" {
  input = {
    artifact = "worker-v1"
    queue    = "synthetic-jobs"
  }
}

The isolated fixture first creates terraform_data.worker, then plans this exact configuration against that local state. The assertion checks the resource is moved and no create or destroy is proposed; it creates no cloud resources.

Executed with Terraform 1.15.3 local-only state; plan JSON asserted the resource address move with no remote provider.

Follow-up: Can a moved block rename a remote resource?

It changes Terraform's state address mapping. Whether the provider updates or replaces the remote object depends on the resource arguments and provider behavior; inspect the resulting plan.

Read the source: Terraform: Refactor modules and resources · Terraform: Moved block

↑ Back to questions

Question 5 of 9

How do modules and provider constraints keep infrastructure changes reproducible?

A module should expose a small contract around a coherent ownership boundary. Pin compatible provider versions with constraints, retain the dependency lock file and review provider upgrades as code changes with their own plan and test scope.

A reusable network module can accept explicit CIDRs and return subnet IDs, while the root configuration owns environment-specific values. Avoid hidden lookups or broad defaults that make the same module behave differently without a visible input.

The lock file records selected provider packages and checksums. Version constraints express allowed updates; the lock file makes installs reproducible within that range. Upgrade intentionally, inspect provider changelogs and run a plan against representative state.

Follow-up: Should every resource be wrapped in a module?

No. Extract a module when it gives a stable reusable contract or a meaningful ownership boundary; a one-resource wrapper can hide behavior without reducing duplication or risk.

Read the source: Terraform: Modules · Terraform: Dependency Lock File

↑ Back to questions

Question 6 of 9

How do you bring an existing remote object under Terraform management?

Write matching configuration, import the existing object to exactly one resource address, and inspect the resulting plan before applying changes. Import establishes a state binding; it does not guarantee the written configuration matches every live setting.

An engineer imports an existing database but omits its retention setting. The next plan may propose a destructive change. Generate or inspect the configuration, compare important live attributes, and make the first normal plan intentionally converge without surprise replacement.

Use declarative import blocks for reviewable onboarding where supported, or the CLI import workflow with a controlled state lock. Avoid exposing import identifiers or state values in public logs if they reveal sensitive infrastructure details.

Follow-up: Does import change the remote resource?

Import records a binding in state. A later apply can change the object to match configuration, so inspect the post-import plan before applying.

Read the source: Terraform: Import existing resources · Terraform: State

↑ Back to questions

Question 7 of 9

What does marking a value sensitive protect?

Sensitive marks suppress values from normal CLI display, but the value can still be stored in state and plan files. Protect backend access, artifacts, logs and backups; do not treat a redacted terminal as secret storage.

A database password enters Terraform as a sensitive input and is written into a resource argument. The CLI may redact it, while state still contains it. Restrict state readers, encrypt storage and transport, and rotate credentials if an artifact is exposed.

Use ephemeral values only when the Terraform version and provider argument support their intended non-persistence behavior. Verify the plan/state behavior for the exact resource; do not infer that every secret-marked variable is omitted from persistence.

Follow-up: Can secrets simply be kept in environment variables?

Environment variables can reduce accidental source-control exposure, but they do not remove a secret from provider requests, plans, state or process diagnostics. Apply access controls at each storage and execution boundary.

Read the source: Terraform: Sensitive Data · Terraform: State

↑ Back to questions

Question 8 of 9

How do you reason about replacement and destroy ordering?

Read which attributes force replacement, dependency order, lifecycle settings and the availability window. Create-before-destroy may reduce downtime only when the platform permits both objects to coexist and the service can safely switch between them.

Changing an immutable network identity may require a new load balancer. If both balancers can coexist, a staged cutover may work; if the name is globally unique, create-before-destroy cannot satisfy the constraint. A lifecycle flag cannot remove the platform's uniqueness rule.

Plan replacement can still produce downtime or data loss if clients hold old endpoints, DNS caches persist, or dependent state is removed too early. Build health checks, migration steps and a rollback boundary around the specific service rather than relying on Terraform graph order alone.

Follow-up: Does prevent_destroy protect data forever?

It blocks some Terraform destroy plans while the lifecycle rule remains in configuration. It is not a backup, access-control policy or protection from manual provider-side deletion.

Read the source: Terraform: Lifecycle Meta-Arguments · Terraform: Create and Manage Resources

↑ Back to questions

Question 9 of 9

What do you do when apply partially succeeds or state writing fails?

Stop concurrent writers, preserve the exact error and state lineage, inspect both state and remote reality, then produce a fresh plan before any repair. Terraform may have completed some remote operations before a later provider or backend error.

A provider creates a subnet, then times out before returning the ID. Do not immediately rerun or manually delete resources. Inspect provider state, refresh, identify whether the object exists, and import or reconcile it using the documented recovery procedure.

If a remote backend write fails, Terraform may preserve local state to prevent data loss. Protect that file, compare lineage and serial, and follow the backend-specific recovery path. Never use force push or force unlock as generic cleanup.

Follow-up: Can a failed apply be rolled back automatically?

Not generally. Terraform applies a graph of operations and does not provide a universal reverse transaction across provider APIs. Recovery is resource- and provider-specific.

Read the source: Terraform: Backends and state persistence · Terraform: State Commands

↑ Back to questions

Salary context

Advertised salaries for these skills

These are Hacker News job posts that mention these technologies, not employee earnings or a measure of what a skill adds to pay. The amounts summarize annualized advertised minimums in approximate USD. Groups can overlap and differ in roles, locations and dates.

Terraform posts

100 posts · 100 usable advertised salary amounts

2024-06-04 to 2026-11-09

$150,000

Median advertised minimum, approximate USD/year

Middle 50%: $125,000–$170,000

Explore Terraform salaries → Browse matching job posts →
Currency and calculation basis

Approximate USD using ECB daily reference rates as of 2026-10-30. Original currencies and offer ranges remain on the source listings. These figures cover posts tagged Terraform, rather than every job in the broader technology family.

↑ Back to questions

Keep exploring