There are several tools for Infrastructure as Code. The most well-known are Terraform, CloudFormation, Pulumi, and CDK. In this subchapter, we compare them so you understand their differences and, above all, why this book chooses Terraform. It’s not about which one is “the best” in the abstract, but about which fits best for learning and for most cases.

The Four Tools

Terraform (by HashiCorp)

  • What it is: the most popular IaC tool and the main focus of this book.
  • Language: HCL (HashiCorp Configuration Language), a declarative language created specifically to describe infrastructure. It’s easy to read (we’ll see it in Chapter 10).
  • Multi-cloud: works with AWS, Azure, GCP, and hundreds of other providers, all with the same language. This is its big advantage.
  • Declarative: yes (as we saw in subchapter 9.2).

CloudFormation (by AWS)

  • What it is: the native AWS IaC tool.
  • Language: YAML or JSON files.
  • AWS only: exclusive to AWS. Not for Azure or GCP.
  • Advantage: fully integrated into AWS and supports new AWS services very quickly. You don’t need to install anything extra.
  • Drawback: files can become long and verbose, and it locks you into AWS (vendor lock-in, remember Chapter 2).

Pulumi

  • What it is: IaC using real programming languages (Python, TypeScript, Go, C#…).
  • Idea: instead of learning a specific language, you use the language you already know, with normal loops, conditions, and functions.
  • Multi-cloud: yes.
  • For whom: attractive for developers who prefer “normal” code. In exchange, it can be more complex and requires programming knowledge.

CDK (Cloud Development Kit, by AWS)

  • What it is: like Pulumi but from AWS: you define infrastructure with programming languages (TypeScript, Python, Java…) and, underneath, it generates CloudFormation.
  • AWS only (mainly).
  • For whom: developers in the AWS ecosystem who want to use code instead of YAML. There is also CDK for Terraform (CDKTF), which combines CDK with Terraform.

Comparison Table

Terraform CloudFormation Pulumi CDK
Creator HashiCorp AWS Pulumi AWS
Language HCL (proprietary, declarative) YAML/JSON Python, TS, Go… TS, Python, Java…
Multi-cloud Yes No (AWS only) Yes Mainly AWS
Learning curve Gentle Medium Medium-high (must know programming) Medium-high
Popularity / community The largest High (in AWS) Growing Growing
Locks you into AWS No Yes No Yes

Why This Book Chooses Terraform

We choose Terraform for very specific reasons, similar to why we chose AWS in Chapter 2:

  1. It’s the de facto market standard

Terraform is by far the most used and in-demand IaC tool in job offers. Learning it maximizes your professional opportunities.

  1. It’s multi-cloud (doesn’t lock you in)

With Terraform, what you learn works for AWS, Azure, GCP, and hundreds of other services, all with the same language. If you switch clouds tomorrow, you can reuse your knowledge. CloudFormation and CDK lock you into AWS.

  1. HCL is easy to read and learn

The HCL language was designed to be readable and clear, even for those who don’t program. It’s friendlier to start with than writing long YAML or using a full programming language.

  1. Huge community and ecosystem

There are thousands of examples, reusable modules (Chapter 18), and answers to any question. The Terraform community is gigantic.

  1. Fits perfectly with AWS

As we saw in Chapter 2, the AWS provider for Terraform is the most mature and complete. AWS + Terraform is one of the most in-demand combinations.

What About the Others? Don’t Rule Them Out

Choosing Terraform doesn’t mean the others are bad:

  • CloudFormation is excellent if you work only with AWS and want total native integration.
  • CDK / Pulumi are great for developers who prefer to use their favorite programming language.

The good thing is that, once you understand the concepts of IaC (declarative, state, idempotence…), switching from one tool to another is relatively easy. The concepts are universal, as we saw with clouds in Chapter 2.

A Note About Licenses (OpenTofu)

In 2023, HashiCorp changed Terraform’s license to a more restrictive one. In response, the community created OpenTofu, an open-source version compatible with Terraform (it’s a fork). For learning and for most uses, both are practically identical and what you learn here applies to both. It’s good to know that OpenTofu exists as a free alternative.

What You Should Remember

  • The four main IaC tools are Terraform, CloudFormation, Pulumi, and CDK.
  • CloudFormation and CDK are AWS-only; Terraform and Pulumi are multi-cloud.
  • Pulumi and CDK use programming languages; Terraform uses HCL (declarative and easy to read); CloudFormation uses YAML/JSON.
  • We choose Terraform because it’s the market standard, multi-cloud (doesn’t lock you in), with readable HCL, and a huge community.
  • OpenTofu is a free and compatible alternative to Terraform, created after the 2023 license change.

In the last subchapter of this chapter, we’ll see the fundamental Terraform workflow: the plan → apply → destroy cycle.

Cloud, AWS & Terraform — From Zero to Expert

Chapter 1 · What is cloud computing

Chapter 2 · The cloud market and major providers

Chapter 3 · Regions, availability zones and edge

Chapter 4 · Compute: EC2

Chapter 5 · Storage: S3

Chapter 6 · Networking: VPC

Chapter 7 · Identity and access: IAM

Chapter 8 · Managed databases

Chapter 9 · Why Infrastructure as Code

Chapter 10 · HCL: the Terraform language

Chapter 11 · Providers and state

Chapter 12 · Your first real infrastructure in Terraform

Chapter 13 · Load balancing and auto scaling

Chapter 14 · Serverless with Lambda

Chapter 15 · Messaging and events

Chapter 16 · Content delivery and DNS

Chapter 17 · Containers on AWS

Chapter 18 · Modules: reuse and composition

Chapter 19 · Workspaces and environment management

Chapter 20 · Remote backends and locking

Chapter 21 · Infrastructure testing

Chapter 22 · Terraform in CI/CD

Chapter 23 · Defense in depth

Chapter 24 · Observability: logs, metrics and traces

Chapter 25 · Cost optimization

Chapter 26 · High availability and disaster recovery

Chapter 27 · AWS Well-Architected Framework

Chapter 28 · Serverless architectures at scale

Chapter 29 · Data platforms on AWS

Chapter 30 · Multi-account and landing zones

Chapter 31 · Platform Engineering and Internal Developer Platform

Chapter 32 · Relevant AWS certifications

Chapter 33 · Projects to consolidate what you've learned

Chapter 34 · Resources and community

© Copyright 2024. All rights reserved