Terraform¶
Terraform is an open-source infrastructure as code (Infrastructure as Code, IaC) tool developed by HashiCorp. It allows you to securely create, modify, and terminate 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 provides a Terraform Provider for managing Guance resources. Users can define and write related Guance resources through the Provider and manage resources via the Terraform command-line tool.
Installing Terraform¶
For detailed installation instructions, refer to the official documentation. Below are installation methods for some operating systems. The Terraform version is 1.9.5.
macOS¶
Package Manager
Binary Installation Package
Windows¶
Binary Installation Package
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 Installation Package
Basic Terraform Commands¶
After installing Terraform, use the following command to verify if the installation was successful.
Terraform offers a series of commands to help you manage and operate cloud resources. Below are some commonly used commands:
Initialization¶
The terraform init
command initializes a Terraform project, including downloading and installing plugins, configuring local state storage, initializing remote state storage, etc.
Planning and Applying¶
- The
terraform plan
command generates a change plan that will be executed and displays the actions that will be performed. - The
terraform apply
command executes the change plan, creating, modifying, or deleting resources. - The
terraform destroy
command deletes resources.
State Management¶
- The
terraform state list
command lists all resources in the current state. - The
terraform state show
command displays detailed information about a specified resource. - The
terraform state rm
command deletes a specified resource.
Output¶
The terraform output
command displays the output values defined in the current state.
Others¶
- The
terraform validate
command verifies whether configuration files are correct. - The
terraform fmt
command formats configuration files.