Remove preemptible VMs in favor of spot VMs
This commit is contained in:
@@ -44,7 +44,6 @@ module "spot-vm-example" {
|
||||
options = {
|
||||
allow_stopping_for_update = true
|
||||
deletion_protection = false
|
||||
preemptible = true
|
||||
spot = true
|
||||
}
|
||||
network_interfaces = [{
|
||||
@@ -328,8 +327,8 @@ module "instance-group" {
|
||||
|---|---|:---:|:---:|:---:|
|
||||
| [name](variables.tf#L160) | Instance name. | <code>string</code> | ✓ | |
|
||||
| [network_interfaces](variables.tf#L174) | Network interfaces configuration. Use self links for Shared VPC, set addresses to null if not needed. | <code title="list(object({ nat = bool network = string subnetwork = string addresses = object({ internal = string external = string }) }))">list(object({…}))</code> | ✓ | |
|
||||
| [project_id](variables.tf#L207) | Project id. | <code>string</code> | ✓ | |
|
||||
| [zone](variables.tf#L266) | Compute zone. | <code>string</code> | ✓ | |
|
||||
| [project_id](variables.tf#L201) | Project id. | <code>string</code> | ✓ | |
|
||||
| [zone](variables.tf#L260) | Compute zone. | <code>string</code> | ✓ | |
|
||||
| [attached_disk_defaults](variables.tf#L17) | Defaults for attached disks options. | <code title="object({ mode = string replica_zone = string type = string })">object({…})</code> | | <code title="{ auto_delete = true mode = "READ_WRITE" replica_zone = null type = "pd-balanced" }">{…}</code> |
|
||||
| [attached_disks](variables.tf#L32) | Additional disks, if options is null defaults will be used in its place. Source type is one of 'image' (zonal disks in vms and template), 'snapshot' (vm), 'existing', and null. | <code title="list(object({ name = string size = string source = string source_type = string options = object({ mode = string replica_zone = string type = string }) }))">list(object({…}))</code> | | <code>[]</code> |
|
||||
| [boot_disk](variables.tf#L58) | Boot disk properties. | <code title="object({ image = string size = number type = string })">object({…})</code> | | <code title="{ image = "projects/debian-cloud/global/images/family/debian-11" type = "pd-balanced" size = 10 }">{…}</code> |
|
||||
@@ -348,14 +347,14 @@ 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 spot = bool })">object({…})</code> | | <code title="{ allow_stopping_for_update = true deletion_protection = false preemptible = false spot = false }">{…}</code> |
|
||||
| [scratch_disks](variables.tf#L212) | Scratch disks configuration. | <code title="object({ count = number interface = string })">object({…})</code> | | <code title="{ count = 0 interface = "NVME" }">{…}</code> |
|
||||
| [service_account](variables.tf#L224) | Service account email. Unused if service account is auto-created. | <code>string</code> | | <code>null</code> |
|
||||
| [service_account_create](variables.tf#L230) | Auto-create service account. | <code>bool</code> | | <code>false</code> |
|
||||
| [service_account_scopes](variables.tf#L238) | Scopes applied to service account. | <code>list(string)</code> | | <code>[]</code> |
|
||||
| [shielded_config](variables.tf#L244) | Shielded VM configuration of the instances. | <code title="object({ enable_secure_boot = bool enable_vtpm = bool enable_integrity_monitoring = bool })">object({…})</code> | | <code>null</code> |
|
||||
| [tag_bindings](variables.tf#L254) | Tag bindings for this instance, in key => tag value id format. | <code>map(string)</code> | | <code>null</code> |
|
||||
| [tags](variables.tf#L260) | Instance network tags for firewall rule targets. | <code>list(string)</code> | | <code>[]</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> |
|
||||
| [service_account_scopes](variables.tf#L232) | Scopes applied to service account. | <code>list(string)</code> | | <code>[]</code> |
|
||||
| [shielded_config](variables.tf#L238) | Shielded VM configuration of the instances. | <code title="object({ enable_secure_boot = bool enable_vtpm = bool enable_integrity_monitoring = bool })">object({…})</code> | | <code>null</code> |
|
||||
| [tag_bindings](variables.tf#L248) | Tag bindings for this instance, in key => tag value id format. | <code>map(string)</code> | | <code>null</code> |
|
||||
| [tags](variables.tf#L254) | Instance network tags for firewall rule targets. | <code>list(string)</code> | | <code>[]</code> |
|
||||
|
||||
## Outputs
|
||||
|
||||
|
||||
@@ -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,10 +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
|
||||
provisioning_model = var.options.spot ? "SPOT" : null
|
||||
preemptible = var.options.spot
|
||||
provisioning_model = var.options.spot ? "SPOT" : "STANDARD"
|
||||
}
|
||||
|
||||
dynamic "scratch_disk" {
|
||||
@@ -339,10 +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
|
||||
provisioning_model = var.options.spot ? "SPOT" : null
|
||||
preemptible = var.options.spot
|
||||
provisioning_model = var.options.spot ? "SPOT" : "STANDARD"
|
||||
}
|
||||
|
||||
service_account {
|
||||
|
||||
@@ -189,19 +189,13 @@ 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
|
||||
}
|
||||
validation {
|
||||
condition = !var.options.spot || (var.options.spot && var.options.preemptible)
|
||||
error_message = "Variable var.option.preemptible must be `true` when var.options.spot is set to `true`."
|
||||
}
|
||||
}
|
||||
|
||||
variable "project_id" {
|
||||
|
||||
Reference in New Issue
Block a user