AWS CloudFormation vs Terraform

Choosing the Right Infrastructure as Code Tool for Your Needs

Introduction to AWS CloudFormation

Overview

What is AWS CloudFormation

AWS CloudFormation was first announced in 2011 by Amazon Web Services, initially supporting 13 out of 15 available AWS services with 48 total resource types. It allows users to define infrastructure using declarative JSON or YAML templates to provision AWS resources in a safe, repeatable, and manageable way. As a managed AWS service, CloudFormation automatically handles dependencies between resources and offers built-in drift detection to identify unauthorized changes. Over the years, AWS has continuously enhanced CloudFormation with features like the AWS CloudFormation Registry, nested stacks, and support for third-party resources.

Native AWS Integration

File with check mark

Stack Management

Box with shadows

Drift Detection

Build model

What are the trade offs?

Advantages

  1. Seamless AWS Service Integration: CloudFormation provides day-one support for new AWS services and features, ensuring you always have access to the latest AWS capabilities without waiting for third-party tool updates.
  2. Automatic Rollbacks: CloudFormation attempts to roll back failed deployments automatically, maintaining your infrastructure in a working state when errors occur during updates or deployments.
  3. Native Security Controls: Being an AWS service, CloudFormation integrates deeply with AWS Identity and Access Management (IAM), enabling fine-grained access control and security governance for your infrastructure management.
  4. AWS Support: As a native AWS service, you can leverage AWS Support for assistance with CloudFormation issues, providing an additional layer of confidence for enterprise environments.

Disadvantages

  1. AWS-Specific: CloudFormation only works with AWS resources, making it unsuitable for multi-cloud deployments or environments that use non-AWS services.
  2. Limited Function Support: CloudFormation offers fewer built-in functions compared to Terraform, with less than 15 intrinsic functions available, potentially limiting template flexibility and complexity.
  3. Slower Deployments: For complex stacks with multiple resources, CloudFormation deployments can be slower compared to Terraform due to its sequential approach to resource provisioning.
  4. Complex Template Structure: CloudFormation templates can become unwieldy for large infrastructures, potentially resulting in massive JSON or YAML files that are difficult to maintain and navigate.

Introduction to Terraform

Overview

What is Terraform

HashiCorp released Terraform in July 2014 with initial support for AWS and DigitalOcean. Developed as a cloud-agnostic solution, Terraform allows users to define infrastructure using HashiCorp Configuration Language (HCL) or JSON. Unlike CloudFormation, Terraform supports multiple cloud providers and on-premises infrastructure through its provider ecosystem. The tool manages infrastructure state separately, tracking all provisioned resources and their configurations. Over time, Terraform has grown to become a widely adopted IaC tool with over 100 million downloads, supporting thousands of providers and modules contributed by a vibrant community. In June 2023, Terraform officially reached version 1.0, marking its maturity as an enterprise-ready solution.

Multi-Cloud Support

Lots of connected dots

State Management


{
  "version": 4,
  "terraform_version": "1.8.0",
  "serial": 1,
  "lineage": "a1b2c3d4-e5f6-7890-1234-567890abcdef",
  "outputs": {},
  "resources": [
    {
      "mode": "managed",
      "type": "aws_instance",
      "name": "example",
      "provider": "provider[\"registry.terraform.io/hashicorp/aws\"]",
      "instances": [
        {
          "schema_version": 1,
          "attributes": {
            "ami": "ami-0abcdef1234567890",
            "arn": "arn:aws:ec2:us-east-1:123456789012:instance/i-0fedcba9876543210",
            "associate_public_ip_address": true,
            "availability_zone": "us-east-1a",
            "cpu_core_count": 1,
            "cpu_threads_per_core": 1,
            "disable_api_stop": false,
            "disable_api_termination": false,
            "ebs_optimized": false,
            "get_password_data": false,
            "host_id": null,
            "iam_instance_profile": "",
            "id": "i-0fedcba9876543210",
            "instance_initiated_shutdown_behavior": "stop",
            "instance_state": "running",
            "instance_type": "t2.micro",
            "ipv6_address_count": 0,
            "ipv6_addresses": [],
            "key_name": null,
            "launch_template": [],
            "maintenance_options": [],
            "metadata_options": [],
            "monitoring": false,
            "network_interface": [],
            "outpost_arn": "",
            "placement_group": "",
            "placement_partition_number": null,
            "primary_network_interface_id": "eni-0123456789abcdef0",
            "private_dns": "ip-172-31-1-1.ec2.internal",
            "private_ip": "172.31.1.1",
            "public_dns": "ec2-1-2-3-4.compute-1.amazonaws.com",
            "public_ip": "1.2.3.4",
            "root_block_device": [],
            "security_groups": [
              "default"
            ],
            "source_dest_check": true,
            "spot_instance_request_id": "",
            "subnet_id": "subnet-0fedcba9876543210",
            "tags": {
              "Name": "example-instance"
            },
            "tags_all": {
              "Name": "example-instance"
            },
            "tenancy": "default",
            "timeouts": null,
            "user_data": null,
            "user_data_base64": null,
            "vpc_security_group_ids": [
              "sg-0abcdef1234567890"
            ]
          },
          "sensitive_attributes": [],
          "private": "eyJlMmJmYjczMC1lY2FhLTExZTYtYjE4Ny0wNTI1ZGVjMjU3YjgiOnsiY3JlYXRlIjo2MDAwMDAwMDAwMDAsImRlbGV0ZSI6MTIwMDAwMDAwMDAwMCwidXBkYXRlIjo2MDAwMDAwMDAwMDB9fQ=="
        }
      ]
    }
  ]
}

Modular Architecture

Connect dots with check marks

What are the trade offs?

Advantages

  1. Cloud-Agnostic Approach: Terraform's ability to work with multiple cloud providers makes it ideal for organizations with multi-cloud strategies or those wanting to avoid vendor lock-in.
  2. Powerful State Management: Terraform's state management allows for importing existing resources, handling configuration drift, and enabling infrastructure refactoring without resource recreation.
  3. Rich Ecosystem: With over 1,000 providers and 5,500 modules, Terraform has a vibrant community and ecosystem that contributes to its capabilities, enabling integration with virtually any service with an API.
  4. Flexible Configuration Language: HCL provides powerful features like loops, conditionals, and functions that make complex infrastructure modeling more manageable and reduce code duplication.

Disadvantages

  1. State File Security: Terraform state files may contain sensitive information, requiring careful handling to prevent security risks. Remote state storage with encryption is recommended but adds complexity.
  2. Learning Curve: Terraform's HCL syntax and concepts like state management can present a steeper learning curve for beginners compared to CloudFormation's straightforward approach.
  3. Delayed Support for New Services: As a third-party tool, Terraform may experience delays in supporting new cloud provider services and features compared to native solutions like CloudFormation.
  4. No Automatic Rollbacks: Unlike CloudFormation, Terraform does not automatically roll back failed deployments. Instead, it stops at the point of failure, potentially leaving infrastructure in an inconsistent state.

How CloudFormation and Terraform Compare

Cloud Provider Support

AWS CloudFormation

CloudFormation is designed exclusively for AWS services and resources. While it supports some third-party resources through the CloudFormation Registry, its primary focus remains on the AWS ecosystem.

Terraform

Terraform is cloud-agnostic, supporting multiple providers including AWS, Azure, Google Cloud, and many others. This makes it ideal for organizations with multi-cloud environments or those wanting to avoid vendor lock-in.

Configuration Language

AWS CloudFormation

CloudFormation uses JSON or YAML for template creation. While YAML improves readability over JSON, both formats can become unwieldy with complex nested structures and indentation requirements.

Terraform

Terraform uses HashiCorp Configuration Language (HCL), designed to balance human readability with machine interpretability. HCL typically requires fewer nested scopes than YAML and offers more powerful features like loops, conditionals, and extensive built-in functions.

State Management

AWS CloudFormation

CloudFormation manages state internally as a managed AWS service. It does not expose state files to users but provides drift detection to identify when resources have been modified outside CloudFormation.

Terraform

Terraform explicitly tracks state in state files that can be stored locally or remotely. This approach enables advanced features like importing existing resources and moving resources between configurations but requires careful management of state files.

Modularity & Reusability

AWS CloudFormation

CloudFormation offers nested stacks and modules for reusability, but these have limitations. Nested stacks hide underlying resources from the parent stack, making it difficult to see all changes during updates.

Terraform

Terraform's module system is more flexible and powerful, allowing for highly composable infrastructure definitions. Modules can be published, shared, and versioned easily, promoting code reuse across teams and projects.

Deployment & Updates

AWS CloudFormation

CloudFormation uses Change Sets to preview modifications before applying them. It attempts to roll back all changes automatically if any part of the deployment fails, maintaining infrastructure in a consistent state.

Terraform

Terraform's plan command shows a detailed preview of all changes before they're applied. Unlike CloudFormation, Terraform stops at the point of failure rather than rolling back, which can be faster but may leave infrastructure in an inconsistent state.

Which Tool Should You Choose?

AWS CloudFormation is ideal for:

Terraform is ideal for:

Are you looking for a better CI experience?

Start turning complexity into an advantage

Create an account to get started with a 30-day free trial. No credit card required.

Buildkite Pipelines

Platform

  1. Pipelines
  2. Public pipelines
  3. Test Engine
  4. Package Registries
  5. Mobile Delivery Cloud
  6. Pricing

Hosting options

  1. Self-hosted agents
  2. Mac hosted agents
  3. Linux hosted agents

Resources

  1. Docs
  2. Blog
  3. Changelog
  4. Example pipelines
  5. Plugins
  6. Webinars
  7. Case studies
  8. Events
  9. Migration Services
  10. Comparisons

Company

  1. About
  2. Careers
  3. Press
  4. Security
  5. Brand assets
  6. Contact

Solutions

  1. Replace Jenkins
  2. Workflows for AI/ML
  3. Testing at scale
  4. Monorepo mojo
  5. Bazel orchestration

Legal

  1. Terms of Service
  2. Acceptable Use Policy
  3. Privacy Policy
  4. Subprocessors
  5. Service Level Agreement

Support

  1. System status
  2. Forum
© Buildkite Pty Ltd 2025