CloudFormation and Terraform: Mapping Core Concepts
Leveraging transferable knowledge from CloudFormation to learn a second Infrastructure as Code tool, Terraform
Table of contents
Overview
This article documents the relatable concepts that I find relatable and transferrable based on my experience on CloudFormation to Terraform.
Parent-Child Stack v Modules
Both tools share a similar behavior like a function in a programming language, i.e. taking inputs/parameters to do something.
In CloudFormation, parent-child stack is used when calling multiple different templates. The child stack is also known as nested stack. The nested stack is referencing to a templateUrl
which will point to a CloudFormation template residing in a S3 bucket.
In Terraform, you can defined resources within the Terraform configuration files. One can also use modules which is akin to nested stack. The module can point to a local path or remote source, i.e. Terraform, S3 bucket or other version control system repository.
Parameters v Variables
In CloudFormation, you will define parameters which allows user to provide dynamic values when provisioning the resources.
Parameters defined in the parent CloudFormation stack can be passed into the nested stack
Observe that the parameters defined in the parent stack template, is also defined in the child stack template
In Terraform, input variables are defined to allow users to pass values as inputs.
Define the variables that will be used in the module
In the module, pass the values that will be used as input
In the Terraform configuration file(s) defined under the module, the values from the input variables will be used by the Terraform resources