100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

What is Terraform?

Understand Terraform for DevOps interviews — declarative Infrastructure as Code, plan/apply workflow, and state, with examples and MCQs.

mediumQ13 of 224 in DevOps Est. time: 6 minsLast updated:
Open Code Lab

Expected Interview Answer

Terraform is an open-source Infrastructure as Code tool that lets you define cloud and on-premises resources in declarative configuration files, then plans and applies the changes needed to make real infrastructure match that configuration.

You write resources such as virtual machines, networks, or databases in HashiCorp Configuration Language, describing the desired end state rather than the steps to get there. Terraform builds a dependency graph from that configuration and, on running "terraform plan," shows exactly what will be created, changed, or destroyed before anything happens. Running "terraform apply" executes those changes through provider-specific APIs, and a state file tracks what Terraform currently manages so future runs know the difference between desired and actual state. Because it is provider-agnostic, the same workflow applies across AWS, Azure, GCP, and hundreds of other providers using a consistent syntax.

  • Infrastructure changes are version-controlled and reviewable like code
  • Plan step previews changes before anything is applied
  • Works consistently across many cloud providers
  • State tracking prevents configuration drift from going unnoticed

AI Mentor Explanation

Terraform is like a groundskeeper given a detailed pitch specification — exact grass length, soil moisture, and boundary markings — who first shows the head curator a preview of every change before touching the ground. Once approved, the groundskeeper executes exactly those changes, no more and no less, and keeps a written record of the pitch’s current state so next season’s adjustments only touch what actually needs changing. If someone else mows the outfield differently overnight, the next inspection catches that drift against the written record. This declarative, preview-then-apply approach is exactly how Terraform manages infrastructure.

Step-by-Step Explanation

  1. Step 1

    Write configuration

    Define resources such as VMs, networks, or databases declaratively in HCL files.

  2. Step 2

    Run terraform plan

    Terraform builds a dependency graph and shows exactly what will be created, changed, or destroyed.

  3. Step 3

    Review and approve

    An engineer reviews the plan output before any real infrastructure is touched.

  4. Step 4

    Run terraform apply

    Terraform calls provider APIs to make real infrastructure match the configuration, and updates its state file.

What Interviewer Expects

  • Understanding of declarative Infrastructure as Code versus imperative scripting
  • Awareness of the plan-then-apply workflow as a safety mechanism
  • Mention of the state file and its role in tracking managed resources
  • Knowledge that Terraform is provider-agnostic across multiple clouds

Common Mistakes

  • Confusing Terraform with a configuration-management tool like Ansible
  • Forgetting the importance of reviewing the plan output before applying
  • Not understanding what the state file is used for
  • Assuming Terraform only works with a single cloud provider

Best Answer (HR Friendly)

Terraform is a tool that lets you describe the infrastructure you want — servers, networks, databases — in a configuration file, and it figures out exactly what needs to be created or changed to make that a reality, showing you a preview before it touches anything.

Code Example

Basic Terraform resource and workflow
resource "aws_instance" "web" {
  ami           = "ami-0abcdef1234567890"
  instance_type = "t3.micro"
  tags = {
    Name = "web-server"
  }
}

# Workflow:
terraform init
terraform plan
terraform apply

Follow-up Questions

  • What is the Terraform state file used for?
  • How does terraform plan differ from terraform apply?
  • How would you manage Terraform state for a team, not just one engineer?
  • What happens if someone manually changes infrastructure outside Terraform?

MCQ Practice

1. What does the "terraform plan" command do?

terraform plan previews the exact changes needed to reach the desired state, before anything is applied.

2. What is the purpose of Terraform’s state file?

The state file records what Terraform manages so it can compute the difference between desired and actual infrastructure.

3. Is Terraform limited to a single cloud provider?

Terraform uses a plugin-based provider model that works across AWS, Azure, GCP, and many other platforms.

Flash Cards

What is Terraform?An open-source Infrastructure as Code tool for declaratively managing cloud resources.

What does terraform plan do?Previews exactly what will be created, changed, or destroyed before applying anything.

What is the Terraform state file?A record of the real-world resources Terraform currently manages, used to detect drift.

Is Terraform tied to one cloud provider?No, it is provider-agnostic and supports many clouds through plugins.

1 / 4

Continue Learning