- Compute Instance: Create a Yandex.Cloud compute instance with customizable resources.
- Disks: Attach multiple disks, including boot and secondary disks, with custom settings.
- Network Interfaces: Configure multiple network interfaces with options for NAT, static IP, and DNS records.
- Static IP: Optionally assign a static IP to the instance.
- Filesystem: Attach a Yandex.Cloud Filesystem to the instance.
- Monitoring and Backup: Enable monitoring and backup services using Yandex.Cloud's predefined scripts.
module "compute_instance" {
source = "./path-to-your-module"
image_family = "image"
zone = "ru-central1-a"
name = "name"
hostname = "hostname"
description = "description"
memory = 4
gpus = 0
cores = 2
core_fraction = 100
serial_port_enable = true
allow_stopping_for_update = true
monitoring = true
backup = false
boot_disk = {
size = 30
block_size = 4096
type = "network-ssd"
image_id = null
snapshot_id = null
}
secondary_disks = [
{
disk_id = null
auto_delete = true
device_name = "secondary-disk"
mode = "READ_WRITE"
size = 100
block_size = 4096
type = "network-hdd"
}
]
filesystems = [
{
filesystem_id = null
mode = "READ_WRITE"
zone = "ru-central1-a"
}
]
# Authentication - either use OS Login
enable_oslogin_or_ssh_keys = {
enable-oslogin = "true"
}
# Or use SSH keys
# enable_oslogin_or_ssh_keys = {
# ssh_user = "username"
# ssh_key = "~/.ssh/id_rsa.pub"
# }
network_interfaces = [
{
subnet_id = yandex_vpc_subnet.sub_a.id
ipv4 = true
nat = true
},
{
subnet_id = yandex_vpc_subnet.sub_a.id
ipv4 = true
nat = false
dns_record = []
}
]
static_ip = {
name = "my-static-ip"
description = "Static IP for dev instance"
external_ipv4_address = {
zone_id = "ru-central1-a"
}
}
}
-
Install YC CLI
-
Add environment variables for Terraform authentication in Yandex.Cloud
export YC_TOKEN=$(yc iam create-token) export YC_CLOUD_ID=$(yc config get cloud-id) export YC_FOLDER_ID=$(yc config get folder-id)
Name | Version |
---|---|
terraform | >= 1.3.0 |
local | >= 2.0 |
null | >= 3.0 |
random | > 3.3 |
yandex | = 0.136.0 |
Name | Version |
---|---|
random | 3.7.1 |
yandex | 0.136.0 |
No modules.
Name | Type |
---|---|
random_string.unique_id | resource |
yandex_backup_policy_bindings.this | resource |
yandex_backup_policy_bindings.this_backup_binding | resource |
yandex_compute_disk.secondary | resource |
yandex_compute_disk.this | resource |
yandex_compute_filesystem.this | resource |
yandex_compute_instance.this | resource |
yandex_iam_service_account.sa_instance | resource |
yandex_resourcemanager_folder_iam_member.sa_backup | resource |
yandex_resourcemanager_folder_iam_member.sa_monitoring | resource |
yandex_vpc_address.static_ip | resource |
yandex_backup_policy.this_backup_policy | data source |
yandex_client_config.client | data source |
yandex_compute_image.image | data source |
Name | Description | Type | Default | Required |
---|---|---|---|---|
allow_stopping_for_update | If true, allows Terraform to stop the instance in order to update its properties. If you try to update a property that requires stopping the instance without setting this field, the update will fail. | bool |
false |
no |
backup | Enable Yandex Cloud backup for the instance. If enabled and service_account_id is not provided, a new service account with backup.editor role will be created. Use backup_policy_id to specify backup policy OR backup_frequency to specify backup frequency from default policies. |
bool |
false |
no |
backup_frequency | Timing of backups. Available options: 'Default daily', 'Default weekly', 'Default monthly'. | string |
"Default daily" |
no |
backup_policy_id | ID of the backup policy to use for creating the backup. If not specified, the default backup frequency will be used. | string |
null |
no |
boot_disk | Configuration for the boot disk. If not specified, a disk will be created with default parameters. | object({ |
{} |
no |
core_fraction | CPU core fraction | number |
100 |
no |
cores | Number of CPU cores | number |
2 |
no |
custom_metadata | Adding custom metadata to node-groups. Example: custom_metadata = { |
map(any) |
{} |
no |
description | Description of the instance. | string |
"" |
no |
disk_placement_group_id | Disk placement policy configuration. Used when disk type is network-ssd-nonreplicated. | string |
null |
no |
enable_oslogin_or_ssh_keys | Authentication configuration for the instance. You can either: 1. Enable OS Login by setting enable-oslogin = "true" 2. Provide SSH keys by setting ssh_user and ssh_key Example for OS Login: enable_oslogin_or_ssh_keys = {Example for SSH keys: enable_oslogin_or_ssh_keys = { |
object({ |
{} |
no |
filesystems | List of filesystems that are attached to the instance. | list(object({ |
[] |
no |
folder_id | The ID of the folder that the resource belongs to. If it is not provided, the default provider folder is used. | string |
null |
no |
gpu_cluster_id | ID of the GPU cluster to attach this instance to. The GPU cluster must exist in the same zone as the instance. | string |
"" |
no |
gpus | Number of GPUs. Use variable 'platform_id' with GPUs support. Actual available options: https://yandex.cloud/ru/docs/compute/concepts/vm-platforms#gpu-platforms. | number |
0 |
no |
hostname | Host name for the instance. This field is used to generate the instance fqdn value. The host name must be unique within the network and region. If not specified, the host name will be equal to id of the instance and fqdn will be .auto.internal. Otherwise FQDN will be .<region_id>.internal. | string |
"" |
no |
image_family | The source image family to use for disk creation. command: yc compute image list --folder-id standard-images | string |
null |
no |
labels | A set of key/value label pairs to assign to the instance. | map(string) |
{} |
no |
maintenance_grace_period | Time between notification via metadata service and maintenance. E.g., 60s. | string |
"" |
no |
maintenance_policy | Behaviour on maintenance events. The default is unspecified. Values: unspecified, migrate, restart. | string |
"unspecified" |
no |
memory | Memory size | number |
4 |
no |
monitoring | Enable Yandex Cloud monitoring agent on the instance. If enabled and service_account_id is not provided, a new service account with monitoring.editor role will be created. Note: The UI won't show the 'Monitoring enabled' checkbox, but monitoring will work. |
bool |
false |
no |
name | Resource name. Required parameter. | string |
n/a | yes |
network_acceleration_type | Type of network acceleration. The default is standard. Values: standard, software_accelerated. | string |
"standard" |
no |
network_interfaces | List of network interfaces for the instance. At least one network interface must be specified. Example with NAT: network_interfaces = [Example with multiple interfaces: network_interfaces = [ |
list(object({ |
[] |
no |
placement_policy | Placement policy configuration for the instance. Controls how the instance is placed within dedicated host groups. Example: placement_policy = { |
object({ |
{} |
no |
platform_id | The type of compute platform. Actual available options: https://yandex.cloud/ru/docs/compute/concepts/vm-platforms. | string |
"standard-v3" |
no |
scheduling_policy_preemptible | Specifies if the instance is preemptible. Defaults to false. | bool |
false |
no |
secondary_disks | List of secondary disks | list(object({ |
[] |
no |
serial_port_enable | Enable serial port | bool |
false |
no |
service_account_id | Optional service account ID | string |
null |
no |
static_ip | Configuration for static IP address | object({ |
null |
no |
zone | The availability zone where the virtual machine will be created. If it is not provided, the default provider zone is used. | string |
n/a | yes |
Name | Description |
---|---|
boot_disk_id | The ID of the boot disk |
external_ip | The external IP address of the instance |
filesystem_ids | The list of filesystem IDs |
fqdn | The fully qualified DNS name of this instance |
instance_id | The ID of the instance |
internal_ip | The internal IP address of the instance |
secondary_disk_ids | The list of secondary disk IDs |