terraform
Infrastructure as code provisioning tool
TLDR
Initialize a Terraform working directory
SYNOPSIS
terraform command [options] [args]
DESCRIPTION
terraform is an infrastructure as code tool for building, changing, and versioning cloud infrastructure safely and efficiently. It uses declarative configuration files to describe desired infrastructure state.
Configuration is written in HCL (HashiCorp Configuration Language) defining resources like servers, networks, and databases. Terraform communicates with cloud providers (AWS, Azure, GCP, etc.) via plugins called providers.
The workflow is: init (setup), plan (preview), apply (execute). State is tracked in terraform.tfstate, enabling Terraform to know what exists and what needs changing.
Workspaces allow managing multiple environments (dev, staging, prod) from the same configuration with different state files.
PARAMETERS
init
Initialize working directory, download providersplan
Create execution plan showing proposed changesapply
Apply changes to reach desired statedestroy
Destroy all managed infrastructurefmt
Format configuration files to canonical stylevalidate
Check configuration syntax and consistencyshow
Display current state or saved planoutput
Read output values from statestate
Advanced state management commandsimport
Import existing infrastructure into stateworkspace
Manage workspaces-auto-approve
Skip interactive approval (apply/destroy)-var 'key=value'
Set input variable-var-file file
Load variables from file-target resource
Target specific resource-parallelism n
Limit concurrent operations
CONFIGURATION
terraform.tfvars
Default variable values file, automatically loaded when present in the working directory**\*.auto.tfvars**
Additional variable files automatically loaded alphabetically~/.terraformrc or %APPDATA%/terraform.rc
CLI configuration file for provider installation methods, credentials, and plugin cacheTF_VAR_name
Environment variables prefixed with TFVAR set input variable valuesTF_CLI_CONFIG_FILE
Override the default CLI configuration file location
CAVEATS
State files contain sensitive information (passwords, keys) and should be stored securely. Use remote backends (S3, Terraform Cloud) for team collaboration and state locking.
terraform destroy is irreversible. Always run plan first and verify the destruction plan carefully.
Provider versions should be pinned in configuration to ensure reproducibility. Unexpected provider updates can cause issues.
Changes made outside Terraform (manual console changes) cause state drift. Use terraform refresh or import to reconcile.
HISTORY
Terraform was created by HashiCorp and first released in 2014 by Mitchell Hashimoto. It pioneered the "infrastructure as code" approach for multi-cloud provisioning and became the de facto standard for declarative infrastructure management.
