Commands

Complete List of Terraform Commands

Category

Command

Description

Initialization

terraform init

Initializes Terraform (downloads providers, sets up backend, etc.).

Formatting & Validation

terraform fmt

Formats Terraform code to follow best practices.

terraform validate

Validates the Terraform configuration syntax.

Plan, Apply & Destroy

terraform plan

Shows what Terraform will do before applying changes.

terraform apply

Applies the Terraform configuration (creates/modifies resources).

terraform destroy

Destroys all resources managed by Terraform.

State Management

terraform state list

Lists all resources in the state file.

terraform state show <resource>

Shows details of a specific resource in the state.

terraform state rm <resource>

Removes a resource from the state without deleting it in the cloud.

terraform state mv <source> <destination>

Moves a resource to a new name/location in the state file.

Workspaces (Multiple Environments)

terraform workspace list

Lists all available workspaces.

terraform workspace show

Shows the current workspace.

terraform workspace new <name>

Creates a new workspace.

terraform workspace select <name>

Switches to an existing workspace.

terraform workspace delete <name>

Deletes a workspace.

Variables & Outputs

terraform output

Displays output values from Terraform.

terraform output <name>

Shows a specific output value.

Modules & Providers

terraform get

Downloads and updates modules in the configuration.

terraform providers

Lists all providers used in the current configuration.

Importing Existing Resources

terraform import <resource> <id>

Imports an existing resource into Terraform state.

Debugging & Logs

terraform taint <resource>

Marks a resource for recreation on the next apply.

terraform untaint <resource>

Removes the taint (prevents recreation).

TF_LOG=DEBUG terraform apply

Enables debug logging for troubleshooting.

Let me know if you need any explanations or examples! 🚀

Last updated