From 17568816525e7a549a1dbf5b9bd5a84e18b70a50 Mon Sep 17 00:00:00 2001 From: Tom Downes Date: Mon, 23 Oct 2023 21:35:07 -0500 Subject: [PATCH 1/4] 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" { From f1cfcb1dec86c739d865f785ee1c166b73bc7f88 Mon Sep 17 00:00:00 2001 From: Tom Downes Date: Tue, 12 Dec 2023 08:37:57 -0600 Subject: [PATCH 2/4] Update modules/instance_template/versions.tf Co-authored-by: Andrew Peabody --- modules/instance_template/versions.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/instance_template/versions.tf b/modules/instance_template/versions.tf index a5f91876..162ce96b 100644 --- a/modules/instance_template/versions.tf +++ b/modules/instance_template/versions.tf @@ -19,7 +19,7 @@ terraform { required_providers { google-beta = { source = "hashicorp/google-beta" - version = ">= 5.5" + version = ">= 5.5, < 6" } } provider_meta "google" { From 0b4e42f1410b16ab2e0decd1026aa37c2349f455 Mon Sep 17 00:00:00 2001 From: Awais Malik Date: Fri, 16 Feb 2024 12:29:17 -0800 Subject: [PATCH 3/4] changing subnetwork to self_link --- test/fixtures/instance_template/additional_disks/main.tf | 2 +- test/fixtures/instance_template/alias_ip_range/main.tf | 2 +- test/fixtures/instance_template/simple/main.tf | 2 +- test/fixtures/mig/autoscaler/main.tf | 2 +- test/fixtures/mig/simple/main.tf | 2 +- test/fixtures/mig_stateful/main.tf | 2 +- test/fixtures/mig_with_percent/simple/main.tf | 2 +- .../preemptible_and_regular_instance_templates/simple/main.tf | 2 +- test/fixtures/umig/named_ports/main.tf | 2 +- test/fixtures/umig/simple/main.tf | 2 +- test/fixtures/umig/static_ips/main.tf | 2 +- 11 files changed, 11 insertions(+), 11 deletions(-) diff --git a/test/fixtures/instance_template/additional_disks/main.tf b/test/fixtures/instance_template/additional_disks/main.tf index 9598d6ab..335c6bf1 100644 --- a/test/fixtures/instance_template/additional_disks/main.tf +++ b/test/fixtures/instance_template/additional_disks/main.tf @@ -17,7 +17,7 @@ module "instance_template_additional_disks" { source = "../../../../examples/instance_template/additional_disks" project_id = var.project_id - subnetwork = google_compute_subnetwork.main.name + subnetwork = google_compute_subnetwork.main.self_link service_account = var.service_account } diff --git a/test/fixtures/instance_template/alias_ip_range/main.tf b/test/fixtures/instance_template/alias_ip_range/main.tf index 41e1b133..83e98dd9 100644 --- a/test/fixtures/instance_template/alias_ip_range/main.tf +++ b/test/fixtures/instance_template/alias_ip_range/main.tf @@ -17,6 +17,6 @@ module "instance_template_alias_ip_range" { source = "../../../../examples/instance_template/alias_ip_range" project_id = var.project_id - subnetwork = google_compute_subnetwork.main.name + subnetwork = google_compute_subnetwork.main.self_link service_account = var.service_account } diff --git a/test/fixtures/instance_template/simple/main.tf b/test/fixtures/instance_template/simple/main.tf index a6f13c9d..395e8e6d 100644 --- a/test/fixtures/instance_template/simple/main.tf +++ b/test/fixtures/instance_template/simple/main.tf @@ -17,7 +17,7 @@ module "instance_template_simple" { source = "../../../../examples/instance_template/simple" project_id = var.project_id - subnetwork = google_compute_subnetwork.main.name + subnetwork = google_compute_subnetwork.main.self_link service_account = var.service_account tags = ["foo", "bar"] diff --git a/test/fixtures/mig/autoscaler/main.tf b/test/fixtures/mig/autoscaler/main.tf index 6df78ba9..aeeedad6 100644 --- a/test/fixtures/mig/autoscaler/main.tf +++ b/test/fixtures/mig/autoscaler/main.tf @@ -17,7 +17,7 @@ module "mig_autoscaler" { source = "../../../../examples/mig/autoscaler" project_id = var.project_id - subnetwork = google_compute_subnetwork.main.name + subnetwork = google_compute_subnetwork.main.self_link service_account = var.service_account autoscaling_enabled = "true" min_replicas = 4 diff --git a/test/fixtures/mig/simple/main.tf b/test/fixtures/mig/simple/main.tf index d832f40e..5a94614d 100644 --- a/test/fixtures/mig/simple/main.tf +++ b/test/fixtures/mig/simple/main.tf @@ -17,7 +17,7 @@ module "mig_simple" { source = "../../../../examples/mig/simple" project_id = var.project_id - subnetwork = google_compute_subnetwork.main.name + subnetwork = google_compute_subnetwork.main.self_link target_size = 4 service_account = var.service_account } diff --git a/test/fixtures/mig_stateful/main.tf b/test/fixtures/mig_stateful/main.tf index 983f12d6..d7eb7fca 100644 --- a/test/fixtures/mig_stateful/main.tf +++ b/test/fixtures/mig_stateful/main.tf @@ -18,7 +18,7 @@ module "mig_stateful" { source = "../../../examples/mig_stateful" project_id = var.project_id region = "us-central1" - subnetwork = google_compute_subnetwork.main.name + subnetwork = google_compute_subnetwork.main.self_link target_size = 3 service_account = var.service_account } diff --git a/test/fixtures/mig_with_percent/simple/main.tf b/test/fixtures/mig_with_percent/simple/main.tf index c40b1119..10217848 100644 --- a/test/fixtures/mig_with_percent/simple/main.tf +++ b/test/fixtures/mig_with_percent/simple/main.tf @@ -17,6 +17,6 @@ module "mig_with_percent_simple" { source = "../../../../examples/mig_with_percent/simple" project_id = var.project_id - subnetwork = google_compute_subnetwork.main.name + subnetwork = google_compute_subnetwork.main.self_link service_account = var.service_account } diff --git a/test/fixtures/preemptible_and_regular_instance_templates/simple/main.tf b/test/fixtures/preemptible_and_regular_instance_templates/simple/main.tf index bc7389d0..03ee8cc4 100644 --- a/test/fixtures/preemptible_and_regular_instance_templates/simple/main.tf +++ b/test/fixtures/preemptible_and_regular_instance_templates/simple/main.tf @@ -17,7 +17,7 @@ module "preemptible_and_regular_instance_templates" { source = "../../../../examples/preemptible_and_regular_instance_templates/simple" project_id = var.project_id - subnetwork = google_compute_subnetwork.main.name + subnetwork = google_compute_subnetwork.main.self_link service_account = var.service_account tags = ["foo", "bar"] diff --git a/test/fixtures/umig/named_ports/main.tf b/test/fixtures/umig/named_ports/main.tf index e86b2f34..5543a9af 100644 --- a/test/fixtures/umig/named_ports/main.tf +++ b/test/fixtures/umig/named_ports/main.tf @@ -18,7 +18,7 @@ module "umig_named_ports" { source = "../../../../examples/umig/named_ports" project_id = var.project_id region = "us-central1" - subnetwork = google_compute_subnetwork.main.name + subnetwork = google_compute_subnetwork.main.self_link num_instances = 4 service_account = var.service_account diff --git a/test/fixtures/umig/simple/main.tf b/test/fixtures/umig/simple/main.tf index 0296b3b2..2d3c8808 100644 --- a/test/fixtures/umig/simple/main.tf +++ b/test/fixtures/umig/simple/main.tf @@ -18,7 +18,7 @@ module "umig_simple" { source = "../../../../examples/umig/simple" project_id = var.project_id region = "us-central1" - subnetwork = google_compute_subnetwork.main.name + subnetwork = google_compute_subnetwork.main.self_link num_instances = 4 service_account = var.service_account } diff --git a/test/fixtures/umig/static_ips/main.tf b/test/fixtures/umig/static_ips/main.tf index 94f73296..04b4f22b 100644 --- a/test/fixtures/umig/static_ips/main.tf +++ b/test/fixtures/umig/static_ips/main.tf @@ -18,7 +18,7 @@ module "umig_static_ips" { source = "../../../../examples/umig/static_ips" project_id = var.project_id region = "us-central1" - subnetwork = google_compute_subnetwork.main.name + subnetwork = google_compute_subnetwork.main.self_link static_ips = [ "10.128.0.10", From 685860674d77884a9e2bc4a1801ec0eed3ae5a84 Mon Sep 17 00:00:00 2001 From: Awais Malik Date: Fri, 16 Feb 2024 13:32:15 -0800 Subject: [PATCH 4/4] setting project id for umig examples --- examples/umig/named_ports/main.tf | 1 + examples/umig/simple/main.tf | 1 + examples/umig/static_ips/main.tf | 1 + 3 files changed, 3 insertions(+) diff --git a/examples/umig/named_ports/main.tf b/examples/umig/named_ports/main.tf index bfb40696..44e7a7fa 100644 --- a/examples/umig/named_ports/main.tf +++ b/examples/umig/named_ports/main.tf @@ -24,6 +24,7 @@ module "instance_template" { source = "terraform-google-modules/vm/google//modules/instance_template" version = "~> 10.0" + project_id = var.project_id subnetwork = var.subnetwork service_account = var.service_account } diff --git a/examples/umig/simple/main.tf b/examples/umig/simple/main.tf index 5df2964e..34b644f6 100644 --- a/examples/umig/simple/main.tf +++ b/examples/umig/simple/main.tf @@ -24,6 +24,7 @@ module "instance_template" { source = "terraform-google-modules/vm/google//modules/instance_template" version = "~> 10.0" + project_id = var.project_id subnetwork = var.subnetwork service_account = var.service_account } diff --git a/examples/umig/static_ips/main.tf b/examples/umig/static_ips/main.tf index 7fc8af6d..f4362151 100644 --- a/examples/umig/static_ips/main.tf +++ b/examples/umig/static_ips/main.tf @@ -24,6 +24,7 @@ module "instance_template" { source = "terraform-google-modules/vm/google//modules/instance_template" version = "~> 10.0" + project_id = var.project_id subnetwork = var.subnetwork service_account = var.service_account }