yandex_compute_instance (Resource)
- Example usage
- Schema
- Required
- Optional
- Read-Only
- Nested Schema for boot_disk
- Nested Schema for boot_disk.initialize_params
- Nested Schema for network_interface
- Nested Schema for network_interface.dns_record
- Nested Schema for network_interface.ipv6_dns_record
- Nested Schema for network_interface.nat_dns_record
- Nested Schema for resources
- Nested Schema for filesystem
- Nested Schema for local_disk
- Nested Schema for metadata_options
- Nested Schema for placement_policy
- Nested Schema for placement_policy.host_affinity_rules
- Nested Schema for scheduling_policy
- Nested Schema for secondary_disk
- Nested Schema for timeouts
- Nested Schema for hardware_generation
- Nested Schema for hardware_generation.generation2_features
- Nested Schema for hardware_generation.legacy_features
- Import
A VM instance resource. For more information, see the official documentation.
Example usage
//
// Create a new Compute Instance
//
resource "yandex_compute_instance" "default" {
name = "test"
platform_id = "standard-v3"
zone = "ru-central1-a"
resources {
cores = 2
memory = 4
}
boot_disk {
disk_id = yandex_compute_disk.boot-disk.id
}
network_interface {
index = 1
subnet_id = yandex_vpc_subnet.foo.id
}
metadata = {
foo = "bar"
ssh-keys = "ubuntu:${file("~/.ssh/id_ed25519.pub")}"
}
}
// Auxiliary resources for Compute Instance
resource "yandex_vpc_network" "foo" {}
resource "yandex_vpc_subnet" "foo" {
zone = "ru-central1-a"
network_id = yandex_vpc_network.foo.id
v4_cidr_blocks = ["10.5.0.0/24"]
}
Schema
Required
boot_disk(Block List, Min: 1, Max: 1) The boot disk for the instance. Eitherinitialize_paramsordisk_idmust be specified. (see below for nested schema)network_interface(Block List, Min: 1) Networks to attach to the instance. This can be specified multiple times. (see below for nested schema)resources(Block List, Min: 1, Max: 1) Compute resources that are allocated for the instance. (see below for nested schema)
Optional
allow_recreate(Boolean)allow_stopping_for_update(Boolean) Iftrue, 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.description(String) The resource description.filesystem(Block Set) List of filesystems that are attached to the instance. (see below for nested schema)folder_id(String) The folder identifier that resource belongs to. If it is not provided, the default providerfolder-idis used.gpu_cluster_id(String) ID of the GPU cluster to attach this instance to.hostname(String) Host name for the instance. This field is used to generate the instancefqdnvalue. The host name must be unique within the network and region. If not specified, the host name will be equal toidof the instance andfqdnwill be<id>.auto.internal. Otherwise FQDN will be<hostname>.<region_id>.internal.labels(Map of String) A set of key/value label pairs which assigned to resource.local_disk(Block List) List of local disks that are attached to the instance.
Важно
Local disks are not available for all users by default. (see below for nested schema)
maintenance_grace_period(String) Time between notification via metadata service and maintenance. E.g.,60s.maintenance_policy(String) Behavior on maintenance events. Can be:unspecified,migrate,restart. The default isunspecified.metadata(Map of String) Metadata key/value pairs to make available from within the instance.metadata_options(Block List, Max: 1) Options allow user to configure access to instance's metadata. (see below for nested schema)name(String) The resource name.network_acceleration_type(String) Type of network acceleration. Can bestandardorsoftware_accelerated. The default isstandard.placement_policy(Block List, Max: 1) The placement policy configuration. (see below for nested schema)platform_id(String) The type of virtual machine to create.scheduling_policy(Block List, Max: 1) Scheduling policy configuration. (see below for nested schema)secondary_disk(Block Set) A set of disks to attach to the instance. The structure is documented below.
Важно
The allow_stopping_for_update property must be set to true in order to update this structure. (see below for nested schema)
service_account_id(String) Service account which linked to the resource.timeouts(Block, Optional) (see below for nested schema)zone(String) The availability zone where resource is located. If it is not provided, the default provider zone will be used.
Read-Only
created_at(String) The creation timestamp of the resource.fqdn(String) The fully qualified DNS name of this instance.hardware_generation(List of Object) (see below for nested schema)id(String) The ID of this resource.status(String) The status of this instance.
Nested Schema for boot_disk
Optional:
auto_delete(Boolean) Defines whether the disk will be auto-deleted when the instance is deleted. The default value isTrue.device_name(String) Name that can be used to access an attached disk.disk_id(String) The ID of the existing disk (such as those managed byyandex_compute_disk) to attach as a boot disk.initialize_params(Block List, Max: 1) Parameters for a new disk that will be created alongside the new instance. Eitherinitialize_paramsordisk_idmust be set. Eitherimage_idorsnapshot_idmust be specified. (see below for nested schema)mode(String) Type of access to the disk resource. By default, a disk is attached inREAD_WRITEmode.
Nested Schema for boot_disk.initialize_params
Optional:
block_size(Number) Block size of the disk, specified in bytes.description(String) Description of the boot disk.image_id(String) A disk image to initialize this disk from.kms_key_id(String) ID of KMS symmetric key used to encrypt disk.name(String) Name of the boot disk.size(Number) Size of the disk in GB.snapshot_id(String) A snapshot to initialize this disk from.type(String) Disk type.
Nested Schema for network_interface
Required:
subnet_id(String) ID of the subnet to attach this interface to. The subnet must exist in the same zone where this instance will be created.
Optional:
dns_record(Block List) List of configurations for creating ipv4 DNS records. (see below for nested schema)index(Number) Index of network interface, will be calculated automatically for instance create or update operations if not specified. Required for attach/detach operations.ip_address(String) The private IP address to assign to the instance. If empty, the address will be automatically assigned from the specified subnet.ipv4(Boolean) Allocate an IPv4 address for the interface. The default value istrue.ipv6(Boolean) Iftrue, allocate an IPv6 address for the interface. The address will be automatically assigned from the specified subnet.ipv6_address(String) The private IPv6 address to assign to the instance.ipv6_dns_record(Block List) List of configurations for creating ipv6 DNS records. (see below for nested schema)nat(Boolean) Provide a public address, for instance, to access the internet over NAT.nat_dns_record(Block List) List of configurations for creating ipv4 NAT DNS records. (see below for nested schema)nat_ip_address(String) Provide a public address, for instance, to access the internet over NAT. Address should be already reserved in web UI.security_group_ids(Set of String) Security Group (SG) IDs for network interface.
Read-Only:
mac_address(String)nat_ip_version(String)
Nested Schema for network_interface.dns_record
Required:
fqdn(String) DNS record FQDN (must have a dot at the end).
Optional:
dns_zone_id(String) DNS zone ID (if not set, private zone used).ptr(Boolean) When set totrue, also create a PTR DNS record.ttl(Number) DNS record TTL in seconds.
Nested Schema for network_interface.ipv6_dns_record
Required:
fqdn(String) DNS record FQDN (must have a dot at the end).
Optional:
dns_zone_id(String) DNS zone ID (if not set, private zone used).ptr(Boolean) When set totrue, also create a PTR DNS record.ttl(Number) DNS record TTL in seconds.
Nested Schema for network_interface.nat_dns_record
Required:
fqdn(String) DNS record FQDN (must have a dot at the end).
Optional:
dns_zone_id(String) DNS zone ID (if not set, private zone used).ptr(Boolean) When set totrue, also create a PTR DNS record.ttl(Number) DNS record TTL in seconds.
Nested Schema for resources
Required:
cores(Number) CPU cores for the instance.memory(Number) Memory size in GB.
Optional:
core_fraction(Number) If provided, specifies baseline performance for a core as a percent.gpus(Number) If provided, specifies the number of GPU devices for the instance.
Nested Schema for filesystem
Required:
filesystem_id(String) ID of the filesystem that should be attached.
Optional:
device_name(String) Name of the device representing the filesystem on the instance.mode(String) Mode of access to the filesystem that should be attached. By default, filesystem is attached inREAD_WRITEmode.
Nested Schema for local_disk
Required:
size_bytes(Number) Size of the disk, specified in bytes.
Read-Only:
device_name(String) The name of the local disk device.
Nested Schema for metadata_options
Optional:
aws_v1_http_endpoint(Number)aws_v1_http_token(Number)gce_http_endpoint(Number)gce_http_token(Number)
Nested Schema for placement_policy
Optional:
host_affinity_rules(List of Object) List of host affinity rules.
Важно
Due to terraform limitations, simply deleting the placement_policy fields does not work. To reset the values of these fields, you need to set them empty:
placement_policy {
placement_group_id = ""
host_affinity_rules = []
} (see below for nested schema)
placement_group_id(String) Specifies the id of the Placement Group to assign to the instance.placement_group_partition(Number)
Nested Schema for placement_policy.host_affinity_rules
Optional:
key(String)op(String)values(List of String)
Nested Schema for scheduling_policy
Optional:
preemptible(Boolean) Specifies if the instance is preemptible. Defaults tofalse.
Nested Schema for secondary_disk
Required:
disk_id(String) ID of the disk that is attached to the instance.
Optional:
auto_delete(Boolean) Whether the disk is auto-deleted when the instance is deleted. The default value isfalse.device_name(String) Name that can be used to access an attached disk under/dev/disk/by-id/.mode(String) Type of access to the disk resource. By default, a disk is attached inREAD_WRITEmode.
Nested Schema for timeouts
Optional:
create(String) A string that can be parsed as a duration consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).delete(String) A string that can be parsed as a duration consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours). Setting a timeout for a Delete operation is only applicable if changes are saved into state before the destroy operation occurs.update(String) A string that can be parsed as a duration consisting of numbers and unit suffixes, such as "30s" or "2h45m". Valid time units are "s" (seconds), "m" (minutes), "h" (hours).
Nested Schema for hardware_generation
Read-Only:
generation2_features(List of Object) (see below for nested schema)legacy_features(List of Object) (see below for nested schema)
Nested Schema for hardware_generation.generation2_features
Read-Only:
Nested Schema for hardware_generation.legacy_features
Read-Only:
pci_topology(String)
Import
The resource can be imported by using their resource ID. For getting the resource ID you can use Yandex Cloud Web Console
# terraform import yandex_compute_instance.<resource Name> <resource Id>
terraform import yandex_compute_instance.my_vm1 fhmur**********j51ah