Why Not Just Use CloudFormation?

This lesson will compare Terraform and CloudFormation to learn which one is better.

Terraform vs. CloudFormation#

As this course is going to use AWS for its examples, it seems prudent to address the question: Why use Terraform over CloudFormation? Since CloudFormation is an infrastructure-as-code tool that is doing the same job as Terraform and was written by Amazon themselves, isn’t it better? Well, not exactly. There are several reasons why Terraform is a better choice than CloudFormation for your project.

Terraform vs. CloudFormation

Faster Terraform#

Terraform is open source and generally moves faster than CloudFormation. Even though Amazon produces CloudFormation, it can still take a while for a new AWS feature to appear, whereas the Terraform community is amazing at keeping the program up to date. This is aided by the fact that each Terraform provider (think of that as a plugin to manage a certain vendor or component) is a separate binary that gets deployed at its own speed (we will cover providers in detail later in the course).

Terraform moves faster than CloudFormation

CloudFormation readability#

CloudFormation uses JSON or YAML for configuration. Both of these formats are flawed, in my view, for different reasons. JSON can be quite tricky to read when you have a big object and fiddly to get right due to all of the curly braces. JSON does not allow comments either, which means that you cannot note something to explain it.

CloudFormation uses JSON or YAML, making it a bit difficult to work with it

YAML does allow comments and is a bit less verbose than JSON. The big downside of YAML is that YAML is very, very fussy about correct indentation. It can have you pulling your hair out trying to get it right. If you want to remove a block in the middle of your YAML file, it is a nightmare trying to get the indentation correct again. YAML is also hard to follow when you have a large file, and it is hard to read it quickly and work out what is going on.

Terraform readability#

Terraform uses HCL, which has a clean, concise syntax. It is very easy to read, allows comments (both inline and block), and is not fussy about spacing, newlines, or indentation. That is not to say you cannot use a formatter or an IDE to get it looking neat. It is just that there will not be a syntax error if you add an extra space, as it can be with YAML. Using HCL, you can easily split your project up into multiple files as you see fit to make the code easier to read and understand when coming to the project.

Using HCL in Terraform makes it easy to work with multiple files

Terraform’s pinnacle killer feature#

The final feature that makes Terraform the obvious choice over CloudFormation is that you can use Terraform to configure all of your infrastructures, whereas CloudFormation only works for AWS. This allows you to have one tool and project to manage all of your infrastructures, even if your infrastructure is made up of several components and split across multiple clouds. You can even write your own Terraform provider if you want to configure something that Terraform does not currently support. If you are using CloudFormation and want to configure anything other than AWS, you will have to use a different tool.

Terraform can be used to easily manage all of the infrastructure
Terraform to the Rescue
What About Chef And Puppet, Don’t They Solve This Problem?
Mark as Completed
Report an Issue