terraform(1)
Terraform is an infrastructure-as-code tool that provisions and manages cloud resources declaratively across multiple providers.
Synopsis
terraform [global options] <command> [command options] [arguments]Description
Terraform enables you to define infrastructure using HashiCorp Configuration Language (HCL) and provision it on AWS, Azure, GCP, and other cloud providers. It maintains state files to track resource changes and supports planning changes before applying them.
Common workflow: write configuration in .tf files, run terraform plan to preview changes, then terraform apply to execute. Terraform stores state in local or remote backends to enable team collaboration and idempotent deployments.
Common options
| Flag | What it does |
|---|---|
-chdir=PATH | Switch to a different working directory before executing the command |
-var 'key=value' | Set a variable value; can be used multiple times for multiple variables |
-var-file=FILE | Load variable values from a .tfvars file |
-backend=true|false | Configure the backend; use -backend=false to skip backend initialization |
-upgrade | Allow selecting new versions for required modules and providers |
-lock=true|false | Lock the state file during operations (default: true) |
-auto-approve | Skip approval prompt; automatically apply changes (use with caution) |
-destroy | Destroy infrastructure instead of creating or updating it |
-target=resource | Target a specific resource for apply or destroy operations |
-json | Output results in JSON format for parsing by other tools |
Examples
Initialize a Terraform working directory; downloads providers and sets up the backend
terraform initGenerate and save an execution plan to tfplan without making changes; useful for review
terraform plan -out=tfplanApply the previously saved execution plan to provision infrastructure
terraform apply tfplanApply configuration with inline variable overrides for instance count and environment
terraform apply -var 'instance_count=3' -var 'environment=prod'Destroy all managed infrastructure without confirmation prompt
terraform destroy -auto-approveFormat all Terraform configuration files in the current directory recursively
terraform fmt -recursive .List all resources currently tracked in the Terraform state file
terraform state listDisplay output values as JSON, useful for scripting and integration
terraform output -json