Terraform vs CloudFormation vs Pulumi - Performance Comparison
Start learning this pattern below
Jump into concepts and practice - no test required
When using tools like Terraform, CloudFormation, or Pulumi, it's important to understand how the time to create or update infrastructure grows as you add more resources.
We want to know: How does the number of resources affect the time these tools take to apply changes?
Analyze the time complexity of provisioning multiple cloud resources using Terraform.
resource "aws_instance" "example" {
count = var.instance_count
ami = "ami-12345678"
instance_type = "t2.micro"
}
This code creates a number of virtual machines equal to instance_count.
Look at what happens repeatedly when this runs.
- Primary operation: API call to create each virtual machine.
- How many times: Once per instance, so equal to
var.instance_count.
As you increase the number of instances, the number of API calls grows the same way.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 10 API calls |
| 100 | 100 API calls |
| 1000 | 1000 API calls |
Pattern observation: The number of operations grows directly with the number of resources.
Time Complexity: O(n)
This means the time to apply changes grows in a straight line as you add more resources.
[X] Wrong: "Adding more resources won't affect apply time much because the tool handles everything at once."
[OK] Correct: Each resource usually requires its own API call, so more resources mean more calls and longer time.
Understanding how infrastructure tools scale with resource count helps you design efficient deployments and troubleshoot delays.
What if we used modules that create multiple resources internally? How would that affect the time complexity?
Practice
Solution
Step 1: Identify AWS-only tool
CloudFormation is the only tool among the options that works exclusively with AWS.Step 2: Check template language
CloudFormation uses JSON or YAML for its templates, unlike Terraform (HCL) or Pulumi (programming languages).Final Answer:
CloudFormation -> Option AQuick Check:
AWS-only + JSON/YAML = CloudFormation [OK]
- Confusing Terraform as AWS-only
- Thinking Pulumi uses JSON/YAML
- Selecting Ansible which is not IaC focused
Solution
Step 1: Identify Pulumi's language style
Pulumi uses real programming languages such as JavaScript, Python, Go, or C# for defining infrastructure.Step 2: Eliminate other options
HCL is Terraform's language, JSON/YAML with AWS is CloudFormation, and shell scripts are not Pulumi's approach.Final Answer:
Uses general-purpose programming languages like JavaScript or Python -> Option AQuick Check:
Pulumi = real programming languages [OK]
- Confusing Pulumi with Terraform's HCL
- Thinking Pulumi uses JSON/YAML
- Assuming Pulumi uses shell scripts
1. Supports AWS, Azure, GCP 2. Uses JSON or YAML 3. Uses HCL 4. Uses programming languages like TypeScript
Solution
Step 1: Match multi-cloud support
Terraform supports multiple clouds like AWS, Azure, and GCP.Step 2: Match language used
Terraform uses HCL, a simple declarative language. JSON/YAML is CloudFormation, programming languages like TypeScript is Pulumi.Final Answer:
Terraform -> Option DQuick Check:
Multi-cloud + HCL = Terraform [OK]
- Choosing Pulumi for HCL language
- Selecting CloudFormation for multi-cloud
- Confusing Chef with IaC tools
Solution
Step 1: Identify the cause of failure
The Pulumi program uses AWS resource names but tries to deploy on Azure, causing incompatibility.Step 2: Understand Pulumi's multi-cloud nature
Pulumi supports multiple clouds but resource names and APIs differ per cloud and must be adjusted accordingly.Final Answer:
Using AWS resource names in a multi-cloud Pulumi program without adjusting for Azure -> Option CQuick Check:
Cloud-specific resource names must match target cloud [OK]
- Thinking Pulumi can't use Python
- Believing Terraform is required for AWS
- Assuming CloudFormation works on Azure
Solution
Step 1: Identify multi-cloud support with TypeScript
Pulumi supports multiple clouds and allows writing infrastructure code in TypeScript, matching the requirement.Step 2: Compare other tools
Terraform supports multi-cloud but uses HCL, not TypeScript. CloudFormation is AWS-only. Ansible is for automation, not primarily IaC with TypeScript.Final Answer:
Pulumi, because it supports multiple clouds and uses real programming languages like TypeScript -> Option BQuick Check:
Multi-cloud + TypeScript = Pulumi [OK]
- Choosing Terraform for TypeScript support
- Selecting CloudFormation for multi-cloud
- Confusing Ansible with IaC tools
