VMmanager: Administrator guide

Infrastructure management via Terraform

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

  1. 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
  2. Create a separate directory for Terraform: 


    mkdir ./terraform

Debian, Ubuntu

  1. 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
  2. Create a separate directory for Terraform:

    mkdir ./terraform

macOS

  1. 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)"
  2. Run the commands:

    brew tap hashicorp/tap
    brew install hashicorp/tap/terraform
    brew update
    brew upgrade hashicorp/tap/terraform
  3. Create a separate directory for Terraform:

    mkdir ./terraform

Windows

  1. Download the Terraform version for Windows.
  2. Unpack the contents of the archive into a separate directory. For example, C:\Apps\Terraform\ .
  3. 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:

  1. Unpack the contents of the archive into a separate directory.
  2. Add the path to the directory to the PATH system variable.

    Command for Linux
    export 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.

An example of a main.tf file to create a VM

Creating resources

  1. 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:

    Note
    Local installation of the provider is possible only on PCs with Linux OS family.
    1. 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
    2. In the main.tf file, replace the line

      source = "usaafko/vmmanager6" 

      by 

      source = "localhost/usaafko/vmmanager6"
    3. Initialize the configuration project:

      terraform init
  2. 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.
  3. 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.

  4. Start creating resources:

    terraform apply

    To confirm the creation of the resources, type yes and press Enter.

Editing resources

To edit the created resources:

  1. Edit the resource settings in the main.tf file.
  2. 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.

Note
Resources cannot be recovered after this command is executed.