$linuxjunkies
>

terraform(1)

Terraform is an infrastructure-as-code tool that provisions and manages cloud resources declaratively across multiple providers.

UbuntuDebianFedoraArch

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

FlagWhat it does
-chdir=PATHSwitch 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=FILELoad variable values from a .tfvars file
-backend=true|falseConfigure the backend; use -backend=false to skip backend initialization
-upgradeAllow selecting new versions for required modules and providers
-lock=true|falseLock the state file during operations (default: true)
-auto-approveSkip approval prompt; automatically apply changes (use with caution)
-destroyDestroy infrastructure instead of creating or updating it
-target=resourceTarget a specific resource for apply or destroy operations
-jsonOutput results in JSON format for parsing by other tools

Examples

Initialize a Terraform working directory; downloads providers and sets up the backend

terraform init

Generate and save an execution plan to tfplan without making changes; useful for review

terraform plan -out=tfplan

Apply the previously saved execution plan to provision infrastructure

terraform apply tfplan

Apply 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-approve

Format all Terraform configuration files in the current directory recursively

terraform fmt -recursive .

List all resources currently tracked in the Terraform state file

terraform state list

Display output values as JSON, useful for scripting and integration

terraform output -json

Related commands