Terraform interview question · Most asked
What is Terraform, and how does it work at a high level?
Summary
Terraform is an infrastructure-as-code tool: you declare resources in HCL configuration files, and Terraform builds a dependency graph, compares the configuration with the recorded state and the real infrastructure, produces a plan of creates, updates and deletes, and applies it through providers that call cloud and service APIs.
Longer Answer
Key pieces: providers (plugins for AWS, Azure, GCP, Kubernetes, GitHub, Datadog, and thousands more), resources (things Terraform manages), data sources (read-only lookups), variables, locals and outputs, modules (reusable groups of resources), and state (Terraform's record of what it manages and the real IDs).
Terraform is declarative: you describe the end state, not the steps. Because it calls APIs, the same workflow manages many platforms. Since HashiCorp moved Terraform to the Business Source License in 2023, the community fork OpenTofu (Linux Foundation, MPL licence) offers a compatible open-source alternative.
Key Points
- Declarative HCL configuration.
- Plan = diff of config, state and reality.
- Providers call APIs.
- OpenTofu is the open-source fork.
More most-asked Terraform questions
- How do you handle secrets in Terraform?
- A terraform plan wants to destroy and recreate a database. What do you do?
- What is Terraform state, why is it needed, and where should it be stored?
- Walk through terraform init, plan and apply. What does each do?
- What are Terraform modules, and how do you design good ones?
- How would you run Terraform in CI/CD?
- count or for_each: when do you use each?
- How do you bring existing infrastructure under Terraform management?