Local testing of a Terraform manifestBeta
To locally test the Terraform manifest describing the cloud infrastructure for your image-based application and its deployment procedure:
-
Prepare a network and subnet: use subnets of existing networks or create a new network and use its subnet.
-
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
terraform -helpcommand to verify that Terraform has been installed successfully.
-
Enable API access.
-
Edit the CLI configuration file for Terraform:
terraform.rcfor Windows,.terraformrcfor other OSes.-
To make Terraform work with both mirrors and local providers simultaneously, 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 Terraform does not need to work with both mirrors and local providers simultaneously, clear the file contents.
-
If your local computer does not have such a file, skip this step.
For more information, see the official Terraform documentation.
-
-
Download the VK CS provider plugin from GitHub.
-
Send an email to marketplace@cloud.vk.com to receive the iVK CS provider plugin. In the email, specify the OS of the computer on which you will locally test the manifest, as well as the OS architecture. Example: Linux on the amd64 architecture.
-
If the CLI configuration file for Terraform is missing on your 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 information, see the official Terraform documentation. -
In the
pluginsdirectory, create the following directory structure:├── ivk-cs.local│ └── ivk-cs│ └── ivkcs│ └── <PLUGIN_VERSION>│ └── <OS>├── registry.terraform.io│ └── hashicorp│ └── null│ └── <PLUGIN_VERSION>│ └── <OS>└── vk-cs.local└── vk-cs└── vkcs└── <PLUGIN_VERSION>└── <OS>Here:
-
<PLUGIN_VERSION>is 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. -
<OS>is the OS of the computer. To determine the value, run theterraform --versioncommand. The command output shows the current Terraform version and the OS name with its architecture.Example command output:
Terraform v1.5.4on linux_amd64In this example, the
<OS>value islinux_amd64.
-
-
Place the downloaded provider plugins in the corresponding
<OS>directories.Example directory structure for
/home/user_name/.terraform.d/pluginsfor the Linux OS 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 you will use.-
Specify the VK CS and iVK CS providers. If the CLI configuration file for Terraform is missing on your local computer or has been cleared, additionally specify the Null provider.
terraform {required_providers {vkcs = {# Path to the local provider plugin. The path part 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 information about the VK Cloud account and project on behalf of 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 VK Cloud platformauth_url = "https://cloud.vk.ru/infra/identity/v3/"user_domain_name = "users"username = "<USER_NAME>"password = "<PASSWORD>"project_id = "<PROJECT_ID>"region = "RegionOne"# URL of the Infra API serviceinfra_url = "https://cloud.vk.ru/marketplace/api/infra-api/api/v1/"}Here:
<PROJECT_ID>is the project ID (Project ID) that you provided in the email at the preparation stage.<USER_NAME>is the name of a user of this VK Cloud project.<PASSWORD>is the user password.
-
-
Copy the
plans/<PLAN_NAME>/deployment/deploy.tffile to the working directory. -
If local testing requires creating additional entities that are not described in the
deploy.tfmanifest (for example, a VM with an external IP):- In the working directory, create the
extended.tffile. - In the
extended.tffile, describe the additional entities using provider resources and data sources.
- In the working directory, create the
-
To initialize the providers, run the
terraform initcommand in the working directory. -
To start creating the resources described in the
deploy.tfandextended.tffiles, run theterraform applycommand in the working directory. -
To confirm resource creation, enter
yes. -
After the manifests have finished running, log in to the VK Cloud management console and verify that the resources have been created.