diff --git a/modules/compute-vm/README.md b/modules/compute-vm/README.md
index 35c5fe7dc..36a241f17 100644
--- a/modules/compute-vm/README.md
+++ b/modules/compute-vm/README.md
@@ -809,8 +809,8 @@ module "sole-tenancy" {
|---|---|:---:|:---:|:---:|
| [name](variables.tf#L235) | Instance name. | string | ✓ | |
| [network_interfaces](variables.tf#L247) | Network interfaces configuration. Use self links for Shared VPC, set addresses to null if not needed. | list(object({…})) | ✓ | |
-| [project_id](variables.tf#L289) | Project id. | string | ✓ | |
-| [zone](variables.tf#L387) | Compute zone. | string | ✓ | |
+| [project_id](variables.tf#L293) | Project id. | string | ✓ | |
+| [zone](variables.tf#L391) | Compute zone. | string | ✓ | |
| [attached_disk_defaults](variables.tf#L17) | Defaults for attached disks options. | object({…}) | | {…} |
| [attached_disks](variables.tf#L37) | 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. | list(object({…})) | | [] |
| [boot_disk](variables.tf#L83) | Boot disk properties. | object({…}) | | {…} |
@@ -829,14 +829,14 @@ module "sole-tenancy" {
| [metadata](variables.tf#L223) | Instance metadata. | map(string) | | {} |
| [min_cpu_platform](variables.tf#L229) | Minimum CPU platform. | string | | null |
| [network_attached_interfaces](variables.tf#L240) | Network interfaces using network attachments. | list(string) | | [] |
-| [options](variables.tf#L263) | Instance options. | object({…}) | | {…} |
-| [scratch_disks](variables.tf#L294) | Scratch disks configuration. | object({…}) | | {…} |
-| [service_account](variables.tf#L306) | Service account email and scopes. If email is null, the default Compute service account will be used unless auto_create is true, in which case a service account will be created. Set the variable to null to avoid attaching a service account. | object({…}) | | {} |
-| [shielded_config](variables.tf#L316) | Shielded VM configuration of the instances. | object({…}) | | null |
-| [snapshot_schedules](variables.tf#L326) | Snapshot schedule resource policies that can be attached to disks. | map(object({…})) | | {} |
-| [tag_bindings](variables.tf#L369) | Resource manager tag bindings for this instance, in tag key => tag value format. | map(string) | | null |
-| [tag_bindings_firewall](variables.tf#L375) | Firewall (network scoped) tag bindings for this instance, in tag key => tag value format. | map(string) | | null |
-| [tags](variables.tf#L381) | Instance network tags for firewall rule targets. | list(string) | | [] |
+| [options](variables.tf#L263) | Instance options. | object({…}) | | {…} |
+| [scratch_disks](variables.tf#L298) | Scratch disks configuration. | object({…}) | | {…} |
+| [service_account](variables.tf#L310) | Service account email and scopes. If email is null, the default Compute service account will be used unless auto_create is true, in which case a service account will be created. Set the variable to null to avoid attaching a service account. | object({…}) | | {} |
+| [shielded_config](variables.tf#L320) | Shielded VM configuration of the instances. | object({…}) | | null |
+| [snapshot_schedules](variables.tf#L330) | Snapshot schedule resource policies that can be attached to disks. | map(object({…})) | | {} |
+| [tag_bindings](variables.tf#L373) | Resource manager tag bindings for this instance, in tag key => tag value format. | map(string) | | null |
+| [tag_bindings_firewall](variables.tf#L379) | Firewall (network scoped) tag bindings for this instance, in tag key => tag value format. | map(string) | | null |
+| [tags](variables.tf#L385) | Instance network tags for firewall rule targets. | list(string) | | [] |
## Outputs
diff --git a/modules/compute-vm/main.tf b/modules/compute-vm/main.tf
index 84580812c..0e2da2b22 100644
--- a/modules/compute-vm/main.tf
+++ b/modules/compute-vm/main.tf
@@ -67,7 +67,7 @@ locals {
)
)
termination_action = (
- var.options.spot ? coalesce(var.options.termination_action, "STOP") : null
+ var.options.spot || var.options.max_run_duration != null ? coalesce(var.options.termination_action, "STOP") : null
)
}
@@ -280,6 +280,13 @@ resource "google_compute_instance" "default" {
on_host_maintenance = local.on_host_maintenance
preemptible = var.options.spot
provisioning_model = var.options.spot ? "SPOT" : "STANDARD"
+ dynamic "max_run_duration" {
+ for_each = var.options.max_run_duration == null ? [] : [""]
+ content {
+ nanos = var.options.max_run_duration.nanos
+ seconds = var.options.max_run_duration.seconds
+ }
+ }
dynamic "node_affinities" {
for_each = var.options.node_affinities
@@ -445,6 +452,13 @@ resource "google_compute_instance_template" "default" {
on_host_maintenance = local.on_host_maintenance
preemptible = var.options.spot
provisioning_model = var.options.spot ? "SPOT" : "STANDARD"
+ dynamic "max_run_duration" {
+ for_each = var.options.max_run_duration == null ? [] : [""]
+ content {
+ nanos = var.options.max_run_duration.nanos
+ seconds = var.options.max_run_duration.seconds
+ }
+ }
dynamic "node_affinities" {
for_each = var.options.node_affinities
diff --git a/modules/compute-vm/variables.tf b/modules/compute-vm/variables.tf
index a9594f14d..ff531263d 100644
--- a/modules/compute-vm/variables.tf
+++ b/modules/compute-vm/variables.tf
@@ -265,6 +265,10 @@ variable "options" {
type = object({
allow_stopping_for_update = optional(bool, true)
deletion_protection = optional(bool, false)
+ max_run_duration = optional(object({
+ nanos = optional(number)
+ seconds = number
+ }))
node_affinities = optional(map(object({
values = list(string)
in = optional(bool, true)