ivkcs_user_data resource
The arguments of the ivkcs_user_data resource are given in table 1.
Name | Description | Format | Required | Default value | Resource recreation upon value change |
|---|---|---|---|---|---|
| Service deployment identifier | string | |||
| List of host names for agent initialization | list, list items — string | |||
| Target OS (for details, see the section The target_os argument) | string | |||
| Private key in | string | |||
| Public key in | string | |||
| Keys for user authentication over SSH. Added to the default user | list, list items — string | |||
| List of root certificates to be installed in the OS as trusted | list, list items — string | |||
| Defines whether to install the agent or not | boolean |
| ||
| RAM limit for the agent, MB | integer |
| ||
| Defines which packages must be installed (for details, see the section The packages argument) | set | |||
| Scripts executed via Cloud-init | list | |||
| Path to the file for writing the Marketplace API access token | string | |||
| Defines whether to enable token rotation or not | boolean |
| ||
| User assigned as the owner of the token file | string | |||
| Group assigned to the token file | string |
The ivkcs_user_data resource returns the user_data attribute in the form of a list of strings. The index in the list corresponds to the index of the host passed in the hosts argument. The value is a cloud-config configuration in the MIME archive format. Use the obtained value in the user_data argument of the vkcs_compute_instance resource.
# Creating a key pairresource "ivkcs_ssh_keypair" "test" {}# Creating a cloud-config configuration. Retrieving data for agent initialization on the hostresource "ivkcs_user_data" "test" {uuid = var.instance_uuidhosts = ["host1"]target_os = "almalinux9"ssh_authorized_keys = [ivkcs_ssh_keypair.test.public_key,]}resource "vkcs_compute_instance" "single" {name = "host1"...# Applying the cloud-config configuration to configure the VM. Installing the agent# In [] specify the host number. If the service is deployed on a single VM, the value must be 0user_data = ivkcs_user_data.test.user_data[0]...}
The possible values of the target_os argument are given in table 2. Each value corresponds to a specific base image of the cloud platform and a specific configuration of that image (a combination of the OS and the Cloud-init version).
Creation of a correct cloud-config configuration is guaranteed for the base images from the table.
Value | OS | Cloud-init version | Base OS |
|---|---|---|---|
| FreeBSD 13.2 | 23.1.1 | FreeBSD |
| Debian 11.4 | 20.4.1 | Debian |
| Ubuntu 22.04 | 22.2 | Debian |
| RedOS 7.3 | 21.4 | Debian |
| CentOS 8.4 | 19.4 | RHEL |
| ALT Server 10 | 22.3.4 | Debian |
| Astra Linux SE 1.7 «Voronezh» | 20.2 | Debian |
| AlmaLinux 9 | 22.1 | RHEL |
If the table does not contain the required OS, use the value for the closest related OS or the closest base OS. For example, the closest related OS to Ubuntu 21.10 is Ubuntu 22.04, so specify the ubuntu2204 value.
You can find out the ID of the base image in VK Cloud that corresponds to the target_os value by running the openstack image list command in OpenStack CLI. The command outputs a list of all VM images available in the project. For each image, its ID, the target_os value, and the status are displayed.
The packages arguments are given in table 3.
Name | Description | Format | Required |
|---|---|---|---|
| Package name | string | |
| Package version | string |
To specify the package name and version for the ALT Server OS, use the format:
name: "<NAME>=<VERSION_PART_1>"version: "<VERSION_PART_2>"
Here:
<NAME>— package name.<VERSION_PART_1>— package version value before the first-character.<VERSION_PART_2>— package version value after the first-character.
name: "mc=4.8.28"version: "alt1:p10+299225.100.2.1"
resource "ivkcs_user_data" "user_data" {uuid = var.instance_uuidhosts = ["host1"]target_os = "almalinux9"packages {name = "mc"version = "4.8.30"}packages {name = "tmux"version = "3.3a"}}
The user_script arguments are given in table 4.
Name | Description | Format | Default value |
|---|---|---|---|
| Script name. Scripts are executed in alphabetical order | string | |
| Script type. Defines when the script will be executed. Possible values:
| string | |
| Script body | string |
The script execution order is given in table 5.
Execution order | Script type | Description |
|---|---|---|
1 |
| Executed in alphabetical order every time the system boots |
2 |
| Executed in alphabetical order on the first boot of a new instance |
3 |
| Executed in alphabetical order once. Not run again when the instance changes |
resource "ivkcs_user_data" "init" {uuid = var.instance_uuidhosts = [local.hosts_name]target_os = "almalinux9"ssh_authorized_keys = [ivkcs_ssh_keypair.keypair.public_key,]user_script {name = "script1"content_type = "text/x-shellscript-per-once"content =<<-EOT#!/bin/bashecho "script1"EOT}user_script {name = "script2"content_type = "text/x-shellscript-per-instance"content =<<-EOT#!/bin/bashecho "script2"EOT}}
Additional information: