Terraform¶
Terraform is an open-source Infrastructure as Code (IaC) tool developed by HashiCorp. It allows you to safely create, modify, and stop infrastructure, and these operations can be versioned just like any other code. Terraform can manage multiple cloud service providers (such as AWS, Azure, Google Cloud Platform, etc.), network devices, and other resources.
Guance Cloud provides a Terraform Provider for managing Guance Cloud resources. Users can define and script related Guance Cloud resources through the Provider and manage these resources using the Terraform command-line tool.
Install Terraform¶
For detailed installation instructions for Terraform, please refer to the official documentation. Below, we list the installation procedures for some operating systems. The version of Terraform discussed here is 1.9.5.
macOS¶
Package manager
Binary download
Windows¶
Binary download
Linux¶
Package manager
wget -O- https://apt.releases.hashicorp.com/gpg | sudo gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg
echo "deb [signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/hashicorp.list
sudo apt update && sudo apt install terraform
Binary download
Terrafrom command¶
After installing Terraform, you can use the following command to verify whether the installation was successful:
Terraform provides a series of commands to help you manage and manipulate resources in the cloud. Here are some commonly used commands:
Initialization¶
terraform init
: Initialize your Terraform working directory. This command is used to initialize a Terraform project and download the necessary plugins or providers.
Plan and Apply¶
terraform plan
: Show what actions Terraform plans to take to reach the desired state of your infrastructure. This command is essential for previewing changes.terraform apply
: Apply the changes required to reach the desired state of your infrastructure. After reviewing the plan, you confirm you want to proceed, and Terraform will make the changes.terraform destroy
: Destroy the resources managed by Terraform, effectively cleaning up the infrastructure you've created.
State¶
terraform state list
: List all the resources in the Terraform state.terraform state show
: Show the details of a specific resource in the Terraform state.terraform state rm
: Remove a resource from the Terraform state.
输出¶
terraform output
: Display the output values of your Terraform configuration.
其他¶
terraform validate
: Validate your Terraform configuration files.terraform fmt
: Format your Terraform configuration files.