Terraform — Infrastructure as Code tool from HashiCorp (2014). You declare desired state of cloud resources in HCL (HashiCorp Configuration Language), terraform apply creates/updates. Supports AWS, GCP, Azure, Yandex Cloud, Cloudflare, GitHub — via 3000+ providers. August 2023: HashiCorp changed license from MPL to BSL (Business Source License) → community fork **OpenTofu** (Linux Foundation, 100% compatible).
Below: details, example, related terms, FAQ.
Free online tool — HTTP header checker: instant results, no signup.
# AWS EC2 instance
resource "aws_instance" "web" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t3.small"
tags = { Name = "WebServer" }
}
# Remote state in S3
terraform {
backend "s3" {
bucket = "tfstate"
key = "prod/terraform.tfstate"
region = "us-east-1"
}
}Terraform is an open-source tool that enables Infrastructure as Code (IaC), allowing users to define and provision data center infrastructure using a declarative configuration language. It supports various cloud providers like AWS, Azure, and Google Cloud, making it a versatile choice for managing infrastructure at scale.
Terraform is a powerful tool developed by HashiCorp that enables Infrastructure as Code (IaC). IaC is a modern approach to managing and provisioning infrastructure through code, rather than manual processes. This allows for greater automation, consistency, and version control in infrastructure management.
Terraform uses a declarative configuration language known as HashiCorp Configuration Language (HCL). HCL allows users to define the desired state of their infrastructure, which Terraform then reconciles with the actual state. This approach provides a clear and concise way to manage resources across various platforms.
Key concepts in Terraform include:
By utilizing these concepts, Terraform enables teams to collaborate effectively on infrastructure projects, reducing the risk of inconsistencies and errors.
To illustrate how Terraform can be used to provision infrastructure, here’s a practical example of creating an AWS EC2 instance. This example assumes you have Terraform installed and configured with appropriate AWS credentials.
First, create a new directory for your Terraform project and navigate into it:
mkdir my-terraform-project && cd my-terraform-projectNext, create a file named main.tf and add the following configuration:
provider "aws" {
region = "us-west-2"
}
resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe01e"
instance_type = "t2.micro"
tags = {
Name = "MyExampleInstance"
}
}In this configuration:
us-west-2.Once your configuration is complete, you can initialize Terraform and apply your configuration:
terraform init
terraform applyAfter running these commands, Terraform will prompt you to confirm the creation of the resources. Type yes to proceed. Terraform will then create the EC2 instance as defined in your configuration.
To verify that your instance has been created, you can log into the AWS Management Console and navigate to the EC2 dashboard. You should see your instance listed there. To clean up and remove the resources, you can run:
terraform destroyThis command will remove all resources defined in your configuration, demonstrating the power of Terraform for managing infrastructure efficiently.
OpenTofu: free, MPL license, Linux Foundation. Terraform: BSL (non-commercial ok, commercial vendors restricted). For most teams — OpenTofu safer long-term.
Remote backend mandatory for teams: S3 + DynamoDB (lock), Terraform Cloud, or gitlab-managed-terraform-state. Local state = race conditions.
Pulumi — IaC in real programming languages (TS, Python, Go). Terraform — HCL DSL. Pulumi better for developers, Terraform for sysadmins.
Free plan — 10 monitors, checks every 5 min, no card required. Upgrade for 1-minute interval and multi-region monitoring.