AWS CloudFormation
AWS CloudFormation is the infrastructure as code (IaC) service of AWS. You describe the resources in a template (JSON or YAML) and CloudFormation creates, updates and deletes them in the right order as a single unit, a stack.
Key concepts #
- Template with parameters, resources, mappings, conditions and outputs, and built-in functions such as
!Refand!Sub. - Stack: the resources created from a template. Change sets preview the changes before applying them, and a failed update is rolled back automatically.
- StackSets deploy stacks to several accounts and Regions; nested stacks and modules reuse templates.
- Drift detection finds resources changed outside of CloudFormation.
- AWS CDK and the Serverless Application Model (SAM) generate CloudFormation templates from programming languages.
- No extra cost: you pay only for the resources that it creates (third-party resource handlers have a cost).
CloudFormation or Terraform / OpenTofu? #
| CloudFormation | Terraform / OpenTofu | |
|---|---|---|
| Clouds | AWS only | AWS, Azure, Google Cloud, Kubernetes, SaaS and more |
| Language | JSON / YAML (or CDK) | HCL |
| State | Managed by AWS | A state file (backend) that you manage |
| Support for new AWS features | Usually first | Soon after, through the provider |
Terraform can also manage CloudFormation stacks with the resource aws_cloudformation_stack.
See also: HCL, Terraform Built-in Functions.