Terraform Commands List
List of Terraform commands for beginners
Website Visitors:
Contents
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 initterraform plan- Generate and show an execution plan. Example:terraform plan -out=tfplanterraform apply- Build or change infrastructure. Example:terraform apply tfplanterraform destroy- Destroy Terraform-managed infrastructure. Example:terraform destroyterraform output- Extract the value of an output variable from the state file. Example:terraform output example_outputterraform validate - Validate the syntax of Terraform files. Example:terraform validate`terraform fmt- Format Terraform code. Example:terraform fmtterraform import- Import existing infrastructure into Terraform. Example:terraform import aws_instance.example i-abcd1234terraform workspace- Manage workspaces. Example:terraform workspace new devterraform state- Advanced state management. Example:terraform state listterraform graph- Create a visual graph of Terraform resources. Example:terraform graph | dot -Tpng > graph.pngterraform taint- Manually mark a resource for recreation. Example:terraform taint aws_instance.exampleterraform untaint- Remove the taint on a resource. Example:terraform untaint aws_instance.exampleterraform version- Print Terraform version. Example:terraform versionterraform force-unlock- Release the lock on a state. Example:terraform force-unlock <LOCK_ID>terraform providers- List the plugins for Terraform providers. Example:terraform providersterraform provider- Show details about a particular provider. Example:terraform provider show awsterraform debug- Debug Terraform resource operations. Example:terraform debug <RESOURCE_TYPE>.<RESOURCE_NAME>terraform console- An interactive console for Terraform interpolations. Example:terraform consoleterraform 0.12upgrade- Upgrade Terraform code from Terraform 0.11 to Terraform 0.12. Example:terraform 0.12upgradeterraform providers schema- Generate a JSON schema for Terraform providers. Example:terraform providers schema -provider=aws > schema.jsonterraform providers direction- Output the providers that terraform depends on. Example:terraform providers directionterraform state mv- Move an item (resource) in the Terraform state. Example:terraform state mv aws_instance.example aws_instance.new_exampleterraform state pull- Download and output the Terraform state data (Pull the Terraform state from a remote backend). Example:terraform state pull > state.tfstateterraform state push- Upload a Terraform state file (Push the Terraform state to a remote backend). Example:terraform state push state.tfstateterraform state rm- Remove an item (resource) from the Terraform state. Example:terraform state rm aws_instance.exampleterraform state replace-providers- Replace the providers in the Terraform state. Example:terraform state replace-providers -from=provider.old -to=provider.newterraform state show- Display a Terraform state file. Example:terraform state show aws_instance.exampleterraform state taint- Taint a Terraform-managed resource. Example:terraform state taint aws_instance.exampleterraform providers list- List the providers that are installed and available for use in Terraform. Example:terraform providers listterraform state import- Import a state into Terraform. Example:terraform state import aws_instance.example i-abcd1234terraform state list- List the resources in the Terraform state. Example:terraform state listterraform 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.
