Getting Started with Terraform
This guide walks you through installing and using Terraform to manage infrastructure programmatically using configuration files.
Terraform can run anywhere with a CLI or as part of your infrastructure automation tools. Follow these steps to install:
- Download the latest binary for your operating system from our downloads page
- Extract the archive file
- Add the terraform binary to your system PATH
- Verify the install with
terraform --version
- Install required providers
terraform init
Terraform is open source and available on GitHub at hashicorp/terraform.
Create a basic infrastructure configuration in main.tf
:
provider "aws" {
region = "us-west-2"
}
resource "aws_instance" "example" {
ami = "ami-12345678"
instance_type = "t2.micro"
tags = {
Name = "example-ec2"
}
}
Run terraform apply
to create your first infrastructure resource. This will provision an AWS instance in the configured region.
Terraform saves a state file showing the state of your infrastructure. This state file must be protected by encryption at rest and in transit. Use terraform state
commands for inspection and management.
terraform apply
This command will output your resources and show exactly what infrastructure elements will be created.
- Explore additional resources and providers
- Read about workspaces for environment management
- See how to apply infrastructure-as-code in your team workflow