VK Cloud logo

ivkcs_user_data resource

The arguments of the ivkcs_user_data resource are given in table 1.

Table 1 — Arguments of the ivkcs_user_data resource

Name

Description

Format

Required

Default value

Resource recreation upon value change

uuid

Service deployment identifier

string

ivkcs_user_data resource

ivkcs_user_data resource

ivkcs_user_data resource

hosts

List of host names for agent initialization

list, list items — string

ivkcs_user_data resource

ivkcs_user_data resource

ivkcs_user_data resource

target_os

Target OS (for details, see the section The target_os argument)

string

ivkcs_user_data resource

ivkcs_user_data resource

ivkcs_user_data resource

ssh_private_key

Private key in RSA format for host identification. Used together with the ssh_public_key argument

string

ivkcs_user_data resource

ivkcs_user_data resource

ivkcs_user_data resource

ssh_public_key

Public key in RSA format for host identification. Used together with the ssh_private_key argument

string

ivkcs_user_data resource

ivkcs_user_data resource

ivkcs_user_data resource

ssh_authorized_keys

Keys for user authentication over SSH. Added to the default user

list, list items — string

ivkcs_user_data resource

ivkcs_user_data resource

ivkcs_user_data resource

ca_certificates

List of root certificates to be installed in the OS as trusted

list, list items — string

ivkcs_user_data resource

ivkcs_user_data resource

ivkcs_user_data resource

agent_install

Defines whether to install the agent or not

boolean

ivkcs_user_data resource

true

ivkcs_user_data resource

agent_memory_limit

RAM limit for the agent, MB

integer

ivkcs_user_data resource

512

ivkcs_user_data resource

packages

Defines which packages must be installed (for details, see the section The packages argument)

set

ivkcs_user_data resource

ivkcs_user_data resource

ivkcs_user_data resource

user_script

Scripts executed via Cloud-init

list

ivkcs_user_data resource

ivkcs_user_data resource

ivkcs_user_data resource

token_file_path

Path to the file for writing the Marketplace API access token

string

ivkcs_user_data resource

ivkcs_user_data resource

ivkcs_user_data resource

token_rotate

Defines whether to enable token rotation or not

boolean

ivkcs_user_data resource

false

ivkcs_user_data resource

token_file_owner

User assigned as the owner of the token file

string

ivkcs_user_data resource

ivkcs_user_data resource

ivkcs_user_data resource

token_file_group

Group assigned to the token file

string

ivkcs_user_data resource

ivkcs_user_data resource

ivkcs_user_data resource

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.

Example of using the `ivkcs_user_data` 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_uuid  hosts               = ["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 0  user_data = ivkcs_user_data.test.user_data[0]  ...}

The target_os argument

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.

Table 2 — Possible values of the target_os argument

Value

OS

Cloud-init version

Base OS

freebsd132

FreeBSD 13.2

23.1.1

FreeBSD

debian114

Debian 11.4

20.4.1

Debian

ubuntu2204

Ubuntu 22.04

22.2

Debian

redos73

RedOS 7.3

21.4

Debian

centos84

CentOS 8.4

19.4

RHEL

altserver10

ALT Server 10

22.3.4

Debian

astralinux17

Astra Linux SE 1.7 «Voronezh»

20.2

Debian

almalinux9

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 argument

The packages arguments are given in table 3.

Table 3 — The packages arguments

Name

Description

Format

Required

name

Package name

string

ivkcs_user_data resource

version

Package version

string

ivkcs_user_data resource

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.
Example of a package entry with the name mc and the version 4.8.28-alt1:p10+299225.100.2.1
name: "mc=4.8.28"version: "alt1:p10+299225.100.2.1"
Example of the `ivkcs_user_data` resource with package installation
resource "ivkcs_user_data" "user_data" {  uuid      = var.instance_uuid  hosts     = ["host1"]  target_os = "almalinux9"  packages {    name    = "mc"    version = "4.8.30"  }  packages {    name    = "tmux"    version = "3.3a"  }}

The user_script argument

The user_script arguments are given in table 4.

Table 4 — The user_script arguments

Name

Description

Format

Default value

name

Script name. Scripts are executed in alphabetical order

string

ivkcs_user_data resource

content_type

Script type. Defines when the script will be executed. Possible values:

  • text/x-shellscript-per-boot;
  • text/x-shellscript-per-instance;
  • text/x-shellscript-per-once

string

ivkcs_user_data resource

content

Script body

string

ivkcs_user_data resource

The script execution order is given in table 5.

Table 5 — Script types

Execution order

Script type

Description

1

x-shellscript-per-boot

Executed in alphabetical order every time the system boots

2

x-shellscript-per-instance

Executed in alphabetical order on the first boot of a new instance

3

x-shellscript-per-once

Executed in alphabetical order once. Not run again when the instance changes

Example of the `ivkcs_user_data` resource with `user_script`
resource "ivkcs_user_data" "init" {  uuid      = var.instance_uuid  hosts     = [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:

Was this article helpful?