VK Cloud logo

Service infrastructure description in the manifestBeta

The Terraform manifest describes the infrastructure configuration for deploying an image-based application instance in Marketplace and includes the following components:

Creating the instance VM

Creating a VM from the service boot image includes the following components:

  1. Retrieving VM virtual network data from the vkcs_networking_subnet data source.

  2. (Optional) Creating a security group using the resources:

    • vkcs_networking_secgroup — security group.
    • vkcs_networking_secgroup_rule — access rules for the security group.
  3. Creating the root disk using the vkcs_blockstorage_volume resource.

    The resource specifies the following parameters of your service:

    • ID of the previously created service image;

    • service name <SERVICE_NAME> in the root disk metadata:

      metadata = { "sid" : "xaas", "product" : "<SERVICE_NAME>" }
  4. Creating a separate volume for storing service data using the vkcs_blockstorage_volume resource. In the resource, the disk metadata is specified in the same way as for the root disk.

  5. Creating a VM key pair using the ivkcs_ssh_keypair resource.

  6. Creating a VM from the service boot image and installing the agent using the resources:

    • vkcs_compute_instance. In the resource, the VM metadata is specified in the same way as for the root disk. This is needed so that the service instance VM is displayed on the Virtual machines page of the personal dashboard in a separate block for Marketplace virtual machines.
    • ivkcs_user_data.

    Before publishing the service, the service image ID in the vkcs_compute_instance resource must be replaced with the public ID. For more details, see the section on publishing the service image.

  7. Attaching the separate data volume to the VM using the vkcs_compute_volume_attach resource.

  8. Passing VM data (for example, the private SSH key) in the output parameters.

Retrieving the SDN type and using it in Terraform resources

The SDN type is set in the sdn parameter of the vkcs_networking_subnet resource. The parameter can take one of the following values:

  • neutron — SDN based on OpenStack Neutron.
  • sprut — SDN based on Sprut.

The default value for the sdn parameter corresponds to the SDN type set by default in the VK Cloud user's project. If the default SDN type in the project is based on Sprut, the default value for the sdn parameter is sprut.

The Terraform manifest resources retrieve the SDN type and other subnet data from the vkcs_networking_subnet data source.

Example of retrieving subnet data:

data "vkcs_networking_subnet" "subnet" {  # Subnet ID specified in the ds-subnet variable  id = var.ds-subnet}

Example of using the SDN type in the vkcs_networking_secgroup resource:

resource "vkcs_networking_secgroup" "secgroup" {  name = "security_group"  description = "terraform security group"  sdn = data.vkcs_networking_subnet.subnet.sdn}

Using the SDN type when retrieving a pool of external IP addresses

The vkcs_networking_floatingip resource is used to retrieve a pool of external IP addresses. In the pool parameter of the resource, the external network name is specified so that it is determined automatically depending on the SDN type:

  • If the SDN is based on OpenStack Neutron — ext-net.
  • If the SDN is based on Sprut — internet.

Example of using the SDN type in the vkcs_networking_floatingip resource:

resource "vkcs_networking_floatingip" "base_fip" {  pool  = data.vkcs_networking_subnet.subnet.sdn == "neutron" ? "ext-net" : "internet"}

Assigning a fixed IP address

The IP address of the instance VM must be fixed so that it does not change when the service is reinstalled. Assigning a fixed IP address includes the following components:

  1. Binding the IP address to a VM subnet port using the vkcs_networking_port resource.

    Example of binding an IP address to a port:

    resource "vkcs_networking_port" "port" {  name               = "port name"  admin_state_up     = "true"  # Virtual network ID  network_id         = data.vkcs_networking_subnet.subnet.network_id  # IDs of the security groups applied to the port  security_group_ids = [vkcs_networking_secgroup.secgroup.id]  # SDN type  sdn                = data.vkcs_networking_subnet.subnet.sdn  fixed_ip {    # ID of the subnet from which the port IP address will be assigned    subnet_id = var.ds-subnet  }}

    More about SDN.

  2. Specifying the port ID in the vkcs_compute_instance resource:

    resource "vkcs_compute_instance" "compute" {...  network {    port = vkcs_networking_port.port.id  }}

Generating service instance access passwords

Service instance access passwords are generated using the random_password resource.

Example of using the random_password resource:

resource "random_password" "user" {# Whether to use special characters in the passwordspecial = false# Password lengthlength  = 50}

The generated password is passed to the user in the output parameters.

Was this article helpful?