Terraform Interview Questions and Answers (2026)

Terraform Interview Questions 2026

Last updated: 25 November 2026

Short answer: Terraform interviews are mostly about state: where it lives, how it's locked, and how you fix it when it drifts or breaks. Freshers get the workflow and basic HCL. With 2–5 years, you get remote backends, modules, import and refactoring. Senior rounds are scenarios: a plan that wants to destroy a database, a lost state file, CI/CD for 50 services. Below are 35 questions with short answers. In a Weekday analysis of 400 top Reddit posts from the last 30 days, interview rounds and assessments came up in 93, so expect a hands-on round. On 25 November 2026, Terraform appeared in 78 of the first 1,000 DevOps listings on Weekday.

Terraform 1.17 is the newest release line. It came out on 21 October 2026, and 1.17.2 followed on 11 November 2026 (endoflife.date). Most interview questions don't depend on the exact version, but a few modern features do, like import blocks and native S3 locking. The answers below say which version added them.

What Terraform interviewers actually test

We read the first 1,000 listings on Weekday's DevOps engineer jobs page on 25 November 2026 and counted how many named each tool in the title, skill tags or summary.

SkillListings that mention it (of 1,000)
AWS174
Azure124
Kubernetes110
Terraform78
GCP60
Ansible26

Summaries are short, so these are floor numbers. Terraform rarely shows up alone. It's asked for with a cloud and Kubernetes. So expect Terraform questions that use AWS or Azure resources, and be ready to talk about how your Terraform code and your cluster fit together.

Rounds are getting heavier. A r/jobs thread titled "Is this normal? 9 round interviews???" drew 659 comments, and a r/recruitinghell post about a junior role whose assessment was the company's Q3 backlog got 5,884 upvotes. If you get a take-home, it'll likely be "write a module" or "fix this broken config".

Terraform interview questions for freshers

1. What is Terraform?

An infrastructure as code tool. You describe the end state in HCL, and Terraform works out what to create, change or delete through providers that talk to cloud APIs.

2. What's the core workflow?

terraform init      # download providers and modules, set up the backend
terraform plan      # show what will change
terraform apply     # make the changes
terraform destroy   # delete everything in this configuration

3. What is a provider, and how do you pin its version?

A plugin that knows one platform's API. Pin it in required_providers. ~> 4.0 allows any 4.x but not 5.0.

terraform {
  required_version = ">= 1.11"
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "~> 4.0"
    }
  }
}

4. What is the state file?

Terraform's record of what it manages, mapping resources in code to real objects. It can hold secrets in plain text, so never commit it to Git. Store it in a remote backend.

5. What does .terraform.lock.hcl do?

It records the exact provider versions and checksums chosen by init. Commit it, so everyone and every pipeline uses the same provider builds. Run terraform init -upgrade to move to newer versions on purpose.

6. Variables, locals and outputs?

Variables are inputs. Locals are named values computed inside the module. Outputs expose values to the caller or to the CLI.

7. In what order are variable values applied?

Later sources win: environment variables (TF_VAR_name), then terraform.tfvars, then terraform.tfvars.json, then *.auto.tfvars files in name order, then -var and -var-file on the command line.

8. Resource vs data source?

A resource is something Terraform creates and manages. A data source only reads something that already exists, like an existing VNet or the latest image ID.

9. What are modules?

Folders of Terraform code you call with a module block. The folder you run commands in is the root module. Pin registry modules with version so updates don't surprise you.

10. count or for_each?

count makes N copies addressed by index. for_each uses map keys or set values. Prefer for_each for lists of named things, because removing one item from a count list shifts indexes and recreates the others.

resource "azurerm_resource_group" "env" {
  for_each = toset(["dev", "staging", "prod"])
  name     = "rg-app-${each.key}"
  location = "centralindia"
}

11. What do fmt and validate do?

terraform fmt rewrites files in the standard style. terraform validate checks syntax and internal consistency without calling cloud APIs. Run both in CI.

12. Terraform vs Ansible vs CloudFormation or Bicep?

Terraform provisions infrastructure on many clouds and keeps state. Ansible is mainly for configuring servers. CloudFormation and Bicep are AWS-only and Azure-only, with state handled by the cloud.

Terraform interview questions for 2–5 years

13. How do you set up a remote backend with locking?

On AWS, use S3 with native locking. use_lockfile became generally available in Terraform 1.11, which also deprecated DynamoDB locking (HashiCorp docs). The azurerm backend locks with blob leases.

terraform {
  backend "s3" {
    bucket       = "acme-tf-state"
    key          = "prod/network/terraform.tfstate"
    region       = "ap-south-1"
    encrypt      = true
    use_lockfile = true
  }
}

14. Why save a plan to a file?

terraform plan -out=tfplan then terraform apply tfplan applies exactly what was reviewed. Without it, apply makes a fresh plan that might differ.

15. How do you force one resource to be recreated?

terraform apply -replace="aws_instance.web". The old terraform taint command is deprecated.

16. How do you bring an existing resource under Terraform?

Use an import block (Terraform 1.5+), then let Terraform draft the code:

import {
  to = aws_s3_bucket.logs
  id = "acme-logs-bucket"
}

Run terraform plan -generate-config-out=generated.tf, clean up the generated code and apply. The older terraform import CLI command still works but isn't reviewable in a plan.

17. How do you rename or move a resource without destroying it?

Add a moved block (Terraform 1.1+). It's reviewable in a plan, unlike terraform state mv.

moved {
  from = aws_instance.web
  to   = module.app.aws_instance.web
}

18. How do you stop managing a resource without deleting it?

A removed block (Terraform 1.7+) with destroy = false:

removed {
  from = aws_s3_bucket.old_logs
  lifecycle {
    destroy = false
  }
}

19. Which lifecycle settings do you use most?

create_before_destroy for zero-downtime swaps. prevent_destroy on databases and state buckets. ignore_changes for fields changed outside Terraform, like autoscaled counts. replace_triggered_by to recreate when something else changes.

20. When do you need depends_on?

Rarely. Terraform builds the dependency graph from references. Use depends_on only for hidden dependencies, like an IAM policy that must exist before an app starts.

21. Workspaces or separate folders per environment?

Workspaces give one configuration several state files. They suit identical copies. For dev, staging and prod with different settings and access, most teams use separate folders or separate backends.

22. How do you keep secrets out of state?

sensitive = true only hides values in output. They're still in state. Terraform 1.10 added ephemeral values and resources, and 1.11 added write-only arguments, which keep secrets out of plan and state files (HashiCorp docs). Also encrypt the backend and restrict who can read it.

23. What are dynamic blocks?

They generate repeated nested blocks, like security rules, from a list or map. Use them sparingly. Too many make code hard to read.

24. How do you test Terraform code?

terraform test (1.6+) runs .tftest.hcl files, and 1.7 added mocking. Add validation on variables, preconditions and postconditions, and check blocks (1.5+) for health assertions. Lint with tflint and scan with a tool like Checkov.

25. How do you use more than one region or account?

Provider aliases:

provider "aws" {
  alias  = "hyderabad"
  region = "ap-south-2"
}

resource "aws_s3_bucket" "dr" {
  provider = aws.hyderabad
  bucket   = "acme-dr-logs"
}

Senior and scenario questions

26. The plan wants to destroy and recreate the production database. What do you do?

Stop. Read why: a changed attribute that forces replacement, a renamed resource address, or a count index shift. Fix with a moved block, revert the attribute or switch to for_each. Add prevent_destroy so it can't happen silently again.

27. Someone changed a resource in the console. How do you find and handle drift?

Run terraform plan -refresh-only to see drift. Then either update the code to match, or apply to put things back. Schedule terraform plan -detailed-exitcode in CI: exit code 2 means changes are pending, so alert on it.

28. The state file is corrupted or deleted. How do you recover?

Restore the last good version from backend versioning (S3 versioning or blob versioning). If there's no backup, rebuild state with import blocks for each resource. Then add versioning, locking and tight access so it doesn't happen again.

29. How would you structure Terraform for 50 services and 6 teams?

Split state by layer and blast radius: network, shared data and per-service app stacks. Publish versioned modules in a private registry. Pass values between stacks with outputs and data sources. Each team owns its stacks; a platform team owns modules.

30. What does good Terraform CI/CD look like?

On every pull request: fmt, validate, tflint, a security scan and a plan posted as a comment. After approval, apply the saved plan. Use short-lived cloud credentials through OIDC instead of stored keys. Add policy as code (OPA or Sentinel) for rules like "no public buckets".

31. Plans take 15 minutes. How do you speed them up?

Split the state into smaller stacks. Reduce data sources that call slow APIs. Raise -parallelism if the cloud API's rate limits allow it. Use -target only for emergencies, not as a habit.

32. How do you upgrade a provider across many stacks safely?

Read the changelog for breaking changes. Bump the version constraint, run terraform init -upgrade and plan in dev first. Roll out stack by stack, and commit the updated lock file each time.

33. Terraform or OpenTofu?

HashiCorp moved Terraform to the Business Source License (BUSL-1.1), and OpenTofu was forked as an open-source alternative. Both use HCL and most providers. Pick based on licence needs, team skills and the features each has added since the split.

34. How do you handle a resource that Terraform keeps wanting to change?

Find which attribute differs in the plan. Often the cloud normalises a value (like JSON policy order), or another system edits it. Normalise it in code with functions like jsonencode, or use ignore_changes for that field only.

35. How do you design a reusable module?

Small and focused, with clear typed variables, validation, sensible defaults and only the outputs callers need. No provider blocks inside. Version it with semantic tags, write a README with examples and test it with terraform test.

A 2-week Terraform interview prep plan

DaysFocusDo this
1–2Workflow and HCLBuild a VNet or VPC with subnets; use variables, locals and outputs
3–4StateMove state to a remote backend with locking; read the state file
5–6ModulesTurn your network code into a module with for_each
7–8RefactoringPractise import, moved and removed blocks on a test resource
9–10Testing and CIAdd terraform test, tflint and a plan-on-PR pipeline
11–12Secrets and driftChange something in the console, then catch it with a refresh-only plan
13–14Mock roundsAnswer 26–35 out loud and whiteboard a multi-team layout

What Terraform skills pay

On 25 November 2026, the 46 DevOps listings on Weekday that showed pay had a median of ₹26 LPA, with half paying ₹20–38 LPA. Weekday's DevOps engineer salary guide estimates a 10–18% pay lift for the HashiCorp Terraform Associate certification, and puts 2–4 years of DevOps experience at ₹12–22 LPA. For broader prep, see our DevOps interview questions and Kubernetes interview questions.

Free tool: Paste a job description into Weekday's Interview Question Predictor to see which questions that role is likely to ask.

Find DevOps roles that ask for Terraform

Weekday lists thousands of open DevOps roles, updated daily, with quick-apply jobs shown first. Filter by city, work mode and experience.

Browse DevOps engineer jobs →

Frequently asked questions

What are the most common Terraform interview questions?

What state is and where it should live, remote backends and locking, count vs for_each, modules, import, moved blocks, lifecycle settings, drift, and what to do when a plan wants to destroy something important.

What is the latest Terraform version?

Terraform 1.17, released on 21 October 2026, with 1.17.2 out on 11 November 2026.

Is the Terraform Associate certification worth it?

It helps you get shortlisted and covers the basics well. Weekday's DevOps salary guide estimates a 10–18% pay lift, but interviewers will still ask what you built and how you handled state.

Do I need to know a cloud to clear a Terraform interview?

Yes. Terraform questions use real resources, so learn one cloud well. On Weekday, AWS appeared in 174 of the first 1,000 DevOps listings and Azure in 124.

Sources

  1. Weekday DevOps engineer jobs (25 Nov 2026; first 1,000 listings read for skill counts; median pay from 46 listings)
  2. Weekday analysis of 400 top Reddit posts from the last 30 days (Nov 2026): r/jobs 9-round thread, r/recruitinghell Q3 backlog thread
  3. endoflife.date: Terraform releases
  4. HashiCorp: S3 backend
  5. HashiCorp: manage sensitive data
  6. HashiCorp: Terraform 1.7 release blog
  7. Weekday: DevOps engineer salary in India 2026

Latest Articles

Browse Articles
Use AI to find jobs and apply

Stop manually filling job applications. Use AI to auto-apply to jobs

Browse jobs now