Learn Terraform
Provision any cloud with declarative, version-controlled infrastructure as code.
Terraform, by HashiCorp, is an infrastructure-as-code tool that lets you define cloud and on-prem resources in a declarative configuration language (HCL) and provision them consistently across providers like AWS, Azure, and GCP. It tracks real-world resources in a state file, builds a dependency graph, and computes an execution plan showing exactly what will change before applying. Because configuration is version-controlled and reusable via modules, teams get repeatable, reviewable infrastructure.
Terraform roadmap
- 1
IaC concepts and HCL basics
Understand declarative vs. imperative provisioning and HashiCorp Configuration Language syntax.
- 2
Providers and resources
Configure a provider (e.g. AWS) and declare resources; run init, plan, and apply.
- 3
State management
How the state file maps config to real resources; use remote state with locking for teams.
- 4
Variables and outputs
Parameterize configs with input variables and expose values via outputs.
- 5
Modules
Package reusable groups of resources into modules for DRY, shareable infrastructure.
- 6
Dependencies and data sources
Implicit/explicit dependencies, the resource graph, and reading existing infra with data sources.
- 7
Workspaces and environments
Separate dev/stage/prod state, and structure repos for multiple environments.
- 8
Provisioning safely
Plan reviews, targeted applies, drift detection, and integrating Terraform into CI/CD.
Top Terraform interview questions
Real questions with concise, correct answers. Click to expand each.
What is the Terraform state file and why does it matter?+
State is a file (terraform.tfstate) that maps your configuration to the real resources Terraform manages, storing resource IDs and metadata. Terraform uses it to know what already exists so it can compute an accurate diff on the next plan. In teams you store it remotely (e.g. S3 with a lock) so it's shared and protected from concurrent, conflicting applies.
What is the difference between terraform plan and terraform apply?+
'terraform plan' is a dry run: it refreshes state, compares desired configuration to current reality, and prints the additions, changes, and destructions it would make — without touching anything. 'terraform apply' executes that plan and actually creates, updates, or deletes resources. Applying a saved plan file guarantees you get exactly what you reviewed.
What is a Terraform module?+
A module is a reusable, encapsulated group of Terraform resources with defined input variables and outputs. The root module is your main configuration; you call child modules (local or from a registry) to avoid duplication and standardize patterns like 'a VPC' or 'an ECS service' across environments and teams.
How does Terraform handle resource dependencies?+
Terraform builds a dependency graph. Most dependencies are implicit: when one resource references another's attribute, Terraform orders creation automatically. When there's no direct reference but ordering still matters, you use the depends_on argument to declare an explicit dependency. Destruction happens in reverse order.
What is the difference between count and for_each?+
Both create multiple instances of a resource. 'count' creates instances by numeric index (0,1,2), which is fine for identical copies but causes churn if the list order changes. 'for_each' iterates over a map or set of strings, keying instances by a stable identifier — so adding or removing one item doesn't disturb the others. Prefer for_each when items have meaningful identities.
How do you manage secrets in Terraform?+
Never hardcode secrets in .tf files, and remember that any value Terraform manages is written to state in plaintext — so protect state (encrypt it, restrict access, use remote backends). Pass sensitive values via environment variables or a secrets manager (e.g. Vault, AWS Secrets Manager), mark variables as sensitive to keep them out of logs, and keep secrets out of version control.
Terraform cheat sheet
terraform initInitialize the working dir, download providers and modules.
terraform planPreview the changes Terraform will make (dry run).
terraform applyCreate/update/destroy resources to match config.
terraform destroyTear down all resources managed by the configuration.
terraform fmtRewrite config files to canonical formatting.
terraform validateCheck config for syntactic and internal consistency errors.
terraform state listList resources tracked in the current state.
terraform importBring an existing real resource under Terraform management.
Terraform certifications
HashiCorp Certified: Terraform Associate (003)
The core associate cert covering IaC concepts, state, modules, and the Terraform workflow.
HashiCorp Certified: Terraform Authoring & Operations Professional
Hands-on professional cert for advanced authoring, modules, and operations at scale.
Ready to ace the interview?
This hub gets you started. Our Terraform interview kit goes deeper — hundreds of curated questions, model answers, and mock scenarios built to get you hired.