Terraform is a software for managing external infrastructure. With Terraform, you can manage VMmanager resources - virtual machines (VMs), networks, etc.
Terraform uses the Infrastructure as code (IaC) approach – all commands and settings for resources are transmitted through configuration files. The configuration files use the declarative language HCL (HashiCorp Configuration Language). Read more about Terraform in the official documentation .
Terraform interacts with infrastructure objects using a special set of instructions - a provider. The provider documentation for VMmanager is available at registry.terraform.io and github.com .
Installing Terraform
Standard method
AlmaLinux, CentOS
-
Run the commands:
yum install -y yum-utils
yum-config-manager --add-repo https://rpm.releases.hashicorp.com/RHEL/hashicorp.repo
yum -y install terraform
-
Create a separate directory for Terraform:
mkdir ./terraform
Debian, Ubuntu
-
Run the commands:
apt-get update && apt-get install -y gnupg software-properties-common curl
curl -fsSL https://apt.releases.hashicorp.com/gpg | apt-key add -
apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main"
sudo apt-get update && sudo apt-get install terraform
-
Create a separate directory for Terraform:
mkdir ./terraform
macOS
-
If the Homebrew packet manager is not installed in the system, install it:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
-
Run the commands:
brew tap hashicorp/tap
brew install hashicorp/tap/terraform
brew update
brew upgrade hashicorp/tap/terraform
-
Create a separate directory for Terraform:
mkdir ./terraform
Windows
- Download the Terraform version for Windows.
- Unpack the contents of the archive into a separate directory. For example, C:\Apps\Terraform\ .
- Add the path to the Terraform directory to the PATH system variable. The order of addition depends on the OS version.
Alternative method
If the Terraform repository is unavailable, you can download the software distribution from the repository mirror. After downloading:
- Unpack the contents of the archive into a separate directory.
-
Add the path to the directory to the PATH system variable.
Command for Linuxexport PATH=$PATH:/path/to/terraform
Comments to the command
Preparing the configuration
To prepare the configuration, create a main.tf file in the Terraform directory.
Creating resources
-
Initialize the configuration project:
terraform init
If the resource with provider is unavailable, the response will contain an error of the form
│ Error: Failed to query available provider packages │ │ Could not retrieve the list of available versions for provider │ usaafko/vmmanager6: could not connect to registry.terraform.io: Failed to │ request discovery document: 403 Forbidden
In this case, you can install the provider locally:
NoteLocal installation of the provider is possible only on PCs with Linux OS family.-
Run the commands:
mkdir -p ~/.terraform.d/plugins/localhost/usaafko/vmmanager6/0.0.25/linux_amd64/
curl -L https://github.com/usaafko/terraform-provider-vmmanager6/releases/download/v0.0.25/terraform-provider-vmmanager6_0.0.25_linux_amd64.zip -o terraform-provider-vmmanager6.zip
unzip terraform-provider-vmmanager6.zip
mv terraform-provider-vmmanager6_v0.0.25 ~/.terraform.d/plugins/localhost/usaafko/vmmanager6/0.0.25/linux_amd64/terraform-provider-vmmanager6
-
In the main.tf file, replace the line
source = "usaafko/vmmanager6"
by
source = "localhost/usaafko/vmmanager6"
-
Initialize the configuration project:
terraform init
-
-
Check the syntax of the configuration file:
terraform validate
If the configuration is valid, the response will contain the message:
Success! The configuration is valid.
-
Check that the resources will be created with the required configuration:
terraform plan
The output of the command will list the resources to be created and their properties. If necessary, you can correct the configuration file and run the command again.
-
Start creating resources:
terraform apply
To confirm the creation of the resources, type yes and press Enter.
Editing resources
To edit the created resources:
- Edit the resource settings in the main.tf file.
-
Run the command:
terraform apply
To confirm editing of the resources, type yes and press Enter.
If some resources have already been created, Terraform will not recreate them.
Deleting resources
To delete the created resources, run the command:
terraform destroy
After running the command, the terminal will display the list of resources to be deleted. To confirm deletion, type yes and press Enter.