> For the complete documentation index, see [llms.txt](https://davidjosearaujo.gitbook.io/online-courses/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://davidjosearaujo.gitbook.io/online-courses/infrastructure-as-code/cloud-based-iac/terraform-vs-cloudformation.md).

# Terraform vs CloudFormation

## Terraform vs. CloudFormation

<figure><img src="https://2993487738-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FktvXVeya2CWcwDUQ6cSn%2Fuploads%2FY251rhru0xX5atam7iGc%2Fimage.png?alt=media&amp;token=83060fda-c712-4127-bcb9-0f7931e4e129" alt=""><figcaption></figcaption></figure>

### CloudFormation

* **Vendor Lock-In**: AWS CloudFormation is tightly integrated with AWS services, making it the natural choice for AWS-centric environments.
* **Native Integration**: Seamlessly integrates with other AWS services, providing direct resource references and a unified management experience.
* **Service Coverage**: Provides comprehensive coverage of AWS services, often including support for new services shortly after release.
* **Learning Curve**: Learning CloudFormation may be easier for those familiar with AWS services.

### Terraform

* **Cloud-Agnostic**: Terraform is cloud-agnostic, supporting multiple cloud providers, including AWS, Azure, Google Cloud, and more. This makes it a versatile choice for hybrid or multi-cloud deployments.
* **Community and Modules**: This has a large and active community, and using modules allows for reusable and shareable code.
* **State Management**: Terraform uses a state file to track the current state of infrastructure, providing a clear view of the deployed resources.
* **Language Flexibility**: The HashiCorp Configuration Language (HCL) used by Terraform is designed for readability and is more flexible than JSON or YAML.

## Use Cases

### Terraform Use Cases

#### 1. Multi-Cloud Environments

***Scenario*****:** A company utilises its infrastructure with multiple cloud providers such as AWS, Azure, and GCP.

Reason for Terraform:

* Terraform has providers for various cloud platforms, making it easier to manage multi-cloud environments.
* A single Terraform configuration can span different cloud providers, allowing consistent infrastructure as code (IaC) across the entire infrastructure landscape.

#### 2. Community Modules and Providers:

***Scenario***: An organisation heavily relies on community-contributed modules and providers to enhance infrastructure provisioning.

Reason for Terraform:

* Terraform has a vibrant community that contributes reusable modules and providers for a wide range of services and platforms.
* Leveraging community-driven content can significantly speed up the development process and provide best practices adopted by a broader audience.

### AWS CloudFormation Use Cases

#### 1. Deep AWS Integration

***Scenario***: An enterprise's infrastructure is predominantly AWS-centric, and the team is deeply invested in AWS-specific services and features.

Reason for CloudFormation:

* AWS CloudFormation provides native integration with AWS services, making it well-suited for managing AWS-specific resources.
* Features like CloudFormation StackSets and Change Sets enhance the management of AWS-specific resources and deployments.

#### 2. Managed Service Integration:

***Scenario***: An organisation heavily utilises AWS-managed services, such as AWS Elastic Beanstalk or AWS OpsWorks.

Reason for CloudFormation:

* AWS CloudFormation integrates seamlessly with AWS-managed services, offering simplified provisioning and management of these services.
* CloudFormation provides specific resource types for many AWS-managed services, allowing for a higher level of abstraction in the templates.
