Terraform is a powerful Infrastructure as Code (IaC) tool that allows you to define and manage your infrastructure with simple, human-readable configuration files. As you dive into Terraform, mastering its essential commands is key to effectively managing your cloud infrastructure.
1. terraform init
Initializes a working directory. Run this first to set up your environment.
terraform init
Output:
2. terraform plan
Generates an execution plan, allowing you to preview the changes Terraform will make to your infrastructure. It helps you avoid unintended changes.
terraform plan
Output:
3. terraform apply
Applies the changes defined in your Terraform configuration. This command provisions or updates your infrastructure.
terraform apply
Output:
If everything looks good, type yes
to proceed
Terraform will then provision the resources
4. terraform destroy
Removes all resources managed by Terraform. Use this when you want to clean up or decommission an environment.
terraform destroy
Output:
5.terraform refresh
Updates the Terraform state file
to reflect the current state of your infrastructure
terraform refresh
6. terraform import
Allows you to bring existing infrastructure under Terraform management.
terraform import