Interview questions

Terraform Interview Questions

17 Terraform interview questions on state, modules, plan and apply, drift, imports and team workflows, with model answers for candidates and interviewers.

Terraform Interview Questions

What's here

17 Terraform interview questions, grouped into 4 areas: core concepts, state, modules and structure and team workflows and scenarios. Each one comes with why it is worth asking and what a strong answer contains, so the same question can be scored the same way by different interviewers.

  • Spend real time on state; most production Terraform incidents start there
  • Give a short plan output and ask the candidate to explain what will happen and whether it is safe
  • Ask how they would refactor a resource without recreating it
For hiring teams

Cohesyve finds, contacts and tests Terraform candidates on the real work, then ranks them for these interviews. 14-day free trial for 10 candidates, not charged until it ends.

Preparing for this interview yourself? Practise it free →

Terraform interview questions come up for DevOps engineers, cloud engineers, platform engineers and SREs. Terraform is HashiCorp's infrastructure as code tool: you describe infrastructure in configuration files, and Terraform plans and applies the changes through providers for cloud platforms and other services. Interviewers want to see that a candidate understands state, writes reusable modules and can run Terraform safely in a team. Candidates can use the 'what to look for' notes as model answers; interviewers can use them as a scoring guide.

Core Concepts

The foundations every Terraform interview checks.

  1. 1

    What is infrastructure as code, and why use Terraform for it?

    Why ask it

    A warm-up that shows whether the candidate understands the purpose.

    What to look for

    Managing infrastructure through versioned configuration instead of manual changes: repeatable environments, review through pull requests, and an audit trail. Terraform is declarative, works across many providers with one workflow, and shows a plan before changing anything.
  2. 2

    Walk me through the Terraform workflow: init, plan and apply.

    Why ask it

    The basic commands reveal day-to-day experience.

    What to look for

    terraform init downloads providers and modules and configures the backend; terraform plan compares configuration with state and real infrastructure and shows proposed changes; terraform apply makes the changes. Strong candidates mention saving a plan file and applying that exact plan in pipelines, plus fmt and validate as checks.
  3. 3

    What are providers, resources and data sources?

    Why ask it

    The building blocks of every configuration.

    What to look for

    Providers are plugins that talk to an API (a cloud platform, DNS service and so on). Resources are objects Terraform creates and manages. Data sources read information about existing objects that Terraform does not manage, such as an existing network or image.
  4. 4

    What are variables, outputs and locals?

    Why ask it

    Shows how the candidate structures configuration.

    What to look for

    Input variables parameterise configuration (with types, defaults, validation and a sensitive flag where needed); outputs expose values to users or other configurations; locals name computed values to avoid repetition. Good answers mention keeping environment-specific values in variable files.
For hiring teams

Before the Terraform interviews, see who can do the work

Cohesyve finds and contacts Terraform candidates from your job description and tests each one on an AI job simulation of the role, so these questions go to a ranked shortlist. 14-day free trial for 10 candidates, not charged until it ends.

State

State is where most Terraform problems start, so interviewers spend time here.

  1. 5

    What is Terraform state, and why does it exist?

    Why ask it

    The most important Terraform concept.

    What to look for

    State records the binding between resources in configuration and real objects in the remote system, along with metadata. Terraform uses it to work out what to change, track dependencies and improve performance on large infrastructures.
  2. 6

    Why should state be stored remotely, and what is state locking?

    Why ask it

    Shared state handled badly causes corruption and outages.

    What to look for

    Local state limits collaboration and can be lost. A remote backend (such as HCP Terraform or cloud object storage) shares state and, on backends that support it, locks state automatically during operations that write to it, so two runs cannot corrupt it. HashiCorp advises against keeping state in version control. force-unlock is a last resort for releasing your own stuck lock.
  3. 7

    Why is the state file sensitive, and how do you protect it?

    Why ask it

    Leaked state can expose secrets.

    What to look for

    State is stored in plain text and can contain secret values from the configuration, so anyone who can read it can read them. Protect it by storing it remotely, encrypting it at rest, restricting access and auditing access, and keeping it out of Git.
  4. 8

    How do you bring an existing, manually created resource under Terraform management?

    Why ask it

    Very common in real environments.

    What to look for

    Use an import block with the resource's ID and a matching resource block, then plan and apply; or let terraform plan with the -generate-config-out option draft the resource configuration, then review and tidy it. Older workflows used the terraform import command. Check the plan shows no unexpected changes afterwards.
  5. 9

    You renamed a resource and the plan now wants to destroy and recreate it. What do you do?

    Why ask it

    A classic refactoring trap.

    What to look for

    Add a moved block from the old address to the new one, so Terraform updates the address in state instead of destroying the object. Keep the moved block in the configuration afterwards. terraform state mv is the older command-line alternative.

Modules and Structure

How the candidate keeps Terraform reusable and maintainable.

  1. 10

    What is a module, and what makes a good one?

    Why ask it

    Modules are how teams reuse infrastructure code.

    What to look for

    Any directory of Terraform files is a module; reusable modules take inputs and expose outputs. Good modules have a clear purpose, sensible defaults, input validation, documentation and pinned versions when consumed. Over-wrapping single resources in modules adds complexity without value.
  2. 11

    How do you manage multiple environments such as dev, staging and production?

    Why ask it

    A design decision every team makes.

    What to look for

    Common approaches: separate root configurations or directories per environment calling shared modules, separate state per environment, variable files per environment, or workspaces for near-identical environments. Strong candidates explain the trade-offs, such as workspaces making it easy to apply to the wrong environment.
  3. 12

    What is the difference between count and for_each?

    Why ask it

    A frequent source of unwanted resource replacement.

    What to look for

    count creates instances indexed by number, so removing an item from the middle of a list shifts indexes and can recreate resources. for_each creates instances keyed by map keys or set values, so changes affect only the matching instance. for_each is usually safer for collections.
  4. 13

    How do you pin provider and module versions, and why?

    Why ask it

    Unpinned versions cause surprise changes.

    What to look for

    Version constraints in required_providers and module sources, a committed dependency lock file, and deliberate upgrades tested through plan. This keeps runs reproducible across machines and pipelines.

Team Workflows and Scenarios

Running Terraform safely with other people.

  1. 14

    How would you set up a CI/CD pipeline for Terraform?

    Why ask it

    Most teams apply changes through pipelines.

    What to look for

    On pull requests: fmt, validate, linting or policy checks and a plan posted for review. On merge: apply the reviewed plan with credentials held by the pipeline, not by individuals. Separate pipelines or approvals for production.
  2. 15

    What is drift, and how do you detect and handle it?

    Why ask it

    Manual changes happen even in disciplined teams.

    What to look for

    Drift is when real infrastructure differs from configuration and state, usually from manual changes. Detect it with scheduled plans or refresh-only plans; then either update the configuration to match the intended change or apply to revert it. Prevent it by limiting console write access.
  3. 16

    A terraform apply failed halfway through. What do you do?

    Why ask it

    Tests calm troubleshooting.

    What to look for

    Read the error, check what was created (Terraform records completed resources in state), fix the cause, and run plan again to see the remaining changes before applying. Release a stuck lock only if they are sure no other run holds it.
  4. 17

    How do you handle secrets in Terraform?

    Why ask it

    Secrets in code or state are a common risk.

    What to look for

    Never hard-code secrets in configuration; pass them from a secrets manager or environment variables, mark variables and outputs as sensitive, and protect the state, since values can still end up there. Ephemeral values, which Terraform keeps out of state and plan files, are an option for some cases.

Running the interview well

  • 1Spend real time on state; most production Terraform incidents start there
  • 2Give a short plan output and ask the candidate to explain what will happen and whether it is safe
  • 3Ask how they would refactor a resource without recreating it
  • 4Probe environment strategy and the trade-offs of their chosen approach
  • 5Check secret handling and state protection for any role with production access
  • 6Ask about a Terraform change that went wrong and what they changed afterwards

Common questions

What are the most common Terraform interview questions?

The init, plan and apply workflow, what state is and why it is stored remotely, state locking, modules, count versus for_each, managing environments, importing existing resources, refactoring with moved blocks, drift and handling secrets.

How should I prepare for a Terraform interview?

Build a small project on a cloud free tier with a remote backend, a reusable module and two environments. Practise importing a resource, renaming one with a moved block and fixing drift. Be ready to read a plan output and explain it.

Do I need a certification for Terraform roles?

HashiCorp offers Terraform certifications, including Terraform Associate, and some employers list them as a plus. Hands-on experience with state, modules and team workflows usually matters more in interviews.

What is the difference between Terraform and tools like Ansible?

Terraform is mainly used to provision and manage infrastructure declaratively with state. Configuration management tools such as Ansible are mainly used to configure software on existing machines. Many teams use both.

Are Terraform interview questions different for DevOps and cloud roles?

The core is the same. Cloud engineer interviews often go deeper into a specific provider's resources, while DevOps and platform interviews focus more on pipelines, modules for other teams and policy checks.

For hiring teams

Save these questions for the Terraform candidates who can do the work

Cohesyve takes your Terraform job description, finds candidates, reaches out to them and runs an AI job simulation of the real work, then returns a ranked shortlist.

1,500+

assessments completed

50%

faster time-to-hire

5 min

from JD to assessment

14-day free trial · 10 candidates · Not charged until the trial ends

For job seekers

Preparing for a Terraform interview yourself? Practise on an AI job simulation of the role. 3-day free trial, cancel anytime.

Practise a Terraform interview free →

See Cohesyve in action

Free 30-min walkthrough

See it on your role