
Terraform Commands Reference Table
Terraform commands are the operational core of Terraform CLI. They are used to initialize working directories, validate code, preview infrastructure changes, deploy resources, inspect state, manage modules, and troubleshoot environments. The commands below provide a practical reference for the most important Terraform CLI operations used in real-world Infrastructure as Code deployments.
|
Command |
What It Does |
Explanation |
|
terraform init |
Initializes the working directory |
Downloads required providers and prepares the directory for use. It is typically the first command you run in a new or cloned project. |
|
terraform validate |
Validates configuration files |
Checks whether the Terraform configuration is syntactically valid and internally consistent before planning or applying. |
|
terraform plan |
Creates an execution plan |
Shows what Terraform intends to create, change, or destroy before making any real changes. |
|
terraform apply |
Applies infrastructure changes |
Executes the actions from a plan to create, update, or destroy infrastructure. |
|
terraform destroy |
Destroys managed infrastructure |
Removes resources managed by the current configuration. HashiCorp lists it as one of the primary workflow commands. |
Supporting and Day-to-Day Commands
|
Command |
What It Does |
Explanation |
|
terraform fmt |
Formats Terraform code |
Rewrites configuration files to Terraform’s standard style, which improves consistency and readability. |
|
terraform console |
Opens an interactive expression console |
Let’s you test Terraform expressions and inspect values using the current configuration and state. |
|
terraform show |
Displays state or saved plan contents |
Useful for reviewing the current state or examining a saved plan file in readable form. |
|
terraform output |
Shows output values |
Displays output values defined in the root module after a deployment. |
|
terraform graph |
Generates a dependency graph |
Produces a Graphviz representation of the execution graph for analysis and troubleshooting. |
|
terraform version |
Shows installed Terraform version |
Displays the current Terraform version and may also indicate whether a newer version is available. |
|
terraform providers |
Shows provider requirements |
Lists the providers required by the current configuration, which helps with dependency visibility. |
|
terraform modules |
Shows declared modules |
Gives a consolidated view of modules declared in the working directory, including source and version. HashiCorp notes this command requires Terraform v1.10.0 or later. |
State and Resource Management Commands
|
Command |
What It Does |
Explanation |
|
terraform state |
Advanced state management |
Parent command for working with Terraform state safely instead of editing state files directly. |
|
terraform state list |
Lists resources in state |
Shows all resource addresses currently tracked in the state. |
|
terraform state show |
Shows details for one resource in state |
Displays the attributes Terraform has stored for a specific resource instance. |
|
terraform state mv |
Moves items in state |
Renames or relocates tracked objects in state without recreating infrastructure. |
|
terraform state rm |
Removes resource bindings from state |
Makes Terraform forget a resource without deleting the real object in the provider. |
|
terraform state pull |
Pulls raw state data |
Downloads the latest state snapshot from the configured backend. |
|
terraform state replace-provider |
Rewrites provider references in state |
Updates provider references in the state file, typically during provider source changes or migrations. |
|
terraform import |
Imports existing infrastructure |
Associates an already existing resource with a Terraform resource address so Terraform can manage it. |
|
terraform taint |
Marks a resource for replacement |
Marks an object as tainted so Terraform will propose replacement, but HashiCorp says this command is deprecated in favor of -replace. |
|
terraform untaint |
Removes tainted status |
Clears the taint marker from a resource in state if replacement is no longer needed. |
|
terraform refresh |
Refreshes state from remote systems |
Updates state to match real infrastructure, but HashiCorp marks this command as deprecated and recommends -refresh-only with plan or apply instead. |
Workspace, Locking, and Authentication Commands
|
Command |
What It Does |
Explanation |
|
terraform workspace |
Manages workspaces |
Parent command for creating, selecting, listing, and deleting workspaces. |
|
terraform force-unlock |
Releases a stuck state lock |
Removes a stale lock on the current workspace when a previous operation did not exit cleanly. |
|
terraform login |
Stores credentials for a remote host |
Obtains and saves credentials locally for supported remote services. |
|
terraform logout |
Removes stored credentials |
Deletes locally stored credentials for a remote host. |
Metadata and Specialized Commands
|
Command |
What It Does |
Explanation |
|
terraform metadata functions |
Prints Terraform function signatures |
Shows signatures for functions available in the current Terraform version. HashiCorp notes this requires Terraform v1.4 or later. |
|
terraform get |
Installs or upgrades remote modules |
Fetches remote modules used by the configuration. In modern workflows, terraform init commonly handles module installation as part of initialization. |
Global Options You Can Mention in the Blog
|
Option |
What It Does |
Explanation |
|
-chdir=DIR |
Changes working directory before running a command |
Useful in automation when Terraform must run from a directory other than the root module folder. |
|
-help |
Shows help |
Displays help output for Terraform or for a specific subcommand. |
|
-version |
Alias for terraform version |
Prints the installed Terraform version. |
IMPORTANT NOTES FOR COMPLETENESS
The table above covers the active CLI command set shown in HashiCorp’s current Terraform CLI overview, plus the commonly used terraform state subcommands. There are also older version-specific upgrade commands such as terraform 0.12upgrade and terraform 0.13upgrade, but those are tied to legacy upgrade workflows rather than normal day-to-day Terraform usage today.

If you would like to explore this topic in greater depth, see my book Mastering Terraform: A Comprehensive Guide to Infrastructure as Code, where the subject is covered in much greater detail. The guide expands on the concepts discussed in this article with deeper architectural explanations, service capabilities, and step-by-step implementation using Azure Portal, Azure CLI, Terraform, and Bicep. It also includes real-world deployment, configuration, and troubleshooting scenarios designed for IT professionals, administrators, and cloud architects. All of my books include detailed architectural diagrams and practical deployment examples using PowerShell, Azure CLI, Terraform, and Bicep.
0 comments