Certain resource combinations represent frequently defined stacks and are a good candidate for reuse. A three-tier web application and a static website hosted in S3 are some examples. Modules are one such feature in CloudFormation that allow the end user to publish reusable templates in a centralized registry. This avoids re-inventing the wheel every time a similar stack configuration needs to be provisioned.
Cloud platform teams can use this feature to make certain modules available in the member accounts across the organization. If you’ve worked with Terraform in the past, then you might have used modules there as well. Functionally, they both offer similar benefits around code reuse and modularity.
By now, I am sure you are convinced of CloudFormation’s capabilities around managing your AWS infrastructure resources at scale. While it’s the official IaC offering from the cloud provider, it’s not the only one you can work with. Terraform is another tool that is quite famous in the infrastructure space and offers similar capabilities across other cloud providers, such as Azure and GCP. When starting with AWS, organizations always get into a dilemma about which tool they should go ahead with. Let me make this easy for you.
Deciding between Terraform and CloudFormation
Terraform is an offering from Hashicorp and uses Hashicorp Configuration Language ( HCL) for resource definitions. It is commonly adopted by organizations working with multiple cloud providers as it offers a standard templating scheme. Functionally, it works just like CloudFormation – that is, it directly consumes underlying service APIs from the cloud provider. Other benefits such as code version control, change tracking, and automation are more or less similar to what we already covered in the context of CloudFormation.
Getting started with either of the two to manage sizeable workloads is easy. The difference comes to the surface when you’re dealing with a huge number of resources in a multi-account, multi-region organizational structure. Let’s discuss some areas where these tools are uniquely positioned.
Third-party provider ecosystem
Terraform lets you manage much more than just AWS resources. With support for over 1,000+ providers, you can additionally manage things such as Active Directory , Kubernetes Helm Charts, GitHub/ GitLab repositories, RedisCloud instances, and so on. This is a big benefit when you want to codify not just your cloud components but other infrastructure services as well. The standard configuration language improves the user experience as you can use the same configuration syntax to work with multiple providers. However, it is important to note that it’s not a write once, deploy anywhere tool. Your AWS resource configurations cannot be deployed as-is on Azure, for example.
CloudFormation does not offer much in this space. Of course, you could use custom resources to consume third-party APIs, but it has a learning curve and technical challenges. Terraform has an established ecosystem where many such providers have already made solutions available for adoption by the wider community.