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 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 the Terraform Provider for managing Guance resources. Users can define and write related resources of Guance through the Provider, and manage resources via the Terraform command-line tool.

Install Terraform

For detailed installation instructions for Terraform, refer to the official documentation. Below are installation methods for some operating systems, with Terraform version 1.9.5.

macOS

Package Manager

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

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
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 Package

Basic Terraform Commands

After installing Terraform, you can verify the installation with the following command.

terraform -v

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, and initializing remote state storage.

Plan and Apply

  • The terraform plan command generates a plan of the changes to be executed and displays the operations to be performed.
  • The terraform apply command executes the change plan, creating, modifying, or deleting resources.
  • The terraform destroy command is used to delete 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 removes a specified resource.

Output

The terraform output command displays the output values defined in the current state.

Others

  • The terraform validate command validates whether the configuration files are correct.
  • The terraform fmt command formats the configuration files.

Feedback

Is this page helpful? ×