### Get DB Instance Information Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/data-sources/db_instance.md This example demonstrates how to retrieve information about a database instance using its ID. ```APIDOC ## Get DB Instance Information ### Description Retrieves information about a specific database instance using its unique identifier. ### Method GET (Implicitly through data source usage) ### Endpoint Not applicable (Data source) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```terraform data "vkcs_db_instance" "db_instance" { id = "e7da2869-2ae2-4900-99e3-a44fec2b11ac" } ``` ### Response #### Success Response (200) - **id** (string) - The ID of the instance. - **backup_schedule** (object) - Configuration of PITR backup. - **interval_hours** (number) - Time interval between backups. - **keep_count** (number) - Number of backups to be stored. - **name** (string) - Name of the schedule. - **start_hours** (number) - Hours part of timestamp of initial backup. - **start_minutes** (number) - Minutes part of timestamp of initial backup. - **datastore** (object) - Datastore of the instance. - **type** (string) - Type of the datastore. - **version** (string) - Version of the datastore. - **flavor_id** (string) - The ID of flavor for the instance. - **hostname** (string) - The hostname of the instance. - **ip** (string) - IP address of the instance. - **name** (string) - The name of the instance. - **region** (string) - Region of the resource. - **status** (string) - Instance status. - **volume** (object) - Volume of the instance. - **size** (number) - Size of the instance volume. - **used** (number) - Size of the used volume space. - **volume_id** (string) - ID of the instance volume. - **volume_type** (string) - Type of the instance volume. #### Response Example (Response structure mirrors the Argument Reference, with values populated for the requested instance.) ``` -------------------------------- ### Example Usage Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/resources/dc_interface.md This example demonstrates how to create a direct connect interface to connect a network to a Direct Connect Router. ```APIDOC ## Create Direct Connect Interface ### Description Creates a direct connect interface to connect a network to a Direct Connect Router. ### Method `resource "vkcs_dc_interface"` ### Parameters #### Required - `dc_router_id` (string): Direct Connect Router ID to attach. - `network_id` (string): Network ID to attach. #### Optional - `name` (string): Name of the interface. - `description` (string): Description of the interface. - `subnet_id` (string): Subnet ID to attach. ### Request Example ```terraform resource "vkcs_dc_interface" "dc_interface" { name = "tf-example" description = "tf-example-description" dc_router_id = vkcs_dc_router.dc_router.id network_id = vkcs_networking_network.app.id subnet_id = vkcs_networking_subnet.app.id } ``` ``` -------------------------------- ### Get VKCS DB Datastore Parameters Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/data-sources/db_datastore_parameters.md This example demonstrates how to fetch configuration parameters for a MySQL datastore of a specific version. It then outputs the available parameters. ```terraform data "vkcs_db_datastore_parameters" "mysql_params" { datastore_name = data.vkcs_db_datastore.mysql datastore_version_id = local.mysql_v8_version_id } output "mysql_parameters" { value = data.vkcs_db_datastore_parameters.mysql_params.parameters description = "Available configuration parameters of the latest version of MySQL datastore." } ``` -------------------------------- ### Complete VKCS CDN Configuration Example Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/guides/cdn_getting_started.md An integrated example demonstrating the creation of a CDN resource along with its dependencies: origin group, SSL certificate, and shielding population. ```terraform resource "vkcs_cdn_origin_group" "origin_group" { name = "tfexample-origin-group" origins = [ { source = "origin1.vk.com" }, { source = "origin2.vk.com", backup = true } ] use_next = true } # Remove if not needed resource "vkcs_cdn_ssl_certificate" "certificate" { name = "tfexample-ssl-certificate" certificate = file("${path.module}/certificate.pem") private_key = file("${path.module}/private-key.key") } # Remove if not needed data "vkcs_cdn_shielding_pop" "pop" { city = "Moscow-Megafon" } resource "vkcs_cdn_resource" "resource" { cname = local.cname # Provide your own value origin_group = vkcs_cdn_origin_group.origin_group.id options = { edge_cache_settings = { value = "10m" } forward_host_header = true } # Remove if you decided not to enable shielding on the resource shielding = { enabled = true pop_id = data.vkcs_cdn_shielding_pop.pop.id } # Remove if not necessary. Check provider's documentation for # the attribute to get more information on how to provide a SSL # certificate for a CDN resource. ssl_certificate = { type = "own" id = vkcs_cdn_ssl_certificate.certificate.id } } ``` -------------------------------- ### vkcs_db_backup Resource Example Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/resources/db_backup.md Example of how to create a db backup resource. This resource manages a db backup and can be used to create and delete it. ```terraform resource "vkcs_db_backup" "mysql_backup" { name = "mssql-backup" dbms_id = vkcs_db_instance.mysql.id } ``` -------------------------------- ### Example Usage Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/data-sources/region.md The following example shows how the resource might be used to obtain the name of the VKCS region configured on the provider. ```APIDOC data "vkcs_region" "current" {} ``` -------------------------------- ### Building and Installing the VKCS Provider (macOS) Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/README.md Instructions for cloning the repository, building the provider for macOS, and installing it into the local Terraform plugin directory. This is for provider development. ```sh $ mkdir -p $GOPATH/src/github.com/vk-cs $ cd $GOPATH/src/github.com/vk-cs $ git clone git@github.com:vk-cs/terraform-provider-vkcs.git $ cd $GOPATH/src/github.com/vk-cs/terraform-provider-vkcs $ make build_darwin $ mkdir -p ~/.terraform.d/plugins/hub.mcs.mail.ru/repository/vkcs/0.1.0/darwin_amd64/ $ cp terraform-provider-vkcs_darwin ~/.terraform.d/plugins/hub.mcs.mail.ru/repository/vkcs/0.1.0/darwin_amd64/terraform-provider-vkcs_v0.1.0 ``` -------------------------------- ### Example Usage of vkcs_compute_keypair Data Source Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/data-sources/compute_keypair.md This snippet shows how to use the data source to fetch information about a keypair named 'generated-key-tf-example'. The `depends_on` is included for example purposes to ensure the keypair resource is created before attempting to read it. ```terraform data "vkcs_compute_keypair" "generated_key" { name = "generated-key-tf-example" # This is unnecessary in real life. # This is required here to let the example work with keypair resource example. depends_on = [vkcs_compute_keypair.generated_key] } ``` -------------------------------- ### Example Usage of vkcs_lb_loadbalancer Data Source Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/data-sources/lb_loadbalancer.md This example demonstrates how to use the vkcs_lb_loadbalancer data source to retrieve details of a load balancer and its associated VIP port. It also shows how to output the IP addresses of the application. ```terraform data "vkcs_lb_loadbalancer" "app" { id = vkcs_lb_loadbalancer.app.id # This is unnecessary in real life. # This is required here to let the example work with loadbalancer resource example. depends_on = [vkcs_lb_loadbalancer.app] } data "vkcs_networking_port" "app_port" { id = data.vkcs_lb_loadbalancer.app.vip_port_id } output "used_vips" { value = data.vkcs_networking_port.app_port.all_fixed_ips description = "IP addresses of the app" } ``` -------------------------------- ### Listener for HTTP Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/resources/lb_listener.md Example of creating an HTTP listener for a load balancer. ```APIDOC ## vkcs_lb_listener Manages a listener resource within VKCS. ### Argument Reference - `loadbalancer_id` **required** *string* → The load balancer on which to provision this Listener. Changing this creates a new Listener. - `protocol` **required** *string* → The protocol - can either be TCP, HTTP, HTTPS, TERMINATED_HTTPS, UDP. Changing this creates a new Listener. - `protocol_port` **required** *number* → The port on which to listen for client traffic. Changing this creates a new Listener. - `admin_state_up` optional *boolean* → The administrative state of the Listener. A valid value is true (UP) or false (DOWN). - `allowed_cidrs` optional *set of* *string* → A list of CIDR blocks that are permitted to connect to this listener, denying all other source addresses. If not present, defaults to allow all. - `connection_limit` optional *number* → The maximum number of connections allowed for the Listener. - `default_pool_id` optional *string* → The ID of the default pool with which the Listener is associated. - `default_tls_container_ref` optional *string* → A reference to a Keymanager Secrets container which stores TLS information. This is required if the protocol is `TERMINATED_HTTPS`. - `description` optional *string* → Human-readable description for the Listener. - `insert_headers` optional *map of* *string* → The list of key value pairs representing headers to insert into the request before it is sent to the backend members. Changing this updates the headers of the existing listener. - `name` optional *string* → Human-readable name for the Listener. Does not have to be unique. - `region` optional *string* → The region in which to obtain the Loadbalancer client. If omitted, the `region` argument of the provider is used. Changing this creates a new Listener. - `sni_container_refs` optional *string* → A list of references to Keymanager Secrets containers which store SNI information. - `timeout_client_data` optional *number* → The client inactivity timeout in milliseconds. - `timeout_member_connect` optional *number* → The member connection timeout in milliseconds. - `timeout_member_data` optional *number* → The member inactivity timeout in milliseconds. - `timeout_tcp_inspect` optional *number* → The time in milliseconds, to wait for additional TCP packets for content inspection. ### Attributes Reference In addition to all arguments above, the following attributes are exported: - `id` *string* → ID of the resource. ### Import Load Balancer Listener can be imported using the Listener ID, e.g.: ```shell terraform import vkcs_lb_listener.listener_1 b67ce64e-8b26-405d-afeb-4a078901f15a ``` ``` -------------------------------- ### Get vkcs_iam_service_user Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/data-sources/iam_service_user.md Example of how to retrieve information about an IAM service user using its name. ```terraform data "vkcs_iam_service_user" "service_user" { name = vkcs_iam_service_user.service_user.name } ``` -------------------------------- ### Import ML Platform MLFlow Deploy Instance Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/resources/mlplatform_mlflow_deploy.md Example of how to import an existing ML Platform MLFlow Deploy instance using its ID. ```shell terraform import vkcs_mlplatform_mlflow_deploy.mymlflowdeploy 0cade671-81b5-43c5-83e1-2a659378d53a ``` -------------------------------- ### Get VKCS Port Information Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/data-sources/networking_port.md Use this data source to get the ID of an available VKCS port. It filters ports by tags and network ID. The `depends_on` is a workaround for example purposes. ```terraform data "vkcs_networking_port" "persistent_etcd" { tags = ["tf-example", "etcd"] network_id = vkcs_networking_network.db.id # This is unnecessary in real life. # This is required here to let the example work with port resource example. depends_on = [vkcs_networking_port.persistent_etcd] } ``` -------------------------------- ### Get public Debian images Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/data-sources/images_images.md Use this data source to get information on VKCS images. This example filters for public images that are set as default and have the 'debian' OS distribution property. ```terraform data "vkcs_images_images" "images" { visibility = "public" default = true properties = { mcs_os_distro = "debian" } } ``` -------------------------------- ### Create an ML Platform MLFlow instance Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/resources/mlplatform_mlflow.md This example demonstrates how to create a ML Platform MLFlow instance with specified configurations for flavor, JupyterHub integration, boot volume, data volumes, and networking. ```terraform resource "vkcs_mlplatform_mlflow" "mlflow" { name = "tf-example" flavor_id = data.vkcs_compute_flavor.basic.id jh_instance_id = vkcs_mlplatform_jupyterhub.jupyterhub.id demo_mode = true availability_zone = "GZ1" boot_volume = { size = 50 volume_type = "ceph-ssd" } data_volumes = [ { size = 60 volume_type = "ceph-ssd" }, ] networks = [ { network_id = vkcs_networking_network.app.id }, ] } ``` -------------------------------- ### Get vkcs_networking_router data source Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/data-sources/networking_router.md Use this data source to get the ID of an available VKCS router. It can be filtered by name and tags. The `depends_on` argument is included for example purposes and is not typically needed. ```terraform data "vkcs_networking_router" "router" { name = "router-tf-example" tags = ["tf-example"] # This is unnecessary in real life. # This is required here to let the example work with router resource example. depends_on = [vkcs_networking_router.router] } ``` -------------------------------- ### ML Platform MLFlow Deploy Instance Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/resources/mlplatform_mlflow_deploy.md Example of how to create an ML Platform MLFlow Deploy instance with specified configurations for boot volume, data volumes, and network. ```terraform resource "vkcs_mlplatform_mlflow_deploy" "deploy" { name = "tf-example" flavor_id = data.vkcs_compute_flavor.basic.id mlflow_instance_id = vkcs_mlplatform_mlflow.mlflow.id availability_zone = "GZ1" boot_volume = { size = 50 volume_type = "ceph-ssd" } data_volumes = [ { size = 60 volume_type = "ceph-ssd" }, ] networks = [ { network_id = vkcs_networking_network.app.id }, ] } ``` -------------------------------- ### Compute Instance Creation with Password Data Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/resources/compute_instance.md This example demonstrates how to create a Windows compute instance and retrieve its administrative password. The `get_password_data` option must be enabled in `vendor_options` to generate the password. ```APIDOC ## POST /compute/instances ### Description Creates a new compute instance. This endpoint supports generating an administrative password for Windows instances if a key pair is specified. ### Method POST ### Endpoint /compute/instances ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **name** (string) - Required - A unique name for the resource. - **availability_zone** (string) - Optional - The availability zone in which to create the server. - **key_pair** (string) - Required - The name of the key pair to associate with the instance for password generation. - **block_device** (object) - Optional - Configuration of block devices for the instance. - **source_type** (string) - Required - The source type of the device (e.g., "image", "volume"). - **uuid** (string) - Required - The UUID of the image, volume, or snapshot. - **destination_type** (string) - Optional - The type that gets created (e.g., "volume", "local"). - **volume_size** (number) - Optional - The size of the volume in GB. - **volume_type** (string) - Optional - The type of the volume (e.g., "high-iops-ha"). - **delete_on_termination** (boolean) - Optional - Whether to delete the volume upon instance termination. - **network** (object) - Required - Network configuration for the instance. - **uuid** (string) - Required - The UUID of the network to attach the instance to. - **security_group_ids** (array) - Required - A list of security group IDs to associate with the instance. - **vendor_options** (object) - Optional - Vendor-specific options. - **get_password_data** (boolean) - Optional - Set to `true` to enable administrative password generation for Windows instances. ### Request Example ```json { "name": "windows-password-tf-example", "availability_zone": "ME1", "key_pair": "generated-key-tf-example", "block_device": { "source_type": "image", "uuid": "", "destination_type": "volume", "volume_size": 50, "volume_type": "high-iops-ha", "delete_on_termination": true }, "network": { "uuid": "" }, "security_group_ids": [""], "vendor_options": { "get_password_data": true } } ``` ### Response #### Success Response (200) - **password_data** (string) - The generated administrative password for the instance (sensitive). #### Response Example ```json { "password_data": "" } ``` ``` -------------------------------- ### Get a user-defined image Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/data-sources/images_image.md Use this snippet to find a user-defined image, filtering by a specific tag and ensuring you get the most recent version. The `depends_on` argument is included for example purposes and may not be necessary in real-world scenarios. ```terraform data "vkcs_images_image" "eurolinux9" { tag = "tf-example" # Useful if you keep old versions of your images. most_recent = true properties = { mcs_os_distro = "eurolinux" mcs_os_version = "9" } # This is unnecessary in real life. # This is required here to let the example work with image resource example. depends_on = [vkcs_images_image.eurolinux9] } ``` -------------------------------- ### Get Availability Zones Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/data-sources/compute_availability_zones.md Fetch a list of all available availability zones and output their names. This is a basic usage example. ```terraform data "vkcs_compute_availability_zones" "zones" {} output "available_zones" { value = data.vkcs_compute_availability_zones.zones.names } ``` -------------------------------- ### Get Key Manager Container Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/data-sources/keymanager_container.md Use this data source to get the ID of an available Key container. Specify the container's name to retrieve its details. The `depends_on` block is included for example purposes and may not be necessary in real-world scenarios. ```terraform data "vkcs_keymanager_container" "lb_cert" { name = "container-tf-example" # This is unnecessary in real life. # This is required here to let the example work with container resource example. depends_on = [vkcs_keymanager_container.lb_cert] } ``` -------------------------------- ### Example Usage of vkcs_vpnaas_ike_policy Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/resources/vpnaas_ike_policy.md This snippet shows how to create a basic IKE policy with a specified name, description, and authentication algorithm. ```terraform resource "vkcs_vpnaas_ike_policy" "data_center" { name = "key-policy-tf-example" description = "Policy that restricts remote working users to connect to our data ceneter over VPN" auth_algorithm = "sha256" } ``` -------------------------------- ### Example Usage of vkcs_kubernetes_node_group Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/data-sources/kubernetes_node_group.md Use this data source to get information on a VKCS Kubernetes cluster's node group by its ID. ```terraform data "vkcs_kubernetes_node_group" "k8s_node_group" { id = vkcs_kubernetes_node_group.default_ng.id } ``` -------------------------------- ### Get Shared File System Share Data Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/data-sources/sharedfilesystem_share.md Use this data source to get the ID of an available Shared File System share. It requires the share name and the share network ID. A dependency on the share resource is included for example completeness. ```terraform data "vkcs_sharedfilesystem_share" "data" { name = "share-data-tf-example" share_network_id = vkcs_sharedfilesystem_sharenetwork.data.id # This is unnecessary in real life. # This is required here to let the example work with share resource example. depends_on = [vkcs_sharedfilesystem_share.data] } ``` -------------------------------- ### Get Kubernetes Cluster Template by Version Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/data-sources/kubernetes_clustertemplate.md Example of how to use the `vkcs_kubernetes_clustertemplate` data source to retrieve a cluster template based on its Kubernetes version. ```APIDOC ## Get Kubernetes Cluster Template by Version Use this data source to get the ID of an available VKCS kubernetes cluster template. ### Usage ```terraform data "vkcs_kubernetes_clustertemplate" "k8s_31" { version = "1.31" } ``` ### Arguments - `id` (Optional, String) - The UUID of the cluster template. Note: Only one of `name`, `version`, or `id` must be specified. - `name` (Optional, String) - The name of the cluster template. Note: Only one of `name`, `version`, or `id` must be specified. - `version` (Optional, String) - Kubernetes version. Specify only major and minor versions (i.e. 1.32), patch versions are not used in cluster templates. Note: Only one of `name`, `version`, or `id` must be specified. - `region` (Optional, String) - The region in which to obtain the V1 Container Infra client. If omitted, the `region` argument of the provider is used. ### Attributes - `apiserver_port` (Number) - The API server port for the Container Orchestration Engine for this cluster template. - `cluster_distro` (String) - The distro for the cluster (fedora-atomic, coreos, etc.). - `created_at` (String) - The time at which cluster template was created. - `deprecated_at` (String) - The time at which the cluster template is deprecated. - `dns_nameserver` (String) - Address of the DNS nameserver that is used in nodes of the cluster. - `docker_storage_driver` (String) - Docker storage driver. - `docker_volume_size` (Number) - The size (in GB) of the Docker volume. - `external_network_id` (String) - The ID of the external network that will be used for the cluster. - `flavor` (String) - The ID of flavor for the nodes of the cluster. - `floating_ip_enabled` (Boolean) - Indicates whether created cluster should create IP floating IP for every node or not. - `image` (String) - The reference to an image that is used for nodes of the cluster. - `insecure_registry` (String) - The insecure registry URL for the cluster template. - `keypair_id` (String) - The name of the Compute service SSH keypair. - `labels` (Map of String) - The list of key value pairs representing additional properties of the cluster template. - `master_flavor` (String) - The ID of flavor for the master nodes. - `master_lb_enabled` (Boolean) - Indicates whether created cluster should has a loadbalancer for master nodes or not. - `network_driver` (String) - The name of the driver for the container network. - `no_proxy` (String) - A comma-separated list of IP addresses that shouldn't be used in the cluster. - `project_id` (String) - The project of the cluster template. - `public` (Boolean) - Indicates whether cluster template should be public. - `registry_enabled` (Boolean) - Indicates whether Docker registry is enabled in the cluster. - `server_type` (String) - The server type for the cluster template. - `tls_disabled` (Boolean) - Indicates whether the TLS should be disabled in the cluster. - `updated_at` (String) - The time at which cluster template was updated. - `user_id` (String) - The user of the cluster template. - `volume_driver` (String) - The name of the driver that is used for the volumes of the cluster nodes. ``` -------------------------------- ### Get vkcs_db_instance by ID Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/data-sources/db_instance.md This example shows how to retrieve a database instance using its unique ID. Ensure the ID is correct for the instance you wish to query. ```terraform data "vkcs_db_instance" "db_instance" { id = "e7da2869-2ae2-4900-99e3-a44fec2b11ac" } ``` -------------------------------- ### Get vkcs_blockstorage_volume data source Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/data-sources/blockstorage_volume.md Use this data source to query for an existing volume by its name. The `depends_on` is included for example purposes to ensure a volume resource is available. ```terraform data "vkcs_blockstorage_volume" "data" { name = "data-tf-example" # This is unnecessary in real life. # This is required here to let the example work with volume resource example. depends_on = [vkcs_blockstorage_volume.data] } ``` -------------------------------- ### Get VKCS Subnet by CIDR and Network ID Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/data-sources/networking_subnet.md Use this data source to obtain the ID of a VKCS subnet. It requires the subnet's CIDR and the ID of the network it belongs to. The `depends_on` argument is included for example purposes to ensure the subnet resource is created before this data source is evaluated. ```terraform data "vkcs_networking_subnet" "subnet_one_of_internal" { cidr = "192.168.199.0/24" network_id = vkcs_networking_network.app.id # This is unnecessary in real life. # This is required here to let the example work with subnet resource example. depends_on = [vkcs_networking_subnet.app] } ``` -------------------------------- ### Create an Image resource Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/resources/images_image.md This example demonstrates how to create an image resource using vkcs_images_image. It includes specifying the image name, source URL, compression format, container and disk formats, minimum RAM and disk requirements, custom properties, and tags. ```terraform resource "vkcs_images_image" "eurolinux9" { name = "eurolinux9-tf-example" image_source_url = "https://fbi.cdn.euro-linux.com/images/EL-9-cloudgeneric-2023-03-19.raw.xz" # compression_format should be set for compressed image source. compression_format = "xz" container_format = "bare" disk_format = "raw" # Minimal requirements from image vendor. # Should be set to prevent VKCS to build VM on lesser resources. min_ram_mb = 1536 min_disk_gb = 10 properties = { # Refer to https://mcs.mail.ru/docs/en/base/iaas/instructions/vm-images/vm-image-metadata os_type = "linux" os_admin_user = "root" mcs_name = "EuroLinux 9" mcs_os_distro = "eurolinux" mcs_os_version = "9" hw_qemu_guest_agent = "yes" os_require_quiesce = "yes" } # Use tags to organize your images. tags = ["tf-example"] } ``` -------------------------------- ### vkcs_networking_secgroup Data Source Example Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/data-sources/networking_secgroup.md This example demonstrates how to use the vkcs_networking_secgroup data source to find a security group by its name. It includes a `depends_on` argument for example purposes. ```terraform data "vkcs_networking_secgroup" "etcd" { name = "etcd-tf-example" # This is unnecessary in real life. # This is required here to let the example work with secgroup resource example. depends_on = [vkcs_networking_secgroup.etcd] } ``` -------------------------------- ### Incremental backup for compute instance Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/resources/backup_plan.md Example of creating an incremental backup plan for a compute instance, with a schedule for full backups on Mondays and incremental backups on other days. ```APIDOC ## vkcs_backup_plan Manages a backup plan resource. ### Description Manages a backup plan resource within VKCS. ### Argument Reference - `incremental_backup` **required** *boolean* → Whether incremental backups strategy should be used. If enabled, the schedule.date field must specify one day, on which full backup will be created. On other days, incremental backups will be created. Note: This option may be enabled for only for 'cloud_servers' provider. - `name` **required** *string* → Name of the backup plan - `schedule` ***required*** - `date` optional *string* → List of days when to perform backups. If incremental_backups is enabled, only one day should be specified - `time` optional *string* → Time of backup in format hh:mm (for UTC timezone) or hh:mm+tz (for other timezones, e.g. 10:00+03 for MSK, 10:00-04 for ET) - `full_retention` optional → Parameters for full retention policy. Specifies number of full backups stored. Incremental backups (if enabled) are not counted as full. Incompatible with gfs_retention - `max_full_backup` **required** *number* → Maximum number of backups - `instance_ids` optional *set of* *string* → Set of ids of instances to make backup for. Either backup_targets or instance_ids must be specified, but not both. - `provider_name` optional *string* → Name of backup provider, must be one of: cloud_servers, dbaas ### Request Example ```terraform resource "vkcs_backup_plan" "backup_plan" { name = "backup-plan-tf-example" provider_name = "cloud_servers" incremental_backup = true # Create full backup every Monday at 04:00 MSK # Incremental backups are created each other day at the same time schedule = { date = ["Mo"] time = "04:00+03" } full_retention = { max_full_backup = 25 } instance_ids = [vkcs_compute_instance.basic.id] } ``` ``` -------------------------------- ### Import a block storage snapshot Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/resources/blockstorage_snapshot.md Example of importing an existing block storage snapshot using its ID. ```shell terraform import vkcs_blockstorage_snapshot.myvolumesnapshot 0b4f5a9b-554e-4e80-b553-82aba6502315 ``` -------------------------------- ### Get vkcs_cdn_shielding_pop Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/data-sources/cdn_shielding_pop.md Use the data source to get information about a specific CDN shielding POP by its city. ```terraform data "vkcs_cdn_shielding_pop" "pop" { city = "Moscow-Megafon" } ``` -------------------------------- ### Basic Usage of vkcs_keymanager_secret Data Source Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/data-sources/keymanager_secret.md This example demonstrates how to fetch a secret of type 'certificate'. The `depends_on` is included solely to make this example functional within the context of a secret resource example, and is not typically needed in real-world scenarios. ```terraform data "vkcs_keymanager_secret" "certificate" { secret_type = "certificate" # This is unnecessary in real life. # This is required here to let the example work with secret resource example. depends_on = [vkcs_keymanager_secret.certificate] } ``` -------------------------------- ### Import a Direct Connect IP Port Forwarding Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/resources/dc_ip_port_forwarding.md Example of importing an existing direct connect IP port forwarding resource using its ID. ```shell terraform import vkcs_dc_ip_port_forwarding.mydcipportforwarding 659be09e-a10e-4762-b729-7a003af40f29 ``` -------------------------------- ### Create a VPN Service Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/resources/vpnaas_service.md Example of creating a VPN service, specifying the name and router ID. It includes a note about choosing the correct router ID based on the SDN type. ```terraform resource "vkcs_vpnaas_service" "vpn_to_datacenter" { name = "vpn-tf-example" # See the argument description and check vkcs_networks_sdn datasource output to figure out # what type of router you should use in certain case (vkcs_networking_router or vkcs_dc_router) router_id = vkcs_dc_router.router.id depends_on = [vkcs_dc_interface.internet_sprut] } ``` -------------------------------- ### Get backup providers Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/data-sources/backup_providers.md Use this data source to get backup providers info. The region can be optionally specified. ```terraform data "vkcs_backup_providers" "providers" {} ``` -------------------------------- ### Backup for db instance Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/resources/backup_plan.md Example of creating a backup plan for a database instance, specifying an hourly backup schedule and full retention policy. Note that incremental backups are not supported for DBaaS. ```APIDOC ## vkcs_backup_plan Manages a backup plan resource. ### Description Manages a backup plan resource within VKCS. ### Argument Reference - `incremental_backup` **required** *boolean* → Whether incremental backups strategy should be used. If enabled, the schedule.date field must specify one day, on which full backup will be created. On other days, incremental backups will be created. Note: This option may be enabled for only for 'cloud_servers' provider. - `name` **required** *string* → Name of the backup plan - `schedule` ***required*** - `every_hours` optional *number* → Hour interval of backups, must be one of: 3, 12, 24. This field is incompatible with date/time fields - `full_retention` optional → Parameters for full retention policy. Specifies number of full backups stored. Incremental backups (if enabled) are not counted as full. Incompatible with gfs_retention - `max_full_backup` **required** *number* → Maximum number of backups - `instance_ids` optional *set of* *string* → Set of ids of instances to make backup for. Either backup_targets or instance_ids must be specified, but not both. - `provider_name` optional *string* → Name of backup provider, must be one of: cloud_servers, dbaas ### Request Example ```terraform resource "vkcs_backup_plan" "backup_plan" { name = "backup-plan-tf-example" provider_name = "dbaas" # Must be false since DBaaS does not support incremental backups incremental_backup = false # Backup database data every 12 hours since the next hour after the plan creation schedule = { every_hours = 12 } full_retention = { max_full_backup = 25 } instance_ids = [vkcs_db_instance.mysql.id] } ``` ``` -------------------------------- ### Import a Router Interface Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/resources/networking_router_interface.md Demonstrates how to import an existing router interface using its port ID. First, list ports associated with the router to find the correct port ID. ```shell openstack port list --router terraform import vkcs_networking_router_interface.int_1 ``` -------------------------------- ### Create a ClickHouse Data Platform Cluster Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/resources/dataplatform_cluster.md Example of creating a ClickHouse cluster. It demonstrates setting up network interfaces, pod groups with specific resource requests and volumes, and detailed configurations for settings, users, warehouses, and maintenance/backup schedules. Note the dependency on networking resources and the beta status of the resource. ```terraform resource "vkcs_dataplatform_cluster" "clickhouse" { name = "clickhouse-tf-guide" description = "ClickHouse example instance from Data Platform guide." product_name = "clickhouse" product_version = "25.3.0" network_id = vkcs_networking_network.db.id subnet_id = vkcs_networking_subnet.db.id availability_zone = "GZ1" # Enable public access to simplify testing of the product. floating_ip_pool = "auto" pod_groups = [ # Omit settings for clickhouseKeeper pod group to illustrate # how Data Platform handle this with default settings. # NOTE: If you omit settings for a pod group you cannot scale # the pod group later. # Increase ram_request and storage values for clickhouse pod group # against default settings. { count = 3 name = "clickhouse" resource = { cpu_request = "2.0" ram_request = "8.0" } volumes = { data = { storage_class_name = "ceph-ssd" storage = "150" count = 1 } } }, ] configs = { settings = [ # Increase value of the setting against default one. { alias = "clickhouse.background_common_pool_size" value = 10 }, ] users = [ { username = "owner" password = random_password.clickhouse_owner.result role = "dbOwner" }, { username = "trino" password = random_password.clickhouse_trino.result role = "readOnly" }, ] warehouses = [ # Define database name. { name = "clickhouse" }, ] maintenance = { # Set start om maintenance the same as start of full backup. # Otherwise you get unpredictable behavior of interaction between # Terraform, VKCS Terraform provider and Data Platform API. start = "0 1 * * 0" backup = { full = { keep_count = 5 start = "0 1 * * 0" } incremental = { keep_count = 7 start = "0 1 * * 1-6" } } } } # If you create networking in the same bundle of resources with Data Platform resource # add dependency on corresponding vkcs_networking_router_interface resource. # However this is not required if you set up networking witth terraform-vkcs-network module. depends_on = [vkcs_networking_router_interface.db] } ``` -------------------------------- ### Simple floating IP allocation Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/resources/networking_floatingip.md This example demonstrates how to allocate a simple floating IP from a specified pool. ```APIDOC ## Simple floating IP allocation ### Description Allocates a floating IP from a specified pool. ### Resource `vkcs_networking_floatingip` ### Arguments * `pool` (string, required) - The name of the pool from which to obtain the floating IP. * `description` (string, optional) - Human-readable description for the floating IP. ### Example ```terraform resource "vkcs_networking_floatingip" "base_fip" { pool = "internet" description = "floating ip in external net tf example" } ``` ``` -------------------------------- ### Get vkcs_blockstorage_snapshot data Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/data-sources/blockstorage_snapshot.md Use this data source to get information about an existing snapshot. It can filter by name and select the most recent snapshot. ```terraform data "vkcs_blockstorage_snapshot" "recent_snapshot" { name = "snapshot-tf-example" most_recent = true # This is unnecessary in real life. # This is required here to let the example work with snapshot resource example. depends_on = [vkcs_blockstorage_snapshot.recent_snapshot] } ``` -------------------------------- ### vkcs_lb_loadbalancer Data Source Example Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/data-sources/lb_loadbalancer.md Example usage of the vkcs_lb_loadbalancer data source to retrieve load balancer details and associated port information. ```APIDOC ## vkcs_lb_loadbalancer Data Source Use this data source to get the details of a loadbalancer ### Example Usage ```terraform data "vkcs_lb_loadbalancer" "app" { id = vkcs_lb_loadbalancer.app.id # This is unnecessary in real life. # This is required here to let the example work with loadbalancer resource example. depends_on = [vkcs_lb_loadbalancer.app] } data "vkcs_networking_port" "app_port" { id = data.vkcs_lb_loadbalancer.app.vip_port_id } output "used_vips" { value = data.vkcs_networking_port.app_port.all_fixed_ips description = "IP addresses of the app" } ``` ## Argument Reference - `id` **required** *string* → The UUID of the Loadbalancer - `region` optional *string* → The region in which to obtain the Loadbalancer client. If omitted, the `region` argument of the provider is used. ## Attributes Reference In addition to all arguments above, the following attributes are exported: - `admin_state_up` *boolean* → The administrative state of the Loadbalancer. - `availability_zone` *string* → The availability zone of the Loadbalancer. - `description` *string* → Human-readable description of the Loadbalancer. - `name` *string* → The name of the Loadbalancer. - `security_group_ids` *set of* *string* → A list of security group IDs applied to the Loadbalancer. - `tags` *set of* *string* → A list of simple strings assigned to the loadbalancer. - `vip_address` *string* → The ip address of the Loadbalancer. - `vip_network_id` *string* → The network on which to allocate the Loadbalancer's address. A tenant can only create Loadbalancers on networks authorized by policy (e.g. networks that belong to them or networks that are shared). Changing this creates a new loadbalancer. - `vip_port_id` *string* → The port UUID of the Loadbalancer. - `vip_subnet_id` *string* → The subnet on which the Loadbalancer's address is allocated. ``` -------------------------------- ### Initializing Terraform with Local Provider Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/README.md Command to initialize Terraform after setting up the provider configuration. This downloads provider plugins and initializes the backend. ```sh $ terraform init ``` -------------------------------- ### vkcs_networking_floatingip Data Source Example Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/data-sources/networking_floatingip.md Example usage of the vkcs_networking_floatingip data source to fetch a floating IP based on its associated port ID. ```APIDOC ## vkcs_networking_floatingip Use this data source to get the ID of an available VKCS floating IP. ### Example Usage ```terraform data "vkcs_networking_floatingip" "fip_by_port" { port_id = vkcs_networking_port.persistent_etcd.id # This is unnecessary in real life. # This is required here to let the example work with floating ip resource example. depends_on = [vkcs_networking_floatingip.associated_fip] } ``` ## Argument Reference - `address` optional *string* → The IP address of the floating IP. - `description` optional *string* → Human-readable description of the floating IP. - `fixed_ip` optional *string* → The specific IP address of the internal port which should be associated with the floating IP. - `pool` optional *string* → The name of the pool from which the floating IP belongs to. - `port_id` optional *string* → The ID of the port the floating IP is attached. - `region` optional *string* → The region in which to obtain the Network client. A Network client is needed to retrieve floating IP ids. If omitted, the `region` argument of the provider is used. - `sdn` optional *string* → SDN to use for this resource. Must be one of following: "neutron", "sprut". Default value is project's default SDN. - `status` optional *string* → Status of the floating IP (ACTIVE/DOWN). - `tenant_id` optional *string* → The owner of the floating IP. ## Attributes Reference In addition to all arguments above, the following attributes are exported: - `id` *string* → ID of the found floating IP. ``` -------------------------------- ### Get vkcs_db_backup Information Source: https://github.com/vk-cs/terraform-provider-vkcs/blob/master/docs/data-sources/db_backup.md Use this data source to get the information on a db backup resource. Specify the backup ID to retrieve its details. ```terraform data "vkcs_db_backup" "db_backup" { id = "d27fbf1a-373a-479c-b951-31041756f289" } ```