Merge pull request #646 from GoogleCloudPlatform/sruffilli/spot-vm
Adds Spot VM support to compute-vm
This commit is contained in:
@@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file.
|
||||
|
||||
## Unreleased
|
||||
|
||||
- add support for [Spot VMs](https://cloud.google.com/compute/docs/instances/spot) to `gke-nodepool` module
|
||||
- **incompatible change** add support for [Spot VMs](https://cloud.google.com/compute/docs/instances/spot) to `compute-vm` module
|
||||
- SQL Server AlwaysOn availability groups example
|
||||
- fixed Terraform change detection in CloudSQL when backup is disabled
|
||||
- allow multiple CIDR blocks in the ip_range for Apigee Instance
|
||||
|
||||
@@ -60,6 +60,7 @@ module "nva-template-ew1" {
|
||||
deletion_protection = false
|
||||
# Creates preemptible instances, cheaper than regular one. Only suitable for testing.
|
||||
preemptible = true
|
||||
spot = true
|
||||
}
|
||||
metadata = {
|
||||
startup-script = templatefile(
|
||||
|
||||
@@ -31,6 +31,33 @@ module "simple-vm-example" {
|
||||
|
||||
```
|
||||
|
||||
### Spot VM
|
||||
|
||||
[Spot VMs](https://cloud.google.com/compute/docs/instances/spot) are ephemeral compute instances suitable for batch jobs and fault-tolerant workloads. Spot VMs provide new features that [preemptible instances](https://cloud.google.com/compute/docs/instances/preemptible) do not support, such as the absence of a maximum runtime.
|
||||
|
||||
```hcl
|
||||
module "spot-vm-example" {
|
||||
source = "./modules/compute-vm"
|
||||
project_id = var.project_id
|
||||
zone = "europe-west1-b"
|
||||
name = "test"
|
||||
options = {
|
||||
allow_stopping_for_update = true
|
||||
deletion_protection = false
|
||||
spot = true
|
||||
}
|
||||
network_interfaces = [{
|
||||
network = var.vpc.self_link
|
||||
subnetwork = var.subnet.self_link
|
||||
nat = false
|
||||
addresses = null
|
||||
}]
|
||||
service_account_create = true
|
||||
}
|
||||
# tftest modules=1 resources=2
|
||||
|
||||
```
|
||||
|
||||
### Disk sources
|
||||
|
||||
Attached disks can be created and optionally initialized from a pre-existing source, or attached to VMs when pre-existing. The `source` and `source_type` attributes of the `attached_disks` variable allows several modes of operation:
|
||||
@@ -320,7 +347,7 @@ module "instance-group" {
|
||||
| [metadata](variables.tf#L148) | Instance metadata. | <code>map(string)</code> | | <code>{}</code> |
|
||||
| [min_cpu_platform](variables.tf#L154) | Minimum CPU platform. | <code>string</code> | | <code>null</code> |
|
||||
| [network_interface_options](variables.tf#L165) | Network interfaces extended options. The key is the index of the inteface to configure. The value is an object with alias_ips and nic_type. Set alias_ips or nic_type to null if you need only one of them. | <code title="map(object({ alias_ips = map(string) nic_type = string }))">map(object({…}))</code> | | <code>{}</code> |
|
||||
| [options](variables.tf#L187) | Instance options. | <code title="object({ allow_stopping_for_update = bool deletion_protection = bool preemptible = bool })">object({…})</code> | | <code title="{ allow_stopping_for_update = true deletion_protection = false preemptible = false }">{…}</code> |
|
||||
| [options](variables.tf#L187) | Instance options. | <code title="object({ allow_stopping_for_update = bool deletion_protection = bool spot = bool })">object({…})</code> | | <code title="{ allow_stopping_for_update = true deletion_protection = false spot = false }">{…}</code> |
|
||||
| [scratch_disks](variables.tf#L206) | Scratch disks configuration. | <code title="object({ count = number interface = string })">object({…})</code> | | <code title="{ count = 0 interface = "NVME" }">{…}</code> |
|
||||
| [service_account](variables.tf#L218) | Service account email. Unused if service account is auto-created. | <code>string</code> | | <code>null</code> |
|
||||
| [service_account_create](variables.tf#L224) | Auto-create service account. | <code>bool</code> | | <code>false</code> |
|
||||
|
||||
@@ -30,7 +30,7 @@ locals {
|
||||
k => v if try(v.options.replica_zone, null) == null
|
||||
}
|
||||
on_host_maintenance = (
|
||||
var.options.preemptible || var.confidential_compute
|
||||
var.options.spot || var.confidential_compute
|
||||
? "TERMINATE"
|
||||
: "MIGRATE"
|
||||
)
|
||||
@@ -212,9 +212,10 @@ resource "google_compute_instance" "default" {
|
||||
}
|
||||
|
||||
scheduling {
|
||||
automatic_restart = !var.options.preemptible
|
||||
automatic_restart = !var.options.spot
|
||||
on_host_maintenance = local.on_host_maintenance
|
||||
preemptible = var.options.preemptible
|
||||
preemptible = var.options.spot
|
||||
provisioning_model = var.options.spot ? "SPOT" : "STANDARD"
|
||||
}
|
||||
|
||||
dynamic "scratch_disk" {
|
||||
@@ -338,9 +339,10 @@ resource "google_compute_instance_template" "default" {
|
||||
}
|
||||
|
||||
scheduling {
|
||||
automatic_restart = !var.options.preemptible
|
||||
automatic_restart = !var.options.spot
|
||||
on_host_maintenance = local.on_host_maintenance
|
||||
preemptible = var.options.preemptible
|
||||
preemptible = var.options.spot
|
||||
provisioning_model = var.options.spot ? "SPOT" : "STANDARD"
|
||||
}
|
||||
|
||||
service_account {
|
||||
|
||||
@@ -189,12 +189,12 @@ variable "options" {
|
||||
type = object({
|
||||
allow_stopping_for_update = bool
|
||||
deletion_protection = bool
|
||||
preemptible = bool
|
||||
spot = bool
|
||||
})
|
||||
default = {
|
||||
allow_stopping_for_update = true
|
||||
deletion_protection = false
|
||||
preemptible = false
|
||||
spot = false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -41,7 +41,7 @@ module "cluster-1-nodepool-1" {
|
||||
|---|---|:---:|:---:|:---:|
|
||||
| [cluster_name](variables.tf#L26) | Cluster name. | <code>string</code> | ✓ | |
|
||||
| [location](variables.tf#L59) | Cluster location. | <code>string</code> | ✓ | |
|
||||
| [project_id](variables.tf#L210) | Cluster project id. | <code>string</code> | ✓ | |
|
||||
| [project_id](variables.tf#L216) | Cluster project id. | <code>string</code> | ✓ | |
|
||||
| [autoscaling_config](variables.tf#L17) | Optional autoscaling configuration. | <code title="object({ min_node_count = number max_node_count = number })">object({…})</code> | | <code>null</code> |
|
||||
| [gke_version](variables.tf#L31) | Kubernetes nodes version. Ignored if auto_upgrade is set in management_config. | <code>string</code> | | <code>null</code> |
|
||||
| [initial_node_count](variables.tf#L37) | Initial number of nodes for the pool. | <code>number</code> | | <code>1</code> |
|
||||
@@ -68,10 +68,11 @@ module "cluster-1-nodepool-1" {
|
||||
| [node_service_account_create](variables.tf#L174) | Auto-create service account. | <code>bool</code> | | <code>false</code> |
|
||||
| [node_service_account_scopes](variables.tf#L182) | Scopes applied to service account. Default to: 'cloud-platform' when creating a service account; 'devstorage.read_only', 'logging.write', 'monitoring.write' otherwise. | <code>list(string)</code> | | <code>[]</code> |
|
||||
| [node_shielded_instance_config](variables.tf#L188) | Shielded instance options. | <code title="object({ enable_secure_boot = bool enable_integrity_monitoring = bool })">object({…})</code> | | <code>null</code> |
|
||||
| [node_tags](variables.tf#L197) | Network tags applied to nodes. | <code>list(string)</code> | | <code>null</code> |
|
||||
| [node_taints](variables.tf#L203) | Kubernetes taints applied to nodes. E.g. type=blue:NoSchedule. | <code>list(string)</code> | | <code>[]</code> |
|
||||
| [upgrade_config](variables.tf#L215) | Optional node upgrade configuration. | <code title="object({ max_surge = number max_unavailable = number })">object({…})</code> | | <code>null</code> |
|
||||
| [workload_metadata_config](variables.tf#L224) | Metadata configuration to expose to workloads on the node pool. | <code>string</code> | | <code>"GKE_METADATA"</code> |
|
||||
| [node_spot](variables.tf#L197) | Use Spot VMs for nodes. | <code>bool</code> | | <code>null</code> |
|
||||
| [node_tags](variables.tf#L203) | Network tags applied to nodes. | <code>list(string)</code> | | <code>null</code> |
|
||||
| [node_taints](variables.tf#L209) | Kubernetes taints applied to nodes. E.g. type=blue:NoSchedule. | <code>list(string)</code> | | <code>[]</code> |
|
||||
| [upgrade_config](variables.tf#L221) | Optional node upgrade configuration. | <code title="object({ max_surge = number max_unavailable = number })">object({…})</code> | | <code>null</code> |
|
||||
| [workload_metadata_config](variables.tf#L230) | Metadata configuration to expose to workloads on the node pool. | <code>string</code> | | <code>"GKE_METADATA"</code> |
|
||||
|
||||
## Outputs
|
||||
|
||||
|
||||
@@ -105,6 +105,7 @@ resource "google_container_node_pool" "nodepool" {
|
||||
service_account = local.service_account_email
|
||||
tags = var.node_tags
|
||||
boot_disk_kms_key = var.node_boot_disk_kms_key
|
||||
spot = var.node_spot
|
||||
|
||||
dynamic "guest_accelerator" {
|
||||
for_each = var.node_guest_accelerator
|
||||
|
||||
@@ -194,6 +194,12 @@ variable "node_shielded_instance_config" {
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "node_spot" {
|
||||
description = "Use Spot VMs for nodes."
|
||||
type = bool
|
||||
default = null
|
||||
}
|
||||
|
||||
variable "node_tags" {
|
||||
description = "Network tags applied to nodes."
|
||||
type = list(string)
|
||||
|
||||
Reference in New Issue
Block a user