Infrastructure as Code with Terraform
What IaC actually means
Infrastructure as Code means you describe the desired end state of your infrastructure in files, commit those files to version control, and let a tool reconcile reality with the description. Terraform is declarative and idempotent: you state what you want, not the sequence of API calls to get there. Running the same configuration twice yields the same result and creates no duplicates.
Concepts to know
- Declarative vs procedural - Terraform, CloudFormation and ARM templates are declarative; shell scripts and ad-hoc
ansible -mcommands are procedural. - Provider-based architecture - Terraform core is provider-agnostic; providers translate HCL into cloud API calls, which is why one tool spans many platforms.
- Immutable infrastructure - prefer replacing resources over mutating them in place (
create_before_destroy). - Benefits - repeatability, review via pull request, drift visibility, self-documenting environments, and identical patterns across clouds.
Traps that appear in questions
- Terraform is not a configuration-management tool: there is no agent and it does not manage software inside a running VM (that is Ansible/Chef/Puppet territory).
- Terraform can adopt resources it did not create, but only via
importorimportblocks - never by automatic discovery. - Declarative does not mean order-independent; Terraform derives ordering from the dependency graph built out of references.
planis a dry run, not a guarantee; API-side defaults or permissions can still fail at apply time.
Rule of thumb
If an answer choice says Terraform "runs commands in order" or "installs packages on servers," it is describing a procedural tool and is wrong.