AWS CloudFormation vs. Terraform

The term "infrastructure as code" (IaC) has been popular recently, and for good reason. IaC, or software-defined infrastructure, is an IT setup where developers or operations teams continuously manage and provision the technological stack for an application via software, rather than manually configuring separate hardware devices and operating systems. As an essential part of DevOps, it attempts to boost productivity, quality, and timeliness in organizations. AWS CloudFormation or the open-source Terraform tool is frequently the first two options that come to mind when looking for tools to implement infrastructure as code on AWS. In order to help you decide which is best for your situation, we'll go over the differences between them.

Cloud Formation


As a service provided by AWS, CloudFormation enables you to securely and consistently model and provision AWS and third-party application resources. With CloudFormation, AWS infrastructure modeling and development can be centralized, simplifying the management of dependencies among resources. This tool enables you to make changes in a defined and repeatable manner, facilitating the iterative refinement of your infrastructure. CloudFormation is dedicated to AWS, serving as a native tool designed to streamline infrastructure management.

AWS services may be deployed in a segregated fashion using CloudFormation, which simplifies the process of configuring these services and connecting them to one other. CloudWatch allows you to manage your AWS infrastructure in a controlled and predictable manner, allowing you to keep track of your infrastructure’s evolution. With this, testing may be iterated upon and a rollback is possible (when configured properly).



Terraform is a free and open-source software program designed to assist users in the establishment and deployment of data center infrastructure. Notably cloud-independent, Terraform encapsulates APIs into expressive system settings that can be shared, modified, reviewed, and versioned collaboratively amongst team members. Additionally, Terraform’s capabilities extend to managing existing and popular solutions, as well as on-premise applications, showcasing its versatility in handling diverse infrastructure environments.


As an essential part of DevOps, infrastructure as code (IaC) aims to enhance productivity, quality, and timeliness within organizations. Both CloudFormation and Terraform offer long-term advantages in this regard. CloudFormation, as highlighted in Your article, allows you to create custom resources using Lambda functions. When a custom resource is created or modified, the linked function is triggered, enabling flexibility in resource management. This integration between CloudFormation and Lambda provides a powerful capability for customizing your infrastructure.

However, it is crucial to consider the bigger picture when evaluating the long-term benefits of CloudFormation and Terraform. As mentioned in Their article, CloudFormation may be more convenient if you are already using AWS tools and have no external dependencies. On the other hand, Terraform offers additional flexibility as a cloud-agnostic platform, seamlessly integrating with AWS services and other popular providers. This adaptability allows organizations to future-proof their infrastructure and easily transition between different cloud environments if needed.

While both CloudFormation and Terraform offer long-term advantages, the decision between the two may ultimately depend on factors such as accessibility and developer comfort. It is crucial to select a tool that aligns with your organization’s objectives, preferences, and existing infrastructure. By leveraging either CloudFormation or Terraform, often referred to as the ‘swiss army knives’ of AWS infrastructure, you can enhance productivity, flexibility, and efficiency in managing your cloud resources.


State Management

Both Terraform and CloudFormation require that you keep a record of all resources that are being managed.

Drift detection may be performed on the full supplied infrastructure using CloudFormation, and comprehensive replies are returned when anything has changed. A parameter can be modified without deleting and rebuilding a CloudFormation stack resource for some resources, whereas others are deemed immutable and must be rebuilt. CloudFormation will also check for dependencies before deleting a resource, and it will abort the operation if any are found . A remote location, such as the provisioning computer, is where Terraform keeps track of infrastructure status (for team use). It’s a special JSON format that tells Terraform where to find the resources it’s responsible for managing and how to set up those resources.

A managed AWS service, CloudFormation takes care of all this for you. CloudFormation will constantly monitor the state and configuration of the infrastructure it has supplied in order to ensure that it is doing so. A remote state option is available for Terraform, which saves the state data on a remote data store and may be used by all members of a team if desired. Amazon S3 is supported by Remote State, but you must set it up yourself.



Flexibility is essential in the ever-changing world of infrastructure requirements. When it comes to meeting this demand, both CloudFormation and Terraform offer unique approaches.

Multiple resources can be contained in a single container in Terraform’s modules. Development teams benefit from the increased iteration speed that modules provide by abstracting their infrastructure into reusable and shareable software code. The “nested stacks” system is employed by CloudFormation. Using CloudFormation templates from within other CloudFormation templates. It is possible to further abstract these hierarchical stacks by creating StackSets. StackSets require special AWS CloudFormation permissions, which are not required for conventional CloudFormation.

CloudFormation, a popular infrastructure-as-code (IaC) tool provided by AWS, has its limitations when it comes to incorporating resources from non-AWS providers or specialized AWS services that are not built into CloudFormation. While it is possible to include third-party resources or integrate with a multi-cloud or hybrid environment, it often requires additional coding and design work. This can make it more challenging for customers to seamlessly provide or natively integrate such resources.

Terraform by comparison offers a more flexible and versatile solution for these scenarios. It allows customers to easily incorporate non-AWS resources or integrate with specialized AWS services, even in multi-cloud or hybrid environments. By utilizing Terraform, customers can streamline the process of deploying infrastructure, automating networking, services, and servers in AWS, and ensuring consistent application performance.


CloudFormation and Terraform use different approaches to handling parameters and settings. Terraform makes advantage of provider-specific data sources. Since it’s modular, it may be used in any Terraform configuration to fetch or compute data for use elsewhere. If you want to use an Elastic IP address to upgrade or provision infrastructure, you can do so with this feature. The maximum number of parameters in a CloudFormation template is 60. There must be a unique identifier for each argument in the template. CloudFormation parameters must be provided at stack runtime and must be of a supported type. The template itself must declare and refer to each parameter that is used. It is possible to use Dynamic References in CloudFormation to fetch parameters from the AWS Systems Manager parameter store if one is correctly configured.


Terraform employs the HashiCorp Configuration Language (HCL), a language developed by HashiCorp, to configure its infrastructure. It was designed to find a compromise between user and machine-friendly languages while still being understandable by humans and is fully compatible with JSON. JSON and YAML are both supported by AWS CloudFormation, with the YAML version being slightly more user-friendly (as well as more compact). The template body is similarly limited to 51,000 bytes in CloudFormation. AWS recommends that developers use stacked stacks if they need to create a larger template.



Both of these tools are completely free of charge. Both of these programmes have sizable user communities that provide a wealth of information, guidance, and inspiration. The act of cloud creation is free. CloudFormation users pay only for the AWS service that is provisioned by the service. Free and open-source, Terraform is a useful tool. Terraform, on the other hand, offers an enterprise-level edition for a fee that includes more tools for teamwork and management.

AWS CloudFormation is provided for free, with users only paying for the resources they provision. Terraform is also free to use; however, it offers various support options based on the size of the organization using it.

Integration of Multiple Cloud Environments


Terraform emerges as the optimal choice for provisioning services across various cloud platforms. Unlike CloudFormation, which is limited to AWS, Terraform offers compatibility with a wide range of cloud providers, including AWS, GCP, Azure, and others. In a multi-cloud setup, relying on CloudFormation may not be the most effective approach. Specifically, if you are utilizing AWS services such as EC2, S3, and similar resources, CloudFormation remains a suitable solution.

It’s worth noting that Terraform has recently addressed its interoperability with AWS in the latest software release. This update brings Terraform to a level where it stands shoulder-to-shoulder with CloudFormation in effectively managing AWS cloud resources. This enhancement ensures that Terraform users can confidently leverage its capabilities for seamless integration and management of multi-cloud environments.

Conclusion and Closing Thoughts

Both tools, CloudFormation and Terraform, are extremely effective at managing cloud infrastructure. If you are currently on AWS and utilizing all AWS capabilities, CloudFormation may be more efficient for you. Being a native AWS service, it is tightly integrated with other AWS services, making it more convenient for AWS users. Additionally, if you have no external tie-ins from third parties, CloudFormation can offer a seamless experience.

However, it is worth noting that Terraform offers a unique advantage in terms of flexibility, especially for users who require a cloud-independent platform. With Terraform, you have the ability to not only interface with AWS services but also tap into other prominent cloud providers, broadening your range of options. This cloud-agnostic framework allows for a more diverse set of solutions, ensuring that you can tailor your infrastructure management to suit your specific requirements.

The decision between CloudFormation and Terraform hinges on your individual needs and preferences. While CloudFormation excels in its tight integration with AWS services and seamless user experience for AWS-centric operations, Terraform stands out for its versatility and ability to cater to a wider array of cloud platforms. Both tools excel at managing cloud infrastructure effectively, offering distinct advantages depending on the context of your cloud environment.

  • State: 
  •  CloudFormation: the state is preserved into the CloudFormation stacks, visible in the console, ensuring a centralized view of the infrastructure configuration.
  • Terraform: When it comes to Terraform, the application states are saved locally or in a specified location, such as an S3 bucket, a local folder, or any other file storage service. This flexibility allows users to choose the most suitable method for their needs and preferences. Additionally, defining the backend for storing Terraform states is a best practice that enhances the ease and security of managing state, offering a robust solution for handling infrastructure changes effectively.
  • Language: 
    • CloudFormation allows users to utilize either JSON or Yaml, with Yaml being the preferred choice for many. Yaml in CloudFormation supports specific rules, such as string joining using the `!Join` function.  It is worth noting that CloudFormation has a limitation that restricts the size of templates to 51MB. If a template surpasses this limit, AWS developers must resort to creating nested stacks to manage the templates efficiently.
    • Terraform: employs Hashicorp’s unique language, HCL (Hashicorp Configuration Language), which is designed to be compatible with JSON. This distinctive feature of Terraform’s language sets it apart from CloudFormation’s language offerings, providing users with a different approach to infrastructure management.

Dolan Cleary

Dolan Cleary

I am a recent graduate from the University of Wisconsin - Stout and am now working with AllCode as a web technician. Currently working within the marketing department.

Related Articles

AWS Graviton and Arm-architecture Processors

AWS Graviton and Arm-architecture Processors

AWS launched its new batch of Arm-based processors in 2018 with AWS Graviton. It is a series of server processors designed for Amazon EC2 virtual machines. The EC2 AI instances support web servers, caching fleets, distributed data centers, and containerized microservices. Arm architecture is gradually being rolled out to handle enterprise-grade utilities at scale. Graviton instances are popular for handling intense workloads in the cloud.

What is Tiered Pricing for Software as a Service?

What is Tiered Pricing for Software as a Service?

Tiered Pricing is a method used by many companies with subscription models. SaaS companies typically offer tiered pricing plans with different services and benefits at each price point with typically increasing benefits the more a customer pays. Striking a balance between what good rates are and the price can be difficult at times.

The Most Popular Cloud Cost Optimization Tools

The Most Popular Cloud Cost Optimization Tools

Cloud environments and their pricing models can be difficult to control. Cloud computing does not offer the best visibility and it is easy to lose track of which price control factors are having an impact on your budget. Having the right tools can help put value to parts of an environment and provide guides on how to better bring budgetary issues back under control.