Convert Figma logo to code with AI

hashicorp logoterraform

Terraform enables you to safely and predictably create, change, and improve infrastructure. It is a source-available tool that codifies APIs into declarative configuration files that can be shared amongst team members, treated as code, edited, reviewed, and versioned.

42,146
9,473
42,146
1,963

Top Related Projects

22,441

OpenTofu lets you declaratively manage your cloud infrastructure.

20,922

Pulumi - Infrastructure as Code in any programming language 🚀

62,307

Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy and maintain. Automate everything from code deployment to network configuration to cloud management, in a language that approaches plain English, using SSH, with no agents to install on remote systems. https://docs.ansible.com.

7,565

Chef Infra, a powerful automation platform that transforms infrastructure into code automating how infrastructure is configured, deployed and managed across any environment, at any scale

7,421

Server automation framework and application

Quick Overview

Terraform is an open-source infrastructure as code (IaC) tool created by HashiCorp. It allows users to define and provision infrastructure resources across various cloud providers and services using a declarative language. Terraform enables consistent and version-controlled infrastructure management, promoting collaboration and automation in DevOps practices.

Pros

  • Multi-cloud support: Works with numerous cloud providers and services
  • Declarative syntax: Easy-to-read HCL (HashiCorp Configuration Language) for defining infrastructure
  • State management: Tracks and manages the current state of infrastructure
  • Large ecosystem: Extensive collection of providers and modules for various resources

Cons

  • Learning curve: Can be challenging for beginners to master
  • State file management: Requires careful handling of state files, especially in team environments
  • Limited rollback capabilities: Doesn't always provide seamless rollback options for failed operations
  • Performance issues: Can be slow when managing large-scale infrastructures

Code Examples

  1. Creating an AWS EC2 instance:
resource "aws_instance" "example" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t2.micro"
  tags = {
    Name = "ExampleInstance"
  }
}
  1. Defining a Google Cloud Storage bucket:
resource "google_storage_bucket" "example_bucket" {
  name     = "my-unique-bucket-name"
  location = "US"
}
  1. Creating an Azure Resource Group:
resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = "West Europe"
}

Getting Started

  1. Install Terraform from the official website: https://www.terraform.io/downloads.html
  2. Create a new directory for your Terraform project
  3. Create a file named main.tf and add your infrastructure code
  4. Initialize the Terraform working directory:
    terraform init
    
  5. Review the planned changes:
    terraform plan
    
  6. Apply the changes to create the infrastructure:
    terraform apply
    

Competitor Comparisons

22,441

OpenTofu lets you declaratively manage your cloud infrastructure.

Pros of OpenTofu

  • Fully open-source and community-driven development
  • Potential for faster feature implementation and bug fixes
  • More flexible licensing options for enterprise use

Cons of OpenTofu

  • Smaller ecosystem and community support compared to Terraform
  • Less established track record and potential stability concerns
  • May lag behind Terraform in terms of new feature releases

Code Comparison

Both OpenTofu and Terraform use similar syntax for defining infrastructure. Here's a basic example:

OpenTofu:

resource "aws_instance" "example" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t2.micro"
}

Terraform:

resource "aws_instance" "example" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t2.micro"
}

As you can see, the code structure and syntax are identical for basic resource definitions. The main differences lie in the underlying implementation, community support, and potential future divergence in features or syntax.

Both projects aim to provide infrastructure as code capabilities, with OpenTofu being a community-driven fork of Terraform. The choice between them may depend on specific requirements, licensing needs, and preference for community-driven vs. corporate-backed development.

20,922

Pulumi - Infrastructure as Code in any programming language 🚀

Pros of Pulumi

  • Supports multiple programming languages (Python, JavaScript, Go, etc.)
  • Offers object-oriented approach to infrastructure as code
  • Provides better integration with existing development workflows

Cons of Pulumi

  • Smaller community and ecosystem compared to Terraform
  • Steeper learning curve for those unfamiliar with programming languages
  • Less mature and battle-tested in large-scale production environments

Code Comparison

Terraform (HCL):

resource "aws_instance" "example" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t2.micro"
}

Pulumi (Python):

import pulumi_aws as aws

instance = aws.ec2.Instance("example",
    ami="ami-0c55b159cbfafe1f0",
    instance_type="t2.micro"
)

Both Terraform and Pulumi are powerful infrastructure as code tools. Terraform uses its domain-specific language (HCL), while Pulumi leverages general-purpose programming languages. This allows Pulumi to offer more flexibility and familiarity for developers, but may require more setup and understanding of programming concepts. Terraform, on the other hand, provides a more straightforward approach with its declarative syntax, making it easier for beginners to get started with infrastructure as code.

62,307

Ansible is a radically simple IT automation platform that makes your applications and systems easier to deploy and maintain. Automate everything from code deployment to network configuration to cloud management, in a language that approaches plain English, using SSH, with no agents to install on remote systems. https://docs.ansible.com.

Pros of Ansible

  • Agentless architecture, requiring no software installation on managed nodes
  • Broader scope for configuration management and application deployment
  • Simpler learning curve with YAML-based playbooks

Cons of Ansible

  • Less robust state management compared to Terraform's state files
  • Not as specialized for infrastructure provisioning across multiple cloud providers
  • Can be slower for large-scale deployments due to its sequential execution model

Code Comparison

Ansible task:

- name: Create EC2 instance
  ec2:
    key_name: mykey
    instance_type: t2.micro
    image: ami-123456
    wait: yes
    group: webserver
    count: 1
    vpc_subnet_id: subnet-29e63245
    assign_public_ip: yes

Terraform resource:

resource "aws_instance" "web" {
  ami           = "ami-123456"
  instance_type = "t2.micro"
  key_name      = "mykey"
  subnet_id     = "subnet-29e63245"
  vpc_security_group_ids = [aws_security_group.webserver.id]
  associate_public_ip_address = true
}

Both Ansible and Terraform are powerful tools for infrastructure management, but they serve different primary purposes. Ansible excels in configuration management and application deployment, while Terraform specializes in infrastructure provisioning and state management across multiple cloud providers.

7,565

Chef Infra, a powerful automation platform that transforms infrastructure into code automating how infrastructure is configured, deployed and managed across any environment, at any scale

Pros of Chef

  • More mature and established in the configuration management space
  • Offers a wider range of features for complex infrastructure management
  • Provides a robust ecosystem with a large community and extensive cookbook library

Cons of Chef

  • Steeper learning curve, especially for those new to Ruby
  • Requires more setup and maintenance of a centralized server
  • Can be slower to execute compared to Terraform's declarative approach

Code Comparison

Chef (Ruby DSL):

package 'nginx' do
  action :install
end

service 'nginx' do
  action [:enable, :start]
end

Terraform (HCL):

resource "aws_instance" "web" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t2.micro"
  tags = {
    Name = "WebServer"
  }
}

Chef focuses on configuring and managing the internal state of servers, while Terraform is designed for provisioning and managing infrastructure resources. Chef uses a Ruby-based DSL for defining configurations, whereas Terraform uses its own HCL (HashiCorp Configuration Language) for describing infrastructure. Chef's approach is more imperative, specifying steps to achieve a desired state, while Terraform's declarative style defines the desired end state, leaving the execution details to the tool itself.

7,421

Server automation framework and application

Pros of Puppet

  • More mature and established in the configuration management space
  • Stronger focus on maintaining system state over time
  • Better suited for managing complex, heterogeneous environments

Cons of Puppet

  • Steeper learning curve, especially for those new to configuration management
  • Less flexible for managing cloud resources compared to Terraform
  • Slower adoption of new technologies and cloud services

Code Comparison

Puppet manifest example:

package { 'nginx':
  ensure => installed,
}

service { 'nginx':
  ensure  => running,
  enable  => true,
  require => Package['nginx'],
}

Terraform configuration example:

resource "aws_instance" "web" {
  ami           = "ami-0c55b159cbfafe1f0"
  instance_type = "t2.micro"
  tags = {
    Name = "WebServer"
  }
}

Puppet focuses on defining the desired state of systems, while Terraform is designed for provisioning and managing infrastructure resources. Puppet uses its own domain-specific language, whereas Terraform uses HCL (HashiCorp Configuration Language). Terraform's syntax is generally considered more intuitive for infrastructure provisioning tasks, while Puppet's language is tailored for system configuration management.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

Terraform

Terraform

Terraform is a tool for building, changing, and versioning infrastructure safely and efficiently. Terraform can manage existing and popular service providers as well as custom in-house solutions.

The key features of Terraform are:

  • Infrastructure as Code: Infrastructure is described using a high-level configuration syntax. This allows a blueprint of your datacenter to be versioned and treated as you would any other code. Additionally, infrastructure can be shared and re-used.

  • Execution Plans: Terraform has a "planning" step where it generates an execution plan. The execution plan shows what Terraform will do when you call apply. This lets you avoid any surprises when Terraform manipulates infrastructure.

  • Resource Graph: Terraform builds a graph of all your resources, and parallelizes the creation and modification of any non-dependent resources. Because of this, Terraform builds infrastructure as efficiently as possible, and operators get insight into dependencies in their infrastructure.

  • Change Automation: Complex changesets can be applied to your infrastructure with minimal human interaction. With the previously mentioned execution plan and resource graph, you know exactly what Terraform will change and in what order, avoiding many possible human errors.

For more information, refer to the What is Terraform? page on the Terraform website.

Getting Started & Documentation

Documentation is available on the Terraform website:

If you're new to Terraform and want to get started creating infrastructure, please check out our Getting Started guides on HashiCorp's learning platform. There are also additional guides to continue your learning.

Show off your Terraform knowledge by passing a certification exam. Visit the certification page for information about exams and find study materials on HashiCorp's learning platform.

Developing Terraform

This repository contains only Terraform core, which includes the command line interface and the main graph engine. Providers are implemented as plugins, and Terraform can automatically download providers that are published on the Terraform Registry. HashiCorp develops some providers, and others are developed by other organizations. For more information, see Extending Terraform.

License

Business Source License 1.1