HomeInterview Questions50+ Terraform Interview Questions Every DevOps Engineer Must Know
Top 100+ Terraform Interview Questions and Answers (2025)

50+ Terraform Interview Questions Every DevOps Engineer Must Know

Comprehensive guide for Cloud / DevOps interviews (3–10 years). Kept original numbering and organized into Beginner → Intermediate → Advanced → Scenario → Modules → Troubleshooting → Terragrunt sections — blog-ready and SEO-friendly.


Table of Contents

  1. Basic Terraform Interview Questions (Q1–Q5)
  2. Intermediate Terraform Questions (Q6–Q14)
  3. Advanced Terraform Questions (Q15–Q25)
  4. Curated 25 Questions (4-year experience flavor)
  5. Advanced / Experienced Interview Questions (1–30)
  6. Scenario-Based Interview Questions & Answers
  7. Real-Time Scenarios & Hands-On Examples
  8. Terraform Enterprise Features & Use Cases
  9. Terraform Modules Interview Questions & Answers
  10. Troubleshooting & Best Practices (AWS + Azure)
  11. Terragrunt: Use Cases, Scenarios, and Interview Questions

🟢 Basic Terraform Interview Questions

  1. What is Terraform?

Answer:
Terraform is an open-source Infrastructure-as-Code (IaC) tool by HashiCorp used to provision, manage, and version cloud infrastructure using declarative configuration files. It supports multiple providers like AWS, Azure, GCP, VMware, and more.


  1. What are the key components of Terraform?

Answer:

  • Providers – Define which cloud/service APIs to interact with (e.g., AWS, Azure).
  • Resources – The actual infrastructure components (e.g., EC2 instance, VNet).
  • Modules – Reusable collections of Terraform configurations.
  • State File – Tracks the current infrastructure status (terraform.tfstate).
  • Variables & Outputs – Parameterize configurations and share results.
  • Backend – Defines where the Terraform state file is stored (local, S3, etc.).

  1. What language is Terraform written in and what is HCL?

Answer:
Terraform is written in Go. It uses HCL (HashiCorp Configuration Language) — a human-readable declarative language designed for infrastructure automation.


  1. What is the difference between terraform plan and terraform apply?

Answer:

  • terraform plan: Shows the changes Terraform will make without applying them.
  • terraform apply: Executes those changes and provisions/updates resources.

  1. What is a Terraform provider?

Answer:
A provider is a plugin that enables Terraform to interact with APIs of cloud providers or services (e.g., aws, azurerm, google, kubernetes, etc.).


🟡 Intermediate Terraform Questions

  1. What is the Terraform state file? Why is it important?

Answer:
The state file (terraform.tfstate) keeps track of the current infrastructure deployed by Terraform. It maps your configuration to real-world resources, allowing Terraform to:

  • Detect drift (changes outside Terraform).
  • Plan accurate updates.
  • Enable collaboration when stored remotely.

  1. What are remote backends in Terraform?

Answer:
Remote backends store the Terraform state file in a centralized, shared location (e.g., AWS S3, Azure Blob, Terraform Cloud). They improve collaboration, enable state locking, and prevent data loss.


  1. How do you handle secrets in Terraform?

Answer:

  • Use environment variables instead of hardcoding secrets.
  • Use Terraform Cloud or Vault for secret management.
  • Integrate with AWS Secrets Manager or Azure Key Vault.
  • Avoid committing .tfstate files with sensitive data to Git.

  1. What are Terraform modules?

Answer:
Modules are reusable Terraform configurations — they help reduce code duplication and standardize infrastructure setup.

Example:

module "vpc" {
  source = "terraform-aws-modules/vpc/aws"
  cidr_block = "10.0.0.0/16"
}

  1. What is the difference between terraform import and terraform state commands?

Answer:

  • terraform import: Brings existing resources under Terraform management.
  • terraform state: Manages or inspects state files (e.g., remove, list, show resources).

  1. What is the purpose of the .terraform.lock.hcl file?

Answer:
It locks provider versions used in the configuration to ensure consistent builds across environments.


  1. Explain Terraform lifecycle meta-arguments.

Answer:
Used to control resource creation, updates, and destruction:

lifecycle {
  create_before_destroy = true
  prevent_destroy       = true
  ignore_changes        = [tags]
}

  1. What is the difference between count and for_each in Terraform?

Answer:

  • count: Creates multiple resources based on index (integer-based).
  • for_each: Creates multiple resources based on keys (map/set-based).

Example:

resource "aws_instance" "web" {
  for_each = toset(["dev", "test", "prod"])
  tags = { Name = each.key }
}

  1. What is Terraform Drift?

Answer:
Drift occurs when infrastructure is changed outside Terraform (e.g., manual console updates), making the actual state different from the .tfstate.


🔵 Advanced Terraform Questions

  1. How do you manage multiple environments (dev/stage/prod)?

Answer:

  • Use workspaces: terraform workspace new dev
  • Use separate directories or state files.
  • Use variable files (dev.tfvars, prod.tfvars).

  1. How can you integrate Terraform with CI/CD pipelines?

Answer:
Use tools like Jenkins, GitHub Actions, or Azure DevOps to run terraform fmt, terraform validate, terraform plan, and terraform apply. Use remote backends and service principals for authentication.


  1. What are Terraform provisioners and when should they be used?

Answer:
Provisioners (e.g., remote-exec, local-exec) run scripts or commands on resources after creation. They should be used sparingly, as they break declarative design principles.


  1. How do you perform a Terraform destroy for only one resource?

Answer:

terraform destroy -target=aws_instance.web

  1. How does depends_on work in Terraform?

Answer:
It defines an explicit dependency between resources to ensure correct creation order.

Example:

resource "aws_instance" "app" {
  depends_on = [aws_security_group.app_sg]
}

  1. Explain Terraform Cloud and Terraform Enterprise.

Answer:

  • Terraform Cloud: Managed SaaS by HashiCorp for remote runs, version control, and team collaboration.
  • Terraform Enterprise: Self-hosted version for organizations needing governance, policy checks, and private modules.

  1. What is a Terraform workspace?

Answer:
Workspaces allow multiple state files within the same configuration — useful for managing multiple environments (e.g., default, dev, prod).


  1. How do you upgrade provider versions in Terraform?

Answer:
Update the required_providers block and run:

terraform init -upgrade

Example:

terraform {
  required_providers {
    aws = { version = "~> 5.0" }
  }
}

  1. How do you debug Terraform issues?

Answer:

  • Run with debug flag: TF_LOG=DEBUG terraform apply
  • Check plan and state for mismatches.
  • Use terraform refresh or terraform state list.

  1. What are some common Terraform best practices?

Answer:

  • Use version control (Git).
  • Store state remotely and enable locking.
  • Use modules and variables.
  • Run terraform fmt and terraform validate.
  • Implement CI/CD validation stages.

  1. What is the difference between local-exec and remote-exec provisioners?

Answer:

  • local-exec: Executes a command on the machine running Terraform.
  • remote-exec: Executes a command inside the target resource (e.g., EC2 instance via SSH).

Curated — 25 Terraform interview questions (4-year DevOps experience flavor)

Concise, experience-focused answers grouped by difficulty to help mid-level candidates prepare for real-world interview scenarios.

Beginner / Fundamentals (Q1–Q6)

  1. What is Terraform and how does it differ from other IaC tools?

Answer: Terraform is an immutable, declarative IaC tool that uses HCL to define infrastructure in code. Unlike Ansible/Chef (configuration management), it creates/destroys resources via providers. Key differences: state management, plan/apply workflow, multi-cloud support.

  1. Explain the Terraform workflow.

Answer: terraform initterraform planterraform applyterraform destroy.

  1. What is Terraform state? Why is it important?

Answer: JSON file (terraform.tfstate) mapping resources to real IDs. Enables incremental changes, collaboration, and drift detection. Never commit to VCS without remote backend + locking.

  1. What are remote backends? Name a few.

Answer: Store state in shared, lockable storage: S3 + DynamoDB, Terraform Cloud, Azure RM, GCS, Consul.

  1. What is a provider? Give examples.

Answer: Plugin that interacts with APIs. Examples: aws, azurerm, google, kubernetes, vault.

  1. Explain terraform fmt, validate, taint, import.

Answer:

  • fmt → canonical HCL style
  • validate → syntax + schema check
  • taint → mark resource for recreation (deprecated; use -replace in v1+)
  • import → bring existing infra under TF management

Intermediate (Q7–Q15)

  1. How do you manage secrets in Terraform?

Answer: Use sensitive = true, Vault, Secrets Manager, env variables (TF_VAR_), Terraform Cloud encrypted variables.

  1. What are modules? When would you create one?

Answer: Reusable, versioned directories with inputs/outputs — create for VPC, ECS, RDS, etc.

  1. Explain count, for_each, and depends_on.

Answer:

  • count → N identical resources
  • for_each → iterate over maps/sets
  • depends_on → explicit dependency
  1. What is a data source? Give an example.

Answer: Reads existing resources without managing them (e.g., data "aws_ami" "latest" { ... }).

  1. How do you handle drift detection?

Answer: Run terraform plan in CI; terraform refresh to update state; use Terraform Cloud/Atlantis for drift checks.

  1. What is terraform workspace? When to use vs. directories?

Answer: Isolated state per workspace — good for simple envs; prefer directory-per-env for complex configs.

  1. Explain null_resource and a use-case.

Answer: Executes scripts when no native resource exists; use for DB seeding or orchestration with triggers.

  1. What are provisioners? When should you avoid them?

Answer: local-exec/remote-exec—use sparingly; prefer cloud-init or native resource support.

  1. How do you version Terraform configurations?

Answer: Use Git tags and semantic versioning in module source references.


Advanced / Scenario-Based (Q16–Q25)

  1. Design a multi-account AWS landing zone with Terraform.

Answer (high level): Root module for Organizations, per-account modules via for_each, remote state per account, assume-role provider aliases.

  1. How to implement blue/green zero-downtime?

Answer: Use AWS CodeDeploy or ECS, manage two target groups, create_before_destroy, Route53 weighted DNS or ALB target switching.

  1. Explain Terraform state locking and DynamoDB.

Answer: Prevent concurrent apply. DynamoDB table stores a lock item; used with S3 backend.

  1. What is terraform graph?

Answer: Outputs DOT dependency graph for visualization and circular dependency detection.

  1. Handling partial state with state mv / rm.

Answer: mv to rename addresses after refactor; rm to remove from state (dangerous)—always backup.

  1. Module supporting AWS and Azure with same interface?

Answer: Use provider aliases and conditional count to enable the desired provider.

  1. Integrate Terraform with GitHub Actions (example).

Answer: Setup job to run init, plan -out, store plan, manual approval stage, apply plan. Add tfsec/infracost for checks.

  1. terraform refresh vs apply -refresh-only.

Answer: refresh updates state only. apply -refresh-only creates a plan to sync state and requires apply to change infra.

  1. Terraform Cloud/Enterprise features used in production.

Answer: Remote execution, VCS workflows, Sentinel, private registry, cost estimation, SSO.

  1. How to perform canary deployments with Terraform?

Answer: Two ASGs or ECS services, weighted routing, create_before_destroy, and CI-driven traffic shift.


Quick Revision Cheat-Sheet (4-yr DevOps)

# versions.tf
terraform {
  required_version = ">= 1.6.0"
  required_providers { aws = { source = "hashicorp/aws", version = "~> 5.0" } }
  backend "s3" { bucket = "my-tf-state", key = "prod.tfstate", dynamodb_table = "lock" }
}

# variables.tf (sensitive)
variable "db_password" { type = string, sensitive = true }

# main.tf
provider "aws" { reg

Share:

Leave A Reply

Your email address will not be published. Required fields are marked *

You May Also Like

Digital Marketing Interview Questions and Answers 2025 Preparing for a digital marketing interview? Whether you’re a fresher or an experienced...
Capgemini AWS Interview Questions and Answers Here are some commonly asked AWS interview questions in Capgemini interviews, based on recent...
Top 25 FSLogix Interview Questions for Citrix Virtual Apps & Desktops and Azure Virtual Desktop (AVD) in 2025 As virtual...