Skip to content

terraform-yc-modules/terraform-yc-compute-instance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Compute Instance Terraform Module for Yandex.Cloud

Features

  • 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.

Usage

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"
    }
  }
}

How to Configure Terraform for Yandex.Cloud

  1. Install YC CLI

  2. 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)

Requirements

Name Version
terraform >= 1.3.0
local >= 2.0
null >= 3.0
random > 3.3
yandex = 0.136.0

Providers

Name Version
random 3.7.1
yandex 0.136.0

Modules

No modules.

Resources

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

Inputs

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({
auto_delete = optional(bool, true)
device_name = optional(string, "boot-disk")
mode = optional(string, "READ_WRITE")
disk_id = optional(string, null)
size = optional(number, 30)
block_size = optional(number, 4096)
type = optional(string, "network-ssd")
image_id = optional(string, null)
snapshot_id = optional(string, null)
kms_key_id = optional(string, null)
})
{} 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 = {
foo = "bar"
}
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 = {
enable-oslogin = "true"
}
Example for SSH keys:
enable_oslogin_or_ssh_keys = {
ssh_user = "username"
ssh_key = "~/.ssh/id_rsa.pub"
}
object({
enable-oslogin = optional(string, "false")
ssh_user = optional(string)
ssh_key = optional(string)
})
{} no
filesystems List of filesystems that are attached to the instance.
list(object({
filesystem_id = optional(string, null)
device_name = optional(string, null)
mode = optional(string, "READ_WRITE")
description = optional(string, null)
zone = optional(string, null)
size = optional(number, 10)
block_size = optional(number, 4096)
type = optional(string, "network-ssd")
}))
[] 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 = [
{
subnet_id = "your-subnet-id"
nat = true
}
]
Example with multiple interfaces:
network_interfaces = [
{
subnet_id = "your-subnet-id-1"
nat = true
},
{
subnet_id = "your-subnet-id-2"
nat = false
}
]
list(object({
subnet_id = string
index = optional(number)
ipv4 = optional(bool, true)
ip_address = optional(string)
nat = optional(bool, false)
nat_ip_address = optional(string)
security_group_ids = optional(list(string))
dns_record = optional(list(object({
fqdn = string
dns_zone_id = optional(string)
ttl = optional(number)
ptr = optional(bool, false)
})), [])
}))
[] no
placement_policy Placement policy configuration for the instance. Controls how the instance is placed within dedicated host groups.

Example:
placement_policy = {
placement_group_id = "your-placement-group-id"
host_affinity_rules = [
{
key = "host"
op = "IN"
values = ["host-1", "host-2"]
}
]
}
object({
placement_group_id = optional(string)
host_affinity_rules = optional(list(object({
key = string
op = string
values = list(string)
})), [])
})
{} 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({
index = optional(number)
disk_id = optional(string)
auto_delete = optional(bool, true)
device_name = optional(string, "secondary-disk")
mode = optional(string, "READ_WRITE")
size = optional(number, 50)
block_size = optional(number, 4096)
type = optional(string, "network-hdd")
description = optional(string, "Secondary disk")
kms_key_id = optional(string, null)
}))
[] 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({
description = optional(string)
folder_id = optional(string)
labels = optional(map(string))
deletion_protection = optional(bool)
external_ipv4_address = optional(object({
zone_id = string
ddos_protection_provider = optional(string)
outgoing_smtp_capability = optional(string)
}))
dns_record = optional(object({
fqdn = string
dns_zone_id = string
ttl = optional(number)
ptr = optional(bool)
}))
})
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

Outputs

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

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages