Terraform¶
Terraform is an open-source Infrastructure as Code (IaC) tool developed by HashiCorp. It allows you to securely create, modify, and decommission infrastructure, and version these operations 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 configurations for Guance resources using the Provider and manage them via the Terraform command-line tool.
Install Terraform¶
For detailed installation instructions for Terraform, please refer to the official documentation. The following lists installation methods for some operating systems only, using Terraform version 1.9.5.
macOS¶
Package Manager
Binary Package
Windows¶
Binary 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 Package
Basic Terraform Commands¶
After installing Terraform, you can verify the installation with the following command.
Terraform provides a series of commands to help you manage and operate cloud resources. Here are some commonly used commands:
Initialize¶
The terraform init command is used to initialize a Terraform project, including downloading and installing plugins, configuring local state storage, initializing remote state storage, etc.
Plan and Apply¶
- The
terraform plancommand generates an execution plan showing the changes that will be made. - The
terraform applycommand executes the plan to create, modify, or delete resources. - The
terraform destroycommand is used to delete resources.
State Management¶
- The
terraform state listcommand lists all resources in the current state. - The
terraform state showcommand displays detailed information for a specified resource. - The
terraform state rmcommand removes a specified resource from the state.
Output¶
The terraform output command displays the output values defined in the current state.
Others¶
- The
terraform validatecommand validates configuration files for correctness. - The
terraform fmtcommand formats configuration files.