Most large companies need a way to automate their cloud deployments, so they turn to Terraform or CloudFormation. Both provision cloud resources, but Terraform is platform agnostic and CloudFormation is specifically for Amazon.

What Is CloudFormation?

If you’re only using Amazon Web Services (AWS), CloudFormation will allow you to provision databases, virtual machines, API gateways, network resources, and any other AWS resource. Administrators use templates to configure resources written in YAML. CloudFormation can be used to provision new infrastructure or remove existing resources.

What Is Terraform?

Terraform can be used to provision cloud resources in AWS and it can also be used in a multi-tenant environment to deploy resources to other cloud providers. It’s written in a proprietary language called HashiCorp Configuration Language (HCL). It’s also configurable using JSON and is a full automation platform for large enterprises.

How CloudFormation Is Similar to Terraform

Although both services are vastly different, they do have some similarities. They both automate infrastructure as code (IaS) using a declarative language. However, they use different languages. You can provision resources as easily using either, and they both can be integrated into your DevOps procedures.

CloudFormation works by launching resources in AWS. It’s not multi-cloud, but it’s often preferred if AWS is the only cloud provider that will be used. CloudFormation is closed source, so it’s proprietary and uses the standard YAML syntax.

It can also be used to provision cloud resources, but it can be used for AWS, Azure, Google Cloud, and any other provider with a provisioning API. It’s stateless, so you do not need to install an agent on the host resource to control provisioning.

How CloudFormation Is Different from Terraform

Both services have more differences than similarities, which is why most administrators have difficulties choosing between the two. Aside from the language differences, CloudFormation and Terraform have several differences that will determine which one is right for your environment.

Terraform is open source software, which makes it attractive for developers. CloudFormation is closed source and proprietary software specifically designed by Amazon. Because CloudFormation is AWS specific, it can only be used with AWS. Terraform, on the other hand, can be used for any platform. 

Another benefit of Terraform over CloudFormation is its on-premises options. Terraform can be used on premises and in the cloud, while CloudFormation can only be used on AWS cloud services.

When to Use CloudFormation

Because CloudFormation works well with AWS, you should use it when you know that you only need to support AWS resources and automation. Administrators can bundle resources to deploy “stacks” of cloud hardware so they can ensure that all resources are included in a rollout. Templates can be used to ensure that rollouts are repeatable for every AWS deployment.

Try FlashBlade

When to Use Terraform over CloudFormation

If you want to use multiple cloud providers or plan not to use AWS at all, then Terraform is your best (and only) choice between the two. Terraform is also open source, so the source code can be forked and customized to fit your own business needs. It also gives you the ability to make changes to the way the code functions overall.

Terraform vs. CloudFormation: FAQs

Can you migrate from CloudFormation to Terraform?

You can migrate from CloudFormation to Terraform, but you’ll need to refactor your code and rewrite it in the HCL syntax, test it, and then roll out your new solution.

Can CloudFormation replace Terraform?

You can refactor your code using CloudFormation YAML, but it only works with AWS deployments. If you use multi-tenant cloud hosting, you cannot replace Terraform with CloudFormation.

Should you learn CloudFormation or Terraform first?

If you want to work strictly with AWS, then CloudFormation is a good choice. Terraform, however, gives you the ability to deploy infrastructure to any platform, so it gives you more flexibility in your platform options.