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
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
Terraform Basic Commands¶
After installing Terraform, verify the installation with the following command:
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 plangenerates an execution plan showing the changes that will be made.terraform applyexecutes the changes to create, modify, or delete resources.terraform destroydeletes resources.
State Management¶
terraform state listlists all resources in the current state.terraform state showdisplays detailed information about a specific resource.terraform state rmremoves a specified resource from state.
Output¶
terraform output displays the output values defined in the current state.
Other¶
terraform validatechecks whether the configuration files are valid.terraform fmtformats the configuration files.