Contents

Terraform Commands List

List of Terraform commands for beginners

Website Visitors:

Terraform is an amazing tool that helps you to create, change, or delete infrastructure as code. In this tutorial, we’ll show you the list of terraform commands you should know to get started with Terraform.

Commands List

Here are the most common Terraform commands with basic examples:

  • terraform init - Initialize a terraform working directory. Example: terraform init
  • terraform plan - Generate and show an execution plan. Example: terraform plan -out=tfplan
  • terraform apply - Build or change infrastructure. Example: terraform apply tfplan
  • terraform destroy - Destroy Terraform-managed infrastructure. Example: terraform destroy
  • terraform output - Extract the value of an output variable from the state file. Example: terraform output example_output
  • terraform validate - Validate the syntax of Terraform files. Example: terraform validate`
  • terraform fmt - Format Terraform code. Example: terraform fmt
  • terraform import - Import existing infrastructure into Terraform. Example: terraform import aws_instance.example i-abcd1234
  • terraform workspace - Manage workspaces. Example: terraform workspace new dev
  • terraform state - Advanced state management. Example: terraform state list
  • terraform graph - Create a visual graph of Terraform resources. Example: terraform graph | dot -Tpng > graph.png
  • terraform taint - Manually mark a resource for recreation. Example: terraform taint aws_instance.example
  • terraform untaint - Remove the taint on a resource. Example: terraform untaint aws_instance.example
  • terraform version - Print Terraform version. Example: terraform version
  • terraform force-unlock - Release the lock on a state. Example: terraform force-unlock <LOCK_ID>
  • terraform providers - List the plugins for Terraform providers. Example: terraform providers
  • terraform provider - Show details about a particular provider. Example: terraform provider show aws
  • terraform debug - Debug Terraform resource operations. Example: terraform debug <RESOURCE_TYPE>.<RESOURCE_NAME>
  • terraform console - An interactive console for Terraform interpolations. Example: terraform console
  • terraform 0.12upgrade - Upgrade Terraform code from Terraform 0.11 to Terraform 0.12. Example: terraform 0.12upgrade
  • terraform providers schema - Generate a JSON schema for Terraform providers. Example: terraform providers schema -provider=aws > schema.json
  • terraform providers direction - Output the providers that terraform depends on. Example: terraform providers direction
  • terraform state mv - Move an item (resource) in the Terraform state. Example: terraform state mv aws_instance.example aws_instance.new_example
  • terraform state pull - Download and output the Terraform state data (Pull the Terraform state from a remote backend). Example: terraform state pull > state.tfstate
  • terraform state push - Upload a Terraform state file (Push the Terraform state to a remote backend). Example: terraform state push state.tfstate
  • terraform state rm - Remove an item (resource) from the Terraform state. Example: terraform state rm aws_instance.example
  • terraform state replace-providers - Replace the providers in the Terraform state. Example: terraform state replace-providers -from=provider.old -to=provider.new
  • terraform state show - Display a Terraform state file. Example: terraform state show aws_instance.example
  • terraform state taint - Taint a Terraform-managed resource. Example: terraform state taint aws_instance.example
  • terraform providers list - List the providers that are installed and available for use in Terraform. Example: terraform providers list
  • terraform state import - Import a state into Terraform. Example: terraform state import aws_instance.example i-abcd1234
  • terraform state list - List the resources in the Terraform state. Example: terraform state list
  • terraform state show - Show the details of a resource in the Terraform state. Example: terraform state show aws_instance.example

Conclusion

In this tutorial, we’ve provided you with list of Terraform Commands. All other DevOps categories are listed here: DevOps Tools. Have a look at the posts as per your topic of interest.

Please feel free to share your thoughts about this article in the comments section below.

Your inbox needs more DevOps articles.

Subscribe to get our latest content by email.