Skip to content

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

brew tap hashicorp/tap
brew install hashicorp/tap/terraform

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
sudo yum install -y yum-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
sudo yum -y install terraform
sudo dnf install -y dnf-plugins-core
sudo dnf config-manager --add-repo https://rpm.releases.hashicorp.com/fedora/hashicorp.repo
sudo dnf -y install terraform
sudo yum install -y yum-utils shadow-utils
sudo yum-config-manager --add-repo https://rpm.releases.hashicorp.com/AmazonLinux/hashicorp.repo
sudo yum -y install terraform
brew tap hashicorp/tap
brew install hashicorp/tap/terraform

Binary download

Terrafrom command

After installing Terraform, you can use the following command to verify whether the installation was successful:

terraform -v

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.

Feedback

Is this page helpful? ×