Terraform Basic Commands: A Quick Guide
Terraform is an open-source tool that allows you to manage infrastructure as code across various cloud providers. Here’s a brief overview of the essential Terraform commands every DevOps engineer should know:
1. terraform init
- Purpose: Initializes a Terraform working directory by downloading necessary plugins and setting up the backend.
-
Usage:
terraform init
2. terraform fmt
- Purpose: Formats Terraform configuration files for consistency.
-
Usage:
terraform fmt
3. terraform validate
- Purpose: Validates the syntax and consistency of your configuration files.
-
Usage:
terraform validate
4. terraform plan
- Purpose: Creates an execution plan, showing the changes Terraform will make to your infrastructure.
-
Usage:
terraform plan
5. terraform apply
- Purpose: Applies the changes required to reach the desired state of the configuration.
-
Usage:
terraform apply
6. terraform destroy
- Purpose: Destroys all the resources defined in your configuration, effectively tearing down your infrastructure.
-
Usage:
terraform destroy
7. terraform show
- Purpose: Displays the current state or details of a saved plan.
-
Usage:
terraform show
8. terraform state
- Purpose: Manages Terraform’s state, including listing and modifying resources.
-
Usage:
terraform state <subcommand>
9. terraform refresh
- Purpose: Updates the state file with the real infrastructure’s current state.
-
Usage:
terraform refresh
10. terraform import
- Purpose: Imports existing resources into Terraform's state.
-
Usage:
terraform import <resource_type>.<resource_name> <resource_id>
11. terraform output
- Purpose: Retrieves the value of output variables from your configuration.
-
Usage:
terraform output
12. terraform workspace
- Purpose: Manages multiple workspaces, allowing you to handle different environments.
-
Usage:
terraform workspace <subcommand>
These commands form the core of Terraform operations, enabling you to efficiently manage your cloud infrastructure with confidence.
Top comments (0)