Local Testing of a Terraform Manifest
Before local testing, make sure the OpenStack PID is included in the list of providers (for more details, see the section Preparatory operations).
For local testing, use subnets of existing networks or create a new network and use its subnet (for more details, see the section Networks and subnets).
To locally test the Terraform manifest plans/<PLAN_NAME>/deployment/deploy.tf:
-
Install Terraform locally:
- Download Terraform from the official VK Cloud mirror.
- Extract the archive and add the path to the extracted file to the
Pathenvironment variable. - Run the command
terraform -helpto verify that Terraform has been installed successfully.
-
In the management console of the cloud platform, enable two-factor authentication (2FA) and API access (for more details, see the section 2FA management).
-
Edit the CLI configuration file for Terraform: for Windows —
terraform.rc, for other OSes —.terraformrc(for more details, see the official Terraform documentation):-
To make Terraform work with both mirrors and local providers at the same time, add the following information:
provider_installation {filesystem_mirror {# Full path to the plugins directorypath = "/home/user_name/.terraform.d/plugins"include = ["vk-cs.local/*/*", "ivk-cs.local/*/*"]}network_mirror {url = "https://terraform-mirror.mcs.mail.ru"include = ["registry.terraform.io/*/*"]}direct {exclude = ["registry.terraform.io/*/*", "vk-cs.local/*/*", "ivk-cs.local/*/*"]}} -
If it is not required for Terraform to work with both mirrors and local providers at the same time, clear the file.
-
If there is no such file on the local computer, skip this step.
-
-
Download the VK CS provider plugin from GitHub.
-
Send an email to marketplace@cloud.vk.com to obtain the iVK CS provider plugin. In the email, specify the OS of the computer on which you will locally test the manifest and its architecture (for example, Linux on the amd64 architecture).
-
If the CLI configuration file for Terraform is missing on the local computer or has been cleared, download the null provider plugin from the official Terraform website.
-
In the
terraform.ddirectory, create apluginsdirectory. Theterraform.ddirectory is created on the computer automatically after Terraform installation; its path depends on the OS (for more details, see the official Terraform documentation). -
In the
pluginsdirectory, create the following directory structure:-
ivk-cs.local.-
ivk-cs.-
ivkcs.-
<PROVIDER_VERSION>.<OPERATING_SYSTEM>.
-
-
-
-
registry.terraform.io.-
hashicorp.-
null.-
<PROVIDER_VERSION>.<OPERATING_SYSTEM>.
-
-
-
-
vk-cs.local.-
vk-cs.-
vkcs.-
<PROVIDER_VERSION>.<OPERATING_SYSTEM>.
-
-
-
Here:
-
<PROVIDER_VERSION>— the provider plugin version. The value is determined from the plugin file name. For example, for theterraform-provider-vkcs_0.4.2plugin the version is0.4.2, and for theterraform-provider-null_v3.2.1_x5plugin it is3.2.1. -
<OPERATING_SYSTEM>— the OS of the computer. To determine the value, run the commandterraform --version. The command output displays the current Terraform version and the OS with its architecture.Example outputTerraform v1.5.4on linux_amd64In the example above, the value of
<OPERATING_SYSTEM>islinux_amd64.
-
-
Place the downloaded provider plugins in the corresponding
<OPERATING_SYSTEM>directories.Example of the `/home/user_name/.terraform.d/plugins` directory structure for Linux on the amd64 architecture/home/user_name/.terraform.d│└── plugins├── ivk-cs.local│ └── ivk-cs│ └── ivkcs│ └── 0.0.4│ └── linux_amd64│ └── terraform-provider-ivkcs_0.0.4├── registry.terraform.io│ └── hashicorp│ └── null│ └── 3.2.1│ └── linux_amd64│ └── terraform-provider-null_v3.2.1└── vk-cs.local└── vk-cs└── vkcs└── 0.4.2└── linux_amd64└── terraform-provider-vkcs_0.4.2 -
Create a working directory for testing the manifest.
-
In the working directory, create the
auth.tffile. -
In the
auth.tffile, describe the providers to be used.-
Specify the VK CS and iVK CS providers. If the CLI configuration file for Terraform is missing on the local computer or has been cleared, additionally specify the null provider.
terraform {required_providers {vkcs = {# Path to the local provider plugin. The part of the path after terraform.d/plugins is specifiedsource = "vk-cs.local/vk-cs/vkcs"# Provider versionversion = "0.2.2"}ivkcs = {source = "ivk-cs.local/ivk-cs/ivkcs"version = "0.1.15"}null = {source = "registry.terraform.io/hashicorp/null"version = "3.2.1"}}} -
For the VK CS and iVK CS providers, specify the information about the account and project of the cloud platform under which you will test the manifest:
provider "vkcs" {# User Domain IDuser_domain_name = "users"username = "USER_NAME"password = "PASSWORD"project_id = "PROJECT_ID"# Region Nameregion = "RegionOne"}provider "ivkcs" {# URL of the Keystone component of the cloud platformauth_url = "https://cloud.vk.ru/infra/identity/v3/"user_domain_name = "users"username = "USER_NAME"password = "PASSWORD"project_id = "OPENSTACK_PROJECT_ID"region = "RegionOne"# URL of the Infra API serviceinfra_url = "https://cloud.vk.ru/marketplace/api/infra-api/api/v1/"}The information about the account and project is displayed in the management console of the cloud platform.
-
-
Copy the file
plans/<PLAN_NAME>/deployment/deploy.tfto the working directory. -
If additional entities that are not described in the
deploy.tfmanifest (for example, a VM with an external IP) need to be created for local testing, create theextended.tffile in the working directory. -
In the
extended.tffile, describe the additional entities using the resources and data sources of the providers. -
In the working directory, run the command
terraform initto initialize the providers. -
In the working directory, run the command
terraform applyto start creating the resources described in thedeploy.tfandextended.tffiles. -
Enter
yesto confirm the creation of the resources. -
After the manifests have finished executing, log in to the management console of the cloud platform and verify that the resources have been created.