Infrastructure as code and how Terraform works
Terraform is the most requested infrastructure-as-code tool in Bangalore DevOps job descriptions. If you already know CloudFormation, EKS or GitOps, the concepts will feel familiar; what interviews test is fluency in HCL, a real understanding of state, the module and environment patterns teams use, and the team workflow around plans and applies. This topic is written to take you from zero to interview-ready, ending with a worked EKS platform example you can build as a portfolio project.
What Terraform is
Terraform (by HashiCorp) is a declarative IaC tool: you describe the infrastructure you want in HCL (HashiCorp Configuration Language) files, and Terraform works out the API calls to create, change or delete real resources to match.
- Providers are plugins that talk to APIs —
aws,kubernetes,helm,github,datadog,cloudflare— over 4,000 in the public registry. That's the multi-cloud/multi-service strength. - Resources are things Terraform manages (
aws_vpc,aws_eks_cluster). - Data sources read things it doesn't manage (an existing VPC, the latest AMI).
- State records the mapping between your configuration and real-world resource IDs.
The core workflow
terraform init # download providers & modules, configure the backend
terraform fmt # format code to the canonical style
terraform validate # syntax and internal consistency (no API calls)
terraform plan # compare config ↔ state ↔ reality; show the changes
terraform apply # execute the plan (asks for confirmation)
terraform destroy # delete everything this configuration manages
Plan output symbols: + create, - destroy, ~ update in place, -/+ destroy and recreate (replacement), <= read (data source). Always read the summary line: Plan: 3 to add, 1 to change, 0 to destroy.
Save a plan and apply exactly that plan (standard in CI):
terraform plan -out=tfplan
terraform show tfplan # human-readable
terraform show -json tfplan # machine-readable (policy checks)
terraform apply tfplan # no surprises: applies only what was reviewed
How plan works internally
- Refresh: read the current state of each managed resource from the provider APIs (detecting drift).
- Diff: compare desired configuration with the refreshed state.
- Graph: build a dependency graph from references between resources (
aws_subnet.a.vpc_id = aws_vpc.main.idmeans the subnet depends on the VPC). - Order: create/update in dependency order, destroy in reverse order, and run independent operations in parallel (default parallelism 10,
-parallelism=n).
Dependencies are usually implicit through references. depends_on adds explicit ones for hidden dependencies (e.g. an IAM policy attachment that must exist before a Lambda runs).
Terraform vs alternatives
| Terraform | CloudFormation | AWS CDK | Pulumi | |
|---|---|---|---|---|
| Language | HCL | YAML/JSON | TypeScript/Python/Java... → CloudFormation | General-purpose languages |
| Clouds/services | Multi-cloud + SaaS | AWS only | AWS (CDK for Terraform exists) | Multi-cloud |
| State | You manage it (S3 backend etc.) | AWS manages it (stacks) | AWS-managed (via CFN) | Managed service or self-managed |
| Preview | plan |
Change sets | cdk diff |
pulumi preview |
| Drift detection | plan / refresh-only |
Drift detection feature | Via CFN | refresh |
| Rollback on failure | No automatic rollback (partial apply stays) | Automatic stack rollback | Via CFN | No |
| New AWS features | Usually fast (provider updates) | Sometimes delayed coverage | Via CFN | Fast |
How to talk about it if your background is CloudFormation: "I've built and run CloudFormation stacks; the declarative model, dependency ordering and change preview are the same ideas. Terraform's differences are explicit state I have to manage and protect, a much larger provider ecosystem, modules from the registry, and no automatic rollback — so plan review and small blast radius matter more."
Licence and OpenTofu
In 2023 HashiCorp moved Terraform from the open-source MPL licence to the Business Source License (BSL). The community forked the last open version as OpenTofu (Linux Foundation), which is largely drop-in compatible (tofu init/plan/apply) and has added features of its own (e.g. state encryption). IBM acquired HashiCorp in 2025. Interviewers may ask; the practical answer is that both work and many teams still use Terraform, with some regulated orgs preferring OpenTofu.