Infrastructure as code: Terraform vs Pulumi vs CloudFormation
Infrastructure as code (IaC) means defining servers, networks, databases and permissions in files that live in version control, instead of clicking through a console. It makes environments reproducible and reviewable.
Terraform (and its open-source fork OpenTofu)
- Declarative configuration language (HCL)
- Works across many clouds and services through providers
- Tracks real infrastructure in a state file, which needs careful storage and locking
- Very large community and module ecosystem
Pulumi
- Write infrastructure in general-purpose languages like TypeScript, Python, Go or C#
- Use loops, functions and testing tools you already know
- Multi-cloud like Terraform
- More flexibility, which can also mean more ways to write confusing code
CloudFormation (and the AWS CDK)
- Native to AWS, with no separate state file to manage
- The CDK lets you define CloudFormation stacks in general-purpose languages
- AWS-only
Good IaC practices
- Keep state secure and remote, with locking
- Review plans before applying changes
- Split infrastructure into small, logical modules
- Avoid manual changes that cause drift
- Store secrets in a secrets manager, not in code
Which IaC tool does your team use, and why? Has a state file mishap ever caused you a bad day?
Comments · 3
Terraform's ecosystem is the draw, since hiring is easier when people know it. That counts for a team more than elegance.
Using a real programming language is appealing for abstractions, but that also lets people make clever messes.
Which is best if you're all in on one cloud? Is CloudFormation simpler there?