From 17568816525e7a549a1dbf5b9bd5a84e18b70a50 Mon Sep 17 00:00:00 2001 From: Tom Downes Date: Mon, 23 Oct 2023 21:35:07 -0500 Subject: [PATCH] feat: support setting maintenance_interval in instance_template --- modules/instance_template/README.md | 1 + modules/instance_template/main.tf | 6 ++++-- modules/instance_template/metadata.yaml | 4 ++++ modules/instance_template/variables.tf | 10 ++++++++++ modules/instance_template/versions.tf | 6 +++--- 5 files changed, 22 insertions(+), 5 deletions(-) diff --git a/modules/instance_template/README.md b/modules/instance_template/README.md index e881f74e..ba099853 100644 --- a/modules/instance_template/README.md +++ b/modules/instance_template/README.md @@ -31,6 +31,7 @@ See the [simple](../../examples/instance_template/simple) for a usage example. | ipv6\_access\_config | IPv6 access configurations. Currently a max of 1 IPv6 access configuration is supported. If not specified, the instance will have no external IPv6 Internet access. |
list(object({
network_tier = string
}))
| `[]` | no | | labels | Labels, provided as a map | `map(string)` | `{}` | no | | machine\_type | Machine type to create, e.g. n1-standard-1 | `string` | `"n1-standard-1"` | no | +| maintenance\_interval | Specifies the frequency of planned maintenance events | `string` | `null` | no | | metadata | Metadata, provided as a map | `map(string)` | `{}` | no | | min\_cpu\_platform | Specifies a minimum CPU platform. Applicable values are the friendly names of CPU platforms, such as Intel Haswell or Intel Skylake. See the complete list: https://cloud.google.com/compute/docs/instances/specify-min-cpu-platform | `string` | `null` | no | | name\_prefix | Name prefix for the instance template | `string` | `"default-instance-template"` | no | diff --git a/modules/instance_template/main.tf b/modules/instance_template/main.tf index af4d0d95..01400357 100644 --- a/modules/instance_template/main.tf +++ b/modules/instance_template/main.tf @@ -63,6 +63,7 @@ locals { # Instance Template #################### resource "google_compute_instance_template" "tpl" { + provider = google-beta name_prefix = "${var.name_prefix}-" project = var.project_id machine_type = var.machine_type @@ -175,11 +176,12 @@ resource "google_compute_instance_template" "tpl" { } scheduling { - preemptible = local.preemptible automatic_restart = local.automatic_restart + instance_termination_action = var.spot ? var.spot_instance_termination_action : null + maintenance_interval = var.maintenance_interval on_host_maintenance = local.on_host_maintenance + preemptible = local.preemptible provisioning_model = var.spot ? "SPOT" : null - instance_termination_action = var.spot ? var.spot_instance_termination_action : null } advanced_machine_features { diff --git a/modules/instance_template/metadata.yaml b/modules/instance_template/metadata.yaml index 23cece85..ce336164 100644 --- a/modules/instance_template/metadata.yaml +++ b/modules/instance_template/metadata.yaml @@ -194,6 +194,10 @@ spec: description: Machine type to create, e.g. n1-standard-1 varType: string defaultValue: n1-standard-1 + - name: maintenance_interval + description: Specifies the frequency of planned maintenance events + varType: string + defaultValue: null - name: metadata description: Metadata, provided as a map varType: map(string) diff --git a/modules/instance_template/variables.tf b/modules/instance_template/variables.tf index 1807d0cd..790f854b 100644 --- a/modules/instance_template/variables.tf +++ b/modules/instance_template/variables.tf @@ -74,6 +74,16 @@ variable "automatic_restart" { default = true } +variable "maintenance_interval" { + type = string + description = "Specifies the frequency of planned maintenance events" + default = null + validation { + condition = var.maintenance_interval == null || var.maintenance_interval == "PERIODIC" + error_message = "var.maintenance_interval must be set to null or \"PERIODIC\"" + } +} + variable "on_host_maintenance" { type = string description = "Instance availability Policy" diff --git a/modules/instance_template/versions.tf b/modules/instance_template/versions.tf index 46563308..a5f91876 100644 --- a/modules/instance_template/versions.tf +++ b/modules/instance_template/versions.tf @@ -17,9 +17,9 @@ terraform { required_version = ">=0.13.0" required_providers { - google = { - source = "hashicorp/google" - version = ">= 4.67, < 6" + google-beta = { + source = "hashicorp/google-beta" + version = ">= 5.5" } } provider_meta "google" {