Bird
Raised Fist0
Terraformcloud~5 mins

Terraform vs CloudFormation vs Pulumi - CLI Comparison

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Introduction
Managing cloud resources can be complex. Terraform, CloudFormation, and Pulumi help by letting you write code to create and update these resources automatically. They solve the problem of manual setup and keep your cloud organized and repeatable.
When you want to create and manage cloud resources like servers, databases, and networks using code.
When you need to keep your cloud setup consistent across different environments like testing and production.
When you want to track changes to your cloud setup safely and roll back if needed.
When you prefer using a specific language or tool that fits your team's skills and cloud provider.
When you want to automate cloud resource management to save time and reduce errors.
Commands
This command sets up Terraform in your project folder by downloading necessary plugins and preparing the environment.
Terminal
terraform init
Expected OutputExpected
Initializing the backend... Initializing provider plugins... - Finding latest version of hashicorp/aws... - Installing hashicorp/aws v4.0.0... - Installed hashicorp/aws v4.0.0 (signed by HashiCorp) Terraform has been successfully initialized!
This command shows what changes Terraform will make to your cloud resources without applying them yet. It helps you review before making changes.
Terminal
terraform plan
Expected OutputExpected
An execution plan has been generated and is shown below. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: + aws_instance.example id: <computed> Plan: 1 to add, 0 to change, 0 to destroy.
This command applies the planned changes to your cloud resources automatically without asking for confirmation.
Terminal
terraform apply -auto-approve
Expected OutputExpected
aws_instance.example: Creating... aws_instance.example: Creation complete after 10s [id=i-1234567890abcdef0] Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
→
-auto-approve - Skip manual approval to apply changes immediately
This command deletes all the resources Terraform created, cleaning up your cloud environment.
Terminal
terraform destroy -auto-approve
Expected OutputExpected
aws_instance.example: Destroying... aws_instance.example: Destruction complete after 5s Destroy complete! Resources: 1 destroyed.
→
-auto-approve - Skip manual approval to destroy resources immediately
Key Concept

If you remember nothing else, remember: Terraform, CloudFormation, and Pulumi let you manage cloud resources with code to automate and control your cloud setup safely.

Common Mistakes
Running terraform apply without running terraform plan first
You might apply unexpected changes without reviewing them, causing errors or downtime.
Always run terraform plan to see what will change before applying.
Not initializing Terraform with terraform init before other commands
Terraform won't have the necessary plugins and setup, causing errors.
Run terraform init once when starting a new project or after changing providers.
Forgetting to destroy resources after testing
Unused cloud resources can cost money and clutter your environment.
Use terraform destroy to clean up resources when no longer needed.
Summary
terraform init prepares your project by downloading needed plugins.
terraform plan shows what changes will happen without applying them.
terraform apply makes the planned changes to your cloud resources.
terraform destroy removes all created resources to clean up.

Practice

(1/5)
1. Which infrastructure as code tool is designed to work only with AWS and uses JSON or YAML for its templates?
easy
A. CloudFormation
B. Terraform
C. Pulumi
D. Ansible

Solution

  1. Step 1: Identify AWS-only tool

    CloudFormation is the only tool among the options that works exclusively with AWS.
  2. Step 2: Check template language

    CloudFormation uses JSON or YAML for its templates, unlike Terraform (HCL) or Pulumi (programming languages).
  3. Final Answer:

    CloudFormation -> Option A
  4. Quick Check:

    AWS-only + JSON/YAML = CloudFormation [OK]
Hint: AWS-only and JSON/YAML means CloudFormation [OK]
Common Mistakes:
  • Confusing Terraform as AWS-only
  • Thinking Pulumi uses JSON/YAML
  • Selecting Ansible which is not IaC focused
2. Which of the following is the correct way to describe Pulumi's approach to infrastructure as code?
easy
A. Uses general-purpose programming languages like JavaScript or Python
B. Uses JSON or YAML templates tightly integrated with AWS
C. Uses shell scripts for provisioning
D. Uses a domain-specific language called HCL

Solution

  1. Step 1: Identify Pulumi's language style

    Pulumi uses real programming languages such as JavaScript, Python, Go, or C# for defining infrastructure.
  2. Step 2: Eliminate other options

    HCL is Terraform's language, JSON/YAML with AWS is CloudFormation, and shell scripts are not Pulumi's approach.
  3. Final Answer:

    Uses general-purpose programming languages like JavaScript or Python -> Option A
  4. Quick Check:

    Pulumi = real programming languages [OK]
Hint: Pulumi uses real programming languages, not templates [OK]
Common Mistakes:
  • Confusing Pulumi with Terraform's HCL
  • Thinking Pulumi uses JSON/YAML
  • Assuming Pulumi uses shell scripts
3. Given the following statements, which tool supports multiple cloud providers and uses a simple declarative language called HCL?
1. Supports AWS, Azure, GCP
2. Uses JSON or YAML
3. Uses HCL
4. Uses programming languages like TypeScript
medium
A. Chef
B. Pulumi
C. CloudFormation
D. Terraform

Solution

  1. Step 1: Match multi-cloud support

    Terraform supports multiple clouds like AWS, Azure, and GCP.
  2. Step 2: Match language used

    Terraform uses HCL, a simple declarative language. JSON/YAML is CloudFormation, programming languages like TypeScript is Pulumi.
  3. Final Answer:

    Terraform -> Option D
  4. Quick Check:

    Multi-cloud + HCL = Terraform [OK]
Hint: Multi-cloud + HCL means Terraform [OK]
Common Mistakes:
  • Choosing Pulumi for HCL language
  • Selecting CloudFormation for multi-cloud
  • Confusing Chef with IaC tools
4. You wrote a Pulumi program in Python but it fails to deploy because it uses AWS-specific resource names not supported by Azure. What is the main error here?
medium
A. Terraform should be used instead of Pulumi for AWS
B. Pulumi does not support Python as a language
C. Using AWS resource names in a multi-cloud Pulumi program without adjusting for Azure
D. CloudFormation templates are required for Azure deployments

Solution

  1. Step 1: Identify the cause of failure

    The Pulumi program uses AWS resource names but tries to deploy on Azure, causing incompatibility.
  2. 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.
  3. Final Answer:

    Using AWS resource names in a multi-cloud Pulumi program without adjusting for Azure -> Option C
  4. Quick Check:

    Cloud-specific resource names must match target cloud [OK]
Hint: Match resource names to target cloud in Pulumi [OK]
Common Mistakes:
  • Thinking Pulumi can't use Python
  • Believing Terraform is required for AWS
  • Assuming CloudFormation works on Azure
5. You want to manage infrastructure across AWS and Azure using a single tool. You prefer writing code in TypeScript and want to reuse existing programming skills. Which tool should you choose and why?
hard
A. CloudFormation, because it is tightly integrated with AWS
B. Pulumi, because it supports multiple clouds and uses real programming languages like TypeScript
C. Terraform, because it supports multiple clouds and uses HCL
D. Ansible, because it uses YAML for automation

Solution

  1. Step 1: Identify multi-cloud support with TypeScript

    Pulumi supports multiple clouds and allows writing infrastructure code in TypeScript, matching the requirement.
  2. 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.
  3. Final Answer:

    Pulumi, because it supports multiple clouds and uses real programming languages like TypeScript -> Option B
  4. Quick Check:

    Multi-cloud + TypeScript = Pulumi [OK]
Hint: Multi-cloud + TypeScript means Pulumi [OK]
Common Mistakes:
  • Choosing Terraform for TypeScript support
  • Selecting CloudFormation for multi-cloud
  • Confusing Ansible with IaC tools