Terraform Fundamentals
The Terraform workflow, HCL syntax, and the core building blocks.
Terraform provisions infrastructure declaratively across any cloud. You write HCL describing the desired state; Terraform figures out the changes to get there. The core workflow:
terraform init— download providers and set up the backendterraform plan— preview create/change/destroy actionsterraform apply— make it soterraform destroy— tear it all down
Building blocks: providers (cloud plugins), resources (things to create), variables (inputs), outputs (results), and data sources (read existing infrastructure). It’s declarative and idempotent — re-running converges to the desired state.
variable "region" { default = "eu-west-1" }
provider "aws" {
region = var.region
}
resource "aws_s3_bucket" "data" {
bucket = "my-app-data-12345"
tags = { env = "dev" }
}
output "bucket_name" {
value = aws_s3_bucket.data.bucket
}terraform init
terraform plan
terraform apply - List the four main Terraform CLI commands and what each does.
- Write a variable, use it in a provider, and add an output.
- Explain why Terraform is described as declarative and idempotent.
- Run a plan and identify a create vs a destroy action in the output.
Cheat Sheet▾
| Command / block | Purpose |
|---|---|
terraform init | Download providers, init backend |
terraform plan | Preview changes |
terraform apply | Apply changes |
terraform destroy | Remove everything |
provider | Cloud plugin |
resource | Thing to create |
variable / output | Inputs / results |
data | Read existing infra |
Common Interview Questions▾
What's the Terraform core workflow?
init (download providers/backend), plan (preview changes), apply (execute), and destroy (tear down). plan/apply is the everyday loop.
What does it mean that Terraform is declarative?
You describe the desired end state, not the steps. Terraform compares it to current state and computes the minimal changes — and re-running is idempotent.
What is a data source?
A read-only lookup of existing infrastructure (e.g. an existing VPC or AMI) that you reference in your configuration without managing it.