Skip to content

Terraform

Terraform is an open-source Infrastructure as Code (IaC) tool developed by HashiCorp. It allows you to securely create, modify, and terminate infrastructure, and version these operations just like any other code. Terraform can manage various 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 resources of Guance through the Provider and manage the resources using the Terraform command-line tool.

Install Terraform

For detailed installation instructions, please refer to the official documentation. The following only lists installation methods for some operating systems. Terraform version is 1.9.5.

macOS

Package Manager

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

Binary Installation Packages

Windows

Binary Installation Packages

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 Installation Packages

Basic Terraform Commands

After installing Terraform, you can verify whether the installation was successful using the following command.

terraform -v

Terraform provides a series of commands to help you manage and operate cloud resources. The following are some commonly used commands:

Initialization

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 is used to generate an execution plan for upcoming changes and display the actions that will be performed.
  • The terraform apply command is used to execute the change plan, creating, modifying, or deleting resources.
  • The terraform destroy command is used to delete resources.

State Management

  • The terraform state list command is used to list all resources in the current state.
  • The terraform state show command is used to display detailed information about a specific resource.
  • The terraform state rm command is used to remove a specified resource.

Output

The terraform output command is used to display output values defined in the current state.

Others

  • The terraform validate command is used to verify whether the configuration files are valid.
  • The terraform fmt command is used to format the configuration files.

Feedback

Is this page helpful? ×