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 tear down 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.

TrueWatch provides a Terraform Provider for managing TrueWatch resources. You can define and write Guance resources using the Provider and manage them through the Terraform command-line tool.

Install Terraform

For detailed installation instructions, refer to the official documentation. The following lists only installation methods for select operating systems, using 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

Terraform Basic Commands

After installing Terraform, verify the installation with the following command:

terraform -v

Terraform provides a set of commands to help you manage and operate cloud resources. Below are some commonly used commands:

Initialize

terraform init initializes a Terraform project, including downloading and installing plugins, configuring local state storage, and initializing remote state storage.

Plan and Apply

  • terraform plan generates an execution plan showing the changes that will be made.
  • terraform apply executes the changes to create, modify, or delete resources.
  • terraform destroy deletes resources.

State Management

  • terraform state list lists all resources in the current state.
  • terraform state show displays detailed information about a specific resource.
  • terraform state rm removes a specified resource from state.

Output

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

Other

  • terraform validate checks whether the configuration files are valid.
  • terraform fmt formats the configuration files.