← Back to tools

Terraform

Infrastructure as code for any cloud or service

Cloud & Services Development linuxmacoswindows Go BUSL-1.1

Description

Terraform is an infrastructure-as-code tool by HashiCorp that lets you define cloud and on-premises resources in declarative configuration files. It supports hundreds of providers (AWS, GCP, Azure, Cloudflare, and more) and manages the full lifecycle of infrastructure — provisioning, updating, and destroying resources with a consistent workflow.

Install

homebrewbrew install terraform

AI Summary

Infrastructure-as-code tool. Define cloud resources in declarative HCL files, preview changes with plan, and apply them idempotently. Supports AWS, GCP, Azure, and hundreds of other providers.

Capabilities

  • + Define infrastructure in declarative HCL configuration files
  • + Plan changes before applying to show what will be created, modified, or destroyed
  • + Provision and manage resources across AWS, GCP, Azure, and 3000+ providers
  • + Track infrastructure state for reliable updates and drift detection
  • + Create reusable modules for common infrastructure patterns
  • + Import existing infrastructure into Terraform management
  • + Generate dependency graphs of infrastructure resources

Use When

  • Managing cloud infrastructure declaratively across any provider
  • Need reproducible, version-controlled infrastructure
  • Provisioning multi-cloud or hybrid environments
  • Want to preview infrastructure changes before applying them
  • Building reusable infrastructure modules for teams

Avoid When

  • x Quick one-off resource creation (use cloud provider CLI directly)
  • x Application deployment without infrastructure changes (use CI/CD tools)
  • x Need real-time imperative commands against cloud APIs (use aws-cli, gcloud, az)

Usage Patterns

Initialize and apply infrastructure

terraform init && terraform plan -out=tfplan && terraform apply tfplan

Downloads providers, previews changes, and applies the saved plan

Destroy all resources

terraform destroy -auto-approve

Tears down all resources managed by the current configuration

Import an existing resource

terraform import aws_instance.web i-1234567890abcdef0

Brings an existing AWS instance under Terraform management

Format configuration files

terraform fmt -recursive

Reformats all .tf files in the directory tree to canonical style

Input / Output

stdin: Not typically used
stdout: Plan output, apply progress, and resource state information
Exit codes:
0 Success (or no changes in plan)
1 Error
2 Plan succeeded with changes (when using -detailed-exitcode)

Typical Pipelines

terraform plan -out=tfplan && terraform show -json tfplan | jq '.resource_changes[] | {action: .change.actions, address}'
terraform state list | fzf | xargs terraform state show
terraform output -json | jq -r '.db_endpoint.value'

Related Tools

View AGENTS.md for Terraform