What is Terraform and what problem does infrastructure as code solve?
Learn what Terraform is, how infrastructure as code works, the plan and apply workflow, and the manual-provisioning problems IaC solves, with examples.
Expected Interview Answer
Terraform is an open-source infrastructure as code (IaC) tool from HashiCorp that lets you define cloud and on-prem resources in human-readable configuration files, then create, change, and version that infrastructure safely and repeatably.
Infrastructure as code solves the problem of manual, click-driven provisioning that is slow, error-prone, and impossible to reproduce reliably. Instead of clicking through a console, you describe the desired end state in HCL, and Terraform builds an execution plan and applies it through provider APIs. Because the configuration is just text, it can be reviewed, versioned in Git, tested, and reused, which eliminates configuration drift and undocumented 'snowflake' servers.
- Reproducible, versioned infrastructure
- Reduces manual errors and configuration drift
- Works across many cloud and SaaS providers
- Enables code review and collaboration on infra changes
- Plan step previews changes before they are applied
AI Mentor Explanation
Infrastructure as code is like a captain's written field-placement chart instead of shouting ad-hoc instructions each over. Anyone can read the chart, reproduce the exact fielding setup for the next match, and review changes before play. Terraform is that chart engine: you write down where every fielder stands, and it positions them identically every single time without relying on memory.
Step-by-Step Explanation
Step 1
Write configuration
Describe desired resources in HCL files, declaring the end state rather than the steps to reach it.
Step 2
Initialize
Run terraform init to download the required provider plugins and set up the backend.
Step 3
Plan
Run terraform plan so Terraform compares desired state to current state and shows what it will add, change, or destroy.
Step 4
Apply
Run terraform apply to call provider APIs and create or update the real infrastructure to match the config.
Step 5
Track state
Terraform records the results in a state file so future runs know what already exists and only make necessary changes.
What Interviewer Expects
- A clear definition of Terraform as a declarative IaC tool
- Understanding of the manual-provisioning problems IaC solves
- Awareness of the plan and apply workflow
- Mention of providers and multi-cloud support
- Recognition that config is versioned like source code
Common Mistakes
- Calling Terraform a configuration-management tool like Ansible
- Forgetting to mention the plan step before apply
- Ignoring state as central to how Terraform tracks resources
- Claiming Terraform only works with AWS
Best Answer (HR Friendly)
“Terraform lets teams describe their servers and cloud setup in text files instead of clicking around a console. Because it is just code, you can review it, store it in Git, and rebuild the exact same environment reliably, which removes manual mistakes.”
Code Example
terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.0"
}
}
}
provider "aws" {
region = "us-east-1"
}
resource "aws_instance" "web" {
ami = "ami-0abcdef1234567890"
instance_type = "t3.micro"
tags = {
Name = "web-server"
}
}Follow-up Questions
- What is the Terraform state file and why does it matter?
- How does terraform plan differ from terraform apply?
- What is a Terraform provider?
- How would you manage Terraform across multiple environments?
- What happens if someone changes infrastructure manually outside Terraform?
MCQ Practice
1. Which best describes Terraform?
Terraform is a declarative IaC tool that provisions infrastructure from configuration files.
2. What primary problem does infrastructure as code solve?
IaC replaces error-prone manual setup with versioned, repeatable configuration, eliminating drift.
3. Which command previews changes before they are applied?
terraform plan compares desired and current state and shows the intended changes before apply.
Flash Cards
What is Terraform? — An open-source declarative IaC tool by HashiCorp for provisioning infrastructure from configuration files.
What problem does IaC solve? — It replaces manual, non-reproducible provisioning, eliminating drift and enabling versioned, reviewable infrastructure.
What language does Terraform use? — HashiCorp Configuration Language (HCL), a declarative, human-readable configuration syntax.
What does terraform plan do? — It previews the additions, changes, and deletions Terraform will make before you apply them.