From 77976e7c33916ea74e282ecbfc80953ec87302e6 Mon Sep 17 00:00:00 2001 From: Rauny Date: Fri, 23 Feb 2024 16:40:07 +0100 Subject: [PATCH 1/7] feat: make mig health check fields optional --- autogen/variables.tf.tmpl | 26 ++++++++--------- .../compute_instance/disk_snapshot/main.tf | 6 ++-- examples/compute_instance/simple/main.tf | 4 +-- .../additional_disks/main.tf | 2 +- .../instance_template/alias_ip_range/main.tf | 2 +- .../instance_template/encrypted_disks/main.tf | 2 +- examples/instance_template/simple/main.tf | 2 +- examples/mig/autoscaler/main.tf | 4 +-- examples/mig/full/main.tf | 4 +-- examples/mig/healthcheck/main.tf | 28 +++++++++++++++++-- examples/mig/simple/main.tf | 4 +-- examples/mig_stateful/main.tf | 4 +-- examples/mig_with_percent/simple/main.tf | 4 +-- .../simple/main.tf | 2 +- examples/umig/full/main.tf | 4 +-- examples/umig/named_ports/main.tf | 4 +-- examples/umig/simple/main.tf | 4 +-- examples/umig/static_ips/main.tf | 4 +-- modules/mig/README.md | 2 +- modules/mig/metadata.yaml | 26 ++++++++--------- modules/mig/variables.tf | 26 ++++++++--------- modules/mig_with_percent/README.md | 2 +- modules/mig_with_percent/metadata.yaml | 26 ++++++++--------- modules/mig_with_percent/variables.tf | 26 ++++++++--------- 24 files changed, 121 insertions(+), 97 deletions(-) diff --git a/autogen/variables.tf.tmpl b/autogen/variables.tf.tmpl index 7589746a..52ebb3fe 100644 --- a/autogen/variables.tf.tmpl +++ b/autogen/variables.tf.tmpl @@ -145,19 +145,19 @@ variable "health_check_name" { variable "health_check" { description = "Health check to determine whether instances are responsive and able to do work" type = object({ - type = string - initial_delay_sec = number - check_interval_sec = number - healthy_threshold = number - timeout_sec = number - unhealthy_threshold = number - response = string - proxy_header = string - port = number - request = string - request_path = string - host = string - enable_logging = bool + type = optional(string, "") + initial_delay_sec = optional(number, 30) + check_interval_sec = optional(number, 30) + healthy_threshold = optional(number, 1) + timeout_sec = optional(number, 10) + unhealthy_threshold = optional(number, 5) + response = optional(string, "") + proxy_header = optional(string, "NONE") + port = optional(number, 80) + request = optional(string, "") + request_path = optional(string, "/") + host = optional(string, "") + enable_logging = optional(bool, false) }) default = { type = "" diff --git a/examples/compute_instance/disk_snapshot/main.tf b/examples/compute_instance/disk_snapshot/main.tf index 8197a8ef..781ecffd 100644 --- a/examples/compute_instance/disk_snapshot/main.tf +++ b/examples/compute_instance/disk_snapshot/main.tf @@ -27,7 +27,7 @@ data "google_compute_zones" "available" { module "instance_template" { source = "terraform-google-modules/vm/google//modules/instance_template" - version = "~> 10.0" + version = "~> 11.0" region = var.region project_id = var.project_id @@ -59,7 +59,7 @@ module "instance_template" { module "compute_instance" { source = "terraform-google-modules/vm/google//modules/compute_instance" - version = "~> 10.0" + version = "~> 11.0" region = var.region subnetwork = var.subnetwork @@ -70,7 +70,7 @@ module "compute_instance" { module "disk_snapshots" { source = "terraform-google-modules/vm/google//modules/compute_disk_snapshot" - version = "~> 10.0" + version = "~> 11.0" name = "backup-policy-test" project = var.project_id diff --git a/examples/compute_instance/simple/main.tf b/examples/compute_instance/simple/main.tf index 833c996b..cdf21279 100644 --- a/examples/compute_instance/simple/main.tf +++ b/examples/compute_instance/simple/main.tf @@ -16,7 +16,7 @@ module "instance_template" { source = "terraform-google-modules/vm/google//modules/instance_template" - version = "~> 10.0" + version = "~> 11.0" region = var.region project_id = var.project_id @@ -26,7 +26,7 @@ module "instance_template" { module "compute_instance" { source = "terraform-google-modules/vm/google//modules/compute_instance" - version = "~> 10.0" + version = "~> 11.0" region = var.region zone = var.zone diff --git a/examples/instance_template/additional_disks/main.tf b/examples/instance_template/additional_disks/main.tf index 09a41e70..177fa867 100644 --- a/examples/instance_template/additional_disks/main.tf +++ b/examples/instance_template/additional_disks/main.tf @@ -22,7 +22,7 @@ provider "google" { module "instance_template" { source = "terraform-google-modules/vm/google//modules/instance_template" - version = "~> 10.0" + version = "~> 11.0" project_id = var.project_id subnetwork = var.subnetwork diff --git a/examples/instance_template/alias_ip_range/main.tf b/examples/instance_template/alias_ip_range/main.tf index eb3c552d..77cedb8b 100644 --- a/examples/instance_template/alias_ip_range/main.tf +++ b/examples/instance_template/alias_ip_range/main.tf @@ -26,7 +26,7 @@ resource "google_compute_address" "ip_address" { module "instance_template" { source = "terraform-google-modules/vm/google//modules/instance_template" - version = "~> 10.0" + version = "~> 11.0" project_id = var.project_id subnetwork = var.subnetwork diff --git a/examples/instance_template/encrypted_disks/main.tf b/examples/instance_template/encrypted_disks/main.tf index fdbad590..82ee0b2c 100644 --- a/examples/instance_template/encrypted_disks/main.tf +++ b/examples/instance_template/encrypted_disks/main.tf @@ -37,7 +37,7 @@ resource "google_kms_crypto_key" "example-key" { module "instance_template" { source = "terraform-google-modules/vm/google//modules/instance_template" - version = "~> 10.0" + version = "~> 11.0" project_id = var.project_id subnetwork = var.subnetwork diff --git a/examples/instance_template/simple/main.tf b/examples/instance_template/simple/main.tf index 234667aa..827595d9 100644 --- a/examples/instance_template/simple/main.tf +++ b/examples/instance_template/simple/main.tf @@ -33,7 +33,7 @@ locals { module "instance_template" { source = "terraform-google-modules/vm/google//modules/instance_template" - version = "~> 10.0" + version = "~> 11.0" project_id = var.project_id subnetwork = var.subnetwork diff --git a/examples/mig/autoscaler/main.tf b/examples/mig/autoscaler/main.tf index aafdb23a..a41dfdad 100644 --- a/examples/mig/autoscaler/main.tf +++ b/examples/mig/autoscaler/main.tf @@ -28,7 +28,7 @@ provider "google-beta" { module "instance_template" { source = "terraform-google-modules/vm/google//modules/instance_template" - version = "~> 10.0" + version = "~> 11.0" project_id = var.project_id subnetwork = var.subnetwork @@ -37,7 +37,7 @@ module "instance_template" { module "mig" { source = "terraform-google-modules/vm/google//modules/mig" - version = "~> 10.0" + version = "~> 11.0" project_id = var.project_id region = var.region diff --git a/examples/mig/full/main.tf b/examples/mig/full/main.tf index 26e1b8ed..e15001e0 100644 --- a/examples/mig/full/main.tf +++ b/examples/mig/full/main.tf @@ -28,7 +28,7 @@ provider "google-beta" { module "instance_template" { source = "terraform-google-modules/vm/google//modules/instance_template" - version = "~> 10.0" + version = "~> 11.0" name_prefix = "${var.hostname}-instance-template" project_id = var.project_id @@ -58,7 +58,7 @@ module "instance_template" { module "mig" { source = "terraform-google-modules/vm/google//modules/mig" - version = "~> 10.0" + version = "~> 11.0" project_id = var.project_id hostname = var.hostname diff --git a/examples/mig/healthcheck/main.tf b/examples/mig/healthcheck/main.tf index 939ea943..b2d7ea20 100644 --- a/examples/mig/healthcheck/main.tf +++ b/examples/mig/healthcheck/main.tf @@ -52,7 +52,7 @@ resource "google_compute_subnetwork" "main" { module "instance_template" { source = "terraform-google-modules/vm/google//modules/instance_template" - version = "~> 10.0" + version = "~> 11.0" project_id = var.project_id subnetwork = google_compute_subnetwork.main.name @@ -63,7 +63,7 @@ module "instance_template" { module "mig" { source = "terraform-google-modules/vm/google//modules/mig" - version = "~> 10.0" + version = "~> 11.0" project_id = var.project_id instance_template = module.instance_template.self_link @@ -97,3 +97,27 @@ module "mig" { enable_logging = false } } + +module "mig_health_check_optional_fields" { + source = "../../../modules/mig" + + project_id = var.project_id + instance_template = module.instance_template.self_link + region = var.region + autoscaling_enabled = true + min_replicas = 1 + autoscaler_name = "mig-as-optional-fields" + hostname = "mig-as-optional-fields" + + autoscaling_cpu = [ + { + target = 0.4 + predictive_method = null # use default of NONE + }, + ] + + health_check_name = "mig-http-hc" + health_check = { + type = "http" # use default port 80 and path / + } +} diff --git a/examples/mig/simple/main.tf b/examples/mig/simple/main.tf index 0682d230..8fd63248 100644 --- a/examples/mig/simple/main.tf +++ b/examples/mig/simple/main.tf @@ -26,7 +26,7 @@ provider "google-beta" { module "instance_template" { source = "terraform-google-modules/vm/google//modules/instance_template" - version = "~> 10.0" + version = "~> 11.0" project_id = var.project_id subnetwork = var.subnetwork @@ -36,7 +36,7 @@ module "instance_template" { module "mig" { source = "terraform-google-modules/vm/google//modules/mig" - version = "~> 10.0" + version = "~> 11.0" project_id = var.project_id region = var.region diff --git a/examples/mig_stateful/main.tf b/examples/mig_stateful/main.tf index 3910dfd8..6463a530 100644 --- a/examples/mig_stateful/main.tf +++ b/examples/mig_stateful/main.tf @@ -44,7 +44,7 @@ resource "google_compute_subnetwork" "main" { module "instance_template" { source = "terraform-google-modules/vm/google//modules/instance_template" - version = "~> 10.0" + version = "~> 11.0" project_id = var.project_id region = var.region @@ -55,7 +55,7 @@ module "instance_template" { module "mig" { source = "terraform-google-modules/vm/google//modules/mig" - version = "~> 10.0" + version = "~> 11.0" project_id = var.project_id region = var.region diff --git a/examples/mig_with_percent/simple/main.tf b/examples/mig_with_percent/simple/main.tf index 09840e6d..be7b35ec 100644 --- a/examples/mig_with_percent/simple/main.tf +++ b/examples/mig_with_percent/simple/main.tf @@ -28,7 +28,7 @@ provider "google-beta" { module "preemptible_and_regular_instance_templates" { source = "terraform-google-modules/vm/google//modules/preemptible_and_regular_instance_templates" - version = "~> 10.0" + version = "~> 11.0" subnetwork = var.subnetwork service_account = var.service_account @@ -36,7 +36,7 @@ module "preemptible_and_regular_instance_templates" { module "mig_with_percent" { source = "terraform-google-modules/vm/google//modules/mig_with_percent" - version = "~> 10.0" + version = "~> 11.0" region = var.region target_size = 4 diff --git a/examples/preemptible_and_regular_instance_templates/simple/main.tf b/examples/preemptible_and_regular_instance_templates/simple/main.tf index 1286c731..f2277e4c 100644 --- a/examples/preemptible_and_regular_instance_templates/simple/main.tf +++ b/examples/preemptible_and_regular_instance_templates/simple/main.tf @@ -22,7 +22,7 @@ provider "google" { module "preemptible_and_regular_instance_templates" { source = "terraform-google-modules/vm/google//modules/preemptible_and_regular_instance_templates" - version = "~> 10.0" + version = "~> 11.0" subnetwork = var.subnetwork project_id = var.project_id diff --git a/examples/umig/full/main.tf b/examples/umig/full/main.tf index 9a8dc61e..c47bb1bc 100644 --- a/examples/umig/full/main.tf +++ b/examples/umig/full/main.tf @@ -32,7 +32,7 @@ locals { module "instance_template" { source = "terraform-google-modules/vm/google//modules/instance_template" - version = "~> 10.0" + version = "~> 11.0" name_prefix = "${var.hostname}-instance-template" machine_type = var.machine_type @@ -61,7 +61,7 @@ module "instance_template" { module "umig" { source = "terraform-google-modules/vm/google//modules/umig" - version = "~> 10.0" + version = "~> 11.0" project_id = var.project_id subnetwork = var.subnetwork diff --git a/examples/umig/named_ports/main.tf b/examples/umig/named_ports/main.tf index 44e7a7fa..b28cfc3f 100644 --- a/examples/umig/named_ports/main.tf +++ b/examples/umig/named_ports/main.tf @@ -22,7 +22,7 @@ provider "google" { module "instance_template" { source = "terraform-google-modules/vm/google//modules/instance_template" - version = "~> 10.0" + version = "~> 11.0" project_id = var.project_id subnetwork = var.subnetwork @@ -31,7 +31,7 @@ module "instance_template" { module "umig" { source = "terraform-google-modules/vm/google//modules/umig" - version = "~> 10.0" + version = "~> 11.0" project_id = var.project_id subnetwork = var.subnetwork diff --git a/examples/umig/simple/main.tf b/examples/umig/simple/main.tf index 34b644f6..6024202b 100644 --- a/examples/umig/simple/main.tf +++ b/examples/umig/simple/main.tf @@ -22,7 +22,7 @@ provider "google" { module "instance_template" { source = "terraform-google-modules/vm/google//modules/instance_template" - version = "~> 10.0" + version = "~> 11.0" project_id = var.project_id subnetwork = var.subnetwork @@ -31,7 +31,7 @@ module "instance_template" { module "umig" { source = "terraform-google-modules/vm/google//modules/umig" - version = "~> 10.0" + version = "~> 11.0" project_id = var.project_id subnetwork = var.subnetwork diff --git a/examples/umig/static_ips/main.tf b/examples/umig/static_ips/main.tf index f4362151..d0ddce7d 100644 --- a/examples/umig/static_ips/main.tf +++ b/examples/umig/static_ips/main.tf @@ -22,7 +22,7 @@ provider "google" { module "instance_template" { source = "terraform-google-modules/vm/google//modules/instance_template" - version = "~> 10.0" + version = "~> 11.0" project_id = var.project_id subnetwork = var.subnetwork @@ -31,7 +31,7 @@ module "instance_template" { module "umig" { source = "terraform-google-modules/vm/google//modules/umig" - version = "~> 10.0" + version = "~> 11.0" project_id = var.project_id subnetwork = var.subnetwork diff --git a/modules/mig/README.md b/modules/mig/README.md index 216bcaa3..2810fcd9 100644 --- a/modules/mig/README.md +++ b/modules/mig/README.md @@ -28,7 +28,7 @@ The current version is 2.X. The following guides are available to assist with up | cooldown\_period | The number of seconds that the autoscaler should wait before it starts collecting information from a new instance. | `number` | `60` | no | | distribution\_policy\_target\_shape | MIG target distribution shape (EVEN, BALANCED, ANY, ANY\_SINGLE\_ZONE) | `string` | `null` | no | | distribution\_policy\_zones | The distribution policy, i.e. which zone(s) should instances be create in. Default is all zones in given region. | `list(string)` | `[]` | no | -| health\_check | Health check to determine whether instances are responsive and able to do work |
object({
type = string
initial_delay_sec = number
check_interval_sec = number
healthy_threshold = number
timeout_sec = number
unhealthy_threshold = number
response = string
proxy_header = string
port = number
request = string
request_path = string
host = string
enable_logging = bool
})
|
{
"check_interval_sec": 30,
"enable_logging": false,
"healthy_threshold": 1,
"host": "",
"initial_delay_sec": 30,
"port": 80,
"proxy_header": "NONE",
"request": "",
"request_path": "/",
"response": "",
"timeout_sec": 10,
"type": "",
"unhealthy_threshold": 5
}
| no | +| health\_check | Health check to determine whether instances are responsive and able to do work |
object({
type = optional(string, "")
initial_delay_sec = optional(number, 30)
check_interval_sec = optional(number, 30)
healthy_threshold = optional(number, 1)
timeout_sec = optional(number, 10)
unhealthy_threshold = optional(number, 5)
response = optional(string, "")
proxy_header = optional(string, "NONE")
port = optional(number, 80)
request = optional(string, "")
request_path = optional(string, "/")
host = optional(string, "")
enable_logging = optional(bool, false)
})
|
{
"check_interval_sec": 30,
"enable_logging": false,
"healthy_threshold": 1,
"host": "",
"initial_delay_sec": 30,
"port": 80,
"proxy_header": "NONE",
"request": "",
"request_path": "/",
"response": "",
"timeout_sec": 10,
"type": "",
"unhealthy_threshold": 5
}
| no | | health\_check\_name | Health check name. When variable is empty, name will be derived from var.hostname. | `string` | `""` | no | | hostname | Hostname prefix for instances | `string` | `"default"` | no | | instance\_template | Instance template self\_link used to create compute instances | `string` | n/a | yes | diff --git a/modules/mig/metadata.yaml b/modules/mig/metadata.yaml index bc0c257e..f69cc390 100644 --- a/modules/mig/metadata.yaml +++ b/modules/mig/metadata.yaml @@ -133,19 +133,19 @@ spec: description: Health check to determine whether instances are responsive and able to do work varType: |- object({ - type = string - initial_delay_sec = number - check_interval_sec = number - healthy_threshold = number - timeout_sec = number - unhealthy_threshold = number - response = string - proxy_header = string - port = number - request = string - request_path = string - host = string - enable_logging = bool + type = optional(string, "") + initial_delay_sec = optional(number, 30) + check_interval_sec = optional(number, 30) + healthy_threshold = optional(number, 1) + timeout_sec = optional(number, 10) + unhealthy_threshold = optional(number, 5) + response = optional(string, "") + proxy_header = optional(string, "NONE") + port = optional(number, 80) + request = optional(string, "") + request_path = optional(string, "/") + host = optional(string, "") + enable_logging = optional(bool, false) }) defaultValue: check_interval_sec: 30 diff --git a/modules/mig/variables.tf b/modules/mig/variables.tf index e440ee2e..cfcffd80 100644 --- a/modules/mig/variables.tf +++ b/modules/mig/variables.tf @@ -127,19 +127,19 @@ variable "health_check_name" { variable "health_check" { description = "Health check to determine whether instances are responsive and able to do work" type = object({ - type = string - initial_delay_sec = number - check_interval_sec = number - healthy_threshold = number - timeout_sec = number - unhealthy_threshold = number - response = string - proxy_header = string - port = number - request = string - request_path = string - host = string - enable_logging = bool + type = optional(string, "") + initial_delay_sec = optional(number, 30) + check_interval_sec = optional(number, 30) + healthy_threshold = optional(number, 1) + timeout_sec = optional(number, 10) + unhealthy_threshold = optional(number, 5) + response = optional(string, "") + proxy_header = optional(string, "NONE") + port = optional(number, 80) + request = optional(string, "") + request_path = optional(string, "/") + host = optional(string, "") + enable_logging = optional(bool, false) }) default = { type = "" diff --git a/modules/mig_with_percent/README.md b/modules/mig_with_percent/README.md index 5e10aec7..be680ad0 100644 --- a/modules/mig_with_percent/README.md +++ b/modules/mig_with_percent/README.md @@ -27,7 +27,7 @@ The current version is 2.X. The following guides are available to assist with up | cooldown\_period | The number of seconds that the autoscaler should wait before it starts collecting information from a new instance. | `number` | `60` | no | | distribution\_policy\_target\_shape | MIG target distribution shape (EVEN, BALANCED, ANY, ANY\_SINGLE\_ZONE) | `string` | `null` | no | | distribution\_policy\_zones | The distribution policy, i.e. which zone(s) should instances be create in. Default is all zones in given region. | `list(string)` | `[]` | no | -| health\_check | Health check to determine whether instances are responsive and able to do work |
object({
type = string
initial_delay_sec = number
check_interval_sec = number
healthy_threshold = number
timeout_sec = number
unhealthy_threshold = number
response = string
proxy_header = string
port = number
request = string
request_path = string
host = string
enable_logging = bool
})
|
{
"check_interval_sec": 30,
"enable_logging": false,
"healthy_threshold": 1,
"host": "",
"initial_delay_sec": 30,
"port": 80,
"proxy_header": "NONE",
"request": "",
"request_path": "/",
"response": "",
"timeout_sec": 10,
"type": "",
"unhealthy_threshold": 5
}
| no | +| health\_check | Health check to determine whether instances are responsive and able to do work |
object({
type = optional(string, "")
initial_delay_sec = optional(number, 30)
check_interval_sec = optional(number, 30)
healthy_threshold = optional(number, 1)
timeout_sec = optional(number, 10)
unhealthy_threshold = optional(number, 5)
response = optional(string, "")
proxy_header = optional(string, "NONE")
port = optional(number, 80)
request = optional(string, "")
request_path = optional(string, "/")
host = optional(string, "")
enable_logging = optional(bool, false)
})
|
{
"check_interval_sec": 30,
"enable_logging": false,
"healthy_threshold": 1,
"host": "",
"initial_delay_sec": 30,
"port": 80,
"proxy_header": "NONE",
"request": "",
"request_path": "/",
"response": "",
"timeout_sec": 10,
"type": "",
"unhealthy_threshold": 5
}
| no | | health\_check\_name | Health check name. When variable is empty, name will be derived from var.hostname. | `string` | `""` | no | | hostname | Hostname prefix for instances | `string` | `"default"` | no | | instance\_template\_initial\_version | Instance template self\_link used to create compute instances for the initial version | `string` | n/a | yes | diff --git a/modules/mig_with_percent/metadata.yaml b/modules/mig_with_percent/metadata.yaml index 01e4aff9..bcb12bde 100644 --- a/modules/mig_with_percent/metadata.yaml +++ b/modules/mig_with_percent/metadata.yaml @@ -133,19 +133,19 @@ spec: description: Health check to determine whether instances are responsive and able to do work varType: |- object({ - type = string - initial_delay_sec = number - check_interval_sec = number - healthy_threshold = number - timeout_sec = number - unhealthy_threshold = number - response = string - proxy_header = string - port = number - request = string - request_path = string - host = string - enable_logging = bool + type = optional(string, "") + initial_delay_sec = optional(number, 30) + check_interval_sec = optional(number, 30) + healthy_threshold = optional(number, 1) + timeout_sec = optional(number, 10) + unhealthy_threshold = optional(number, 5) + response = optional(string, "") + proxy_header = optional(string, "NONE") + port = optional(number, 80) + request = optional(string, "") + request_path = optional(string, "/") + host = optional(string, "") + enable_logging = optional(bool, false) }) defaultValue: check_interval_sec: 30 diff --git a/modules/mig_with_percent/variables.tf b/modules/mig_with_percent/variables.tf index 759cd9de..99f1f08f 100644 --- a/modules/mig_with_percent/variables.tf +++ b/modules/mig_with_percent/variables.tf @@ -137,19 +137,19 @@ variable "health_check_name" { variable "health_check" { description = "Health check to determine whether instances are responsive and able to do work" type = object({ - type = string - initial_delay_sec = number - check_interval_sec = number - healthy_threshold = number - timeout_sec = number - unhealthy_threshold = number - response = string - proxy_header = string - port = number - request = string - request_path = string - host = string - enable_logging = bool + type = optional(string, "") + initial_delay_sec = optional(number, 30) + check_interval_sec = optional(number, 30) + healthy_threshold = optional(number, 1) + timeout_sec = optional(number, 10) + unhealthy_threshold = optional(number, 5) + response = optional(string, "") + proxy_header = optional(string, "NONE") + port = optional(number, 80) + request = optional(string, "") + request_path = optional(string, "/") + host = optional(string, "") + enable_logging = optional(bool, false) }) default = { type = "" From 5e7f85c2866536e8f1663faefed6fcfd47f9e01c Mon Sep 17 00:00:00 2001 From: Rauny Date: Sat, 24 Feb 2024 13:37:54 +0100 Subject: [PATCH 2/7] Update main.tf --- examples/mig/healthcheck/main.tf | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/mig/healthcheck/main.tf b/examples/mig/healthcheck/main.tf index b2d7ea20..346f1b38 100644 --- a/examples/mig/healthcheck/main.tf +++ b/examples/mig/healthcheck/main.tf @@ -99,7 +99,8 @@ module "mig" { } module "mig_health_check_optional_fields" { - source = "../../../modules/mig" + source = "terraform-google-modules/vm/google//modules/mig" + version = "~> 11.0" project_id = var.project_id instance_template = module.instance_template.self_link From e6bde772c30d47232a7ef3bc1a851db0e8a6032d Mon Sep 17 00:00:00 2001 From: Rauny Date: Mon, 26 Feb 2024 08:44:38 +0100 Subject: [PATCH 3/7] fix: bump tf min version --- autogen/versions.tf.tmpl | 2 +- modules/mig/metadata.yaml | 2 +- modules/mig/versions.tf | 2 +- modules/mig_with_percent/metadata.yaml | 2 +- modules/mig_with_percent/versions.tf | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/autogen/versions.tf.tmpl b/autogen/versions.tf.tmpl index d2efe19e..be0cedae 100644 --- a/autogen/versions.tf.tmpl +++ b/autogen/versions.tf.tmpl @@ -15,7 +15,7 @@ */ terraform { - required_version = ">=0.13.0" + required_version = ">=1.3.0" required_providers { google = { source = "hashicorp/google" diff --git a/modules/mig/metadata.yaml b/modules/mig/metadata.yaml index f69cc390..0293e526 100644 --- a/modules/mig/metadata.yaml +++ b/modules/mig/metadata.yaml @@ -28,7 +28,7 @@ spec: version: 11.0.0 actuationTool: flavor: Terraform - version: ">=0.13.0" + version: ">=1.3.0" description: {} content: examples: diff --git a/modules/mig/versions.tf b/modules/mig/versions.tf index d939e3dc..275abccd 100644 --- a/modules/mig/versions.tf +++ b/modules/mig/versions.tf @@ -15,7 +15,7 @@ */ terraform { - required_version = ">=0.13.0" + required_version = ">=1.3.0" required_providers { google = { source = "hashicorp/google" diff --git a/modules/mig_with_percent/metadata.yaml b/modules/mig_with_percent/metadata.yaml index bcb12bde..bdc90294 100644 --- a/modules/mig_with_percent/metadata.yaml +++ b/modules/mig_with_percent/metadata.yaml @@ -28,7 +28,7 @@ spec: version: 11.0.0 actuationTool: flavor: Terraform - version: ">=0.13.0" + version: ">=1.3.0" description: {} content: examples: diff --git a/modules/mig_with_percent/versions.tf b/modules/mig_with_percent/versions.tf index a6d600b5..d959dfc2 100644 --- a/modules/mig_with_percent/versions.tf +++ b/modules/mig_with_percent/versions.tf @@ -15,7 +15,7 @@ */ terraform { - required_version = ">=0.13.0" + required_version = ">=1.3.0" required_providers { google = { source = "hashicorp/google" From 34b26d8e0cfe75cebc805bd6ae4a60a01f89481d Mon Sep 17 00:00:00 2001 From: Rauny Date: Mon, 26 Feb 2024 20:12:49 +0100 Subject: [PATCH 4/7] fix: integration tests --- examples/mig/healthcheck/main.tf | 2 +- test/fixtures/mig/healthcheck/versions.tf | 2 +- .../controls/mig_healthcheck.rb | 126 +++++++++++++++++- 3 files changed, 127 insertions(+), 3 deletions(-) diff --git a/examples/mig/healthcheck/main.tf b/examples/mig/healthcheck/main.tf index 346f1b38..35a72abe 100644 --- a/examples/mig/healthcheck/main.tf +++ b/examples/mig/healthcheck/main.tf @@ -106,7 +106,7 @@ module "mig_health_check_optional_fields" { instance_template = module.instance_template.self_link region = var.region autoscaling_enabled = true - min_replicas = 1 + min_replicas = 2 autoscaler_name = "mig-as-optional-fields" hostname = "mig-as-optional-fields" diff --git a/test/fixtures/mig/healthcheck/versions.tf b/test/fixtures/mig/healthcheck/versions.tf index fb3fee63..ad68a2c4 100644 --- a/test/fixtures/mig/healthcheck/versions.tf +++ b/test/fixtures/mig/healthcheck/versions.tf @@ -15,5 +15,5 @@ */ terraform { - required_version = ">=0.12.6" + required_version = ">=1.3.0" } diff --git a/test/integration/mig_healthcheck/controls/mig_healthcheck.rb b/test/integration/mig_healthcheck/controls/mig_healthcheck.rb index 5c089be7..cac319a7 100644 --- a/test/integration/mig_healthcheck/controls/mig_healthcheck.rb +++ b/test/integration/mig_healthcheck/controls/mig_healthcheck.rb @@ -40,6 +40,25 @@ end end + describe command("gcloud --project=#{project_id} compute instances list --format=json --filter='name~^mig-as-optional-fields*'") do + its(:exit_status) { should eq 0 } + its(:stderr) { should eq '' } + + let!(:data) do + if subject.exit_status == 0 + JSON.parse(subject.stdout) + else + [] + end + end + + describe "number of instances" do + it "should be #{expected_instances}" do + expect(data.length).to eq(expected_instances) + end + end + end + describe command("gcloud --project=#{project_id} compute instance-groups list --format=json --filter='name~^mig-as*'") do its(:exit_status) { should eq 0 } its(:stderr) { should eq '' } @@ -59,6 +78,25 @@ end end + describe command("gcloud --project=#{project_id} compute instance-groups list --format=json --filter='name~^mig-as-optional-fields*'") do + its(:exit_status) { should eq 0 } + its(:stderr) { should eq '' } + + let!(:data) do + if subject.exit_status == 0 + JSON.parse(subject.stdout) + else + [] + end + end + + describe "number of instance groups" do + it "should be #{expected_instance_groups}" do + expect(data.length).to eq(expected_instance_groups) + end + end + end + describe command("gcloud --project=#{project_id} compute instance-groups managed list --format=json --filter='name~^mig-as*'") do its(:exit_status) { should eq 0 } its(:stderr) { should eq '' } @@ -96,6 +134,43 @@ end end + describe command("gcloud --project=#{project_id} compute instance-groups managed list --format=json --filter='name~^mig-as-optional-fields*'") do + its(:exit_status) { should eq 0 } + its(:stderr) { should eq '' } + + let!(:data) do + if subject.exit_status == 0 + JSON.parse(subject.stdout) + else + [] + end + end + + describe "number of instance groups" do + it "should be #{expected_instance_groups}" do + expect(data.length).to eq(expected_instance_groups) + end + end + + describe "autoscaling" do + it "should be enabled" do + expect(data[0]['autoscaled']).to eq("yes") + end + end + + describe "autoscaler scaling policy" do + it "minNumReplicas should be 4" do + expect(data[0]['autoscaler']['autoscalingPolicy']['minNumReplicas']).to eq(2) + end + end + + describe "autoscaler scaling policy" do + it "cpuUtilization target should be 0.4" do + expect(data[0]['autoscaler']['autoscalingPolicy']['cpuUtilization']['utilizationTarget']).to eq(0.4) + end + end + end + describe command("gcloud --project=#{project_id} compute health-checks list --format=json --filter='name~^mig-https-hc*'") do its(:exit_status) { should eq 0 } its(:stderr) { should eq '' } @@ -140,7 +215,56 @@ describe "https health check settings" do it "unhealthyThreshold should be 2" do - expect(data[0]['healthyThreshold']).to eq(2) + expect(data[0]['unhealthyThreshold']).to eq(2) + end + end + end + + describe command("gcloud --project=#{project_id} compute health-checks list --format=json --filter='name~^mig-http-hc*'") do + its(:exit_status) { should eq 0 } + its(:stderr) { should eq '' } + + let!(:data) do + if subject.exit_status == 0 + JSON.parse(subject.stdout) + else + [] + end + end + + describe "http health check settings" do + it "port should be 80" do + expect(data[0]['httpHealthCheck']['port']).to eq(80) + end + end + + describe "http health check settings" do + it "requestPath should be /" do + expect(data[0]['httpHealthCheck']['requestPath']).to eq('/') + end + end + + describe "http health check settings" do + it "proxyHeader should be NONE" do + expect(data[0]['httpHealthCheck']['proxyHeader']).to eq('NONE') + end + end + + describe "http health check settings" do + it "healthyThreshold should be 1" do + expect(data[0]['healthyThreshold']).to eq(1) + end + end + + describe "http health check settings" do + it "checkIntervalSec should be 5" do + expect(data[0]['checkIntervalSec']).to eq(30) + end + end + + describe "http health check settings" do + it "unhealthyThreshold should be 2" do + expect(data[0]['unhealthyThreshold']).to eq(5) end end end From 84ad11605482345c42623c28b570f7307f7f4a5e Mon Sep 17 00:00:00 2001 From: Rauny Date: Mon, 26 Feb 2024 20:16:50 +0100 Subject: [PATCH 5/7] fix: integration tests --- test/integration/mig_healthcheck/controls/mig_healthcheck.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/mig_healthcheck/controls/mig_healthcheck.rb b/test/integration/mig_healthcheck/controls/mig_healthcheck.rb index cac319a7..bce19c2c 100644 --- a/test/integration/mig_healthcheck/controls/mig_healthcheck.rb +++ b/test/integration/mig_healthcheck/controls/mig_healthcheck.rb @@ -257,13 +257,13 @@ end describe "http health check settings" do - it "checkIntervalSec should be 5" do + it "checkIntervalSec should be 30" do expect(data[0]['checkIntervalSec']).to eq(30) end end describe "http health check settings" do - it "unhealthyThreshold should be 2" do + it "unhealthyThreshold should be 5" do expect(data[0]['unhealthyThreshold']).to eq(5) end end From 121ca907ba3103131de852a56153313653ab9999 Mon Sep 17 00:00:00 2001 From: Rauny Date: Tue, 27 Feb 2024 08:48:24 +0100 Subject: [PATCH 6/7] fix: integ tests --- test/integration/mig_healthcheck/controls/mig_healthcheck.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/integration/mig_healthcheck/controls/mig_healthcheck.rb b/test/integration/mig_healthcheck/controls/mig_healthcheck.rb index bce19c2c..54170ca7 100644 --- a/test/integration/mig_healthcheck/controls/mig_healthcheck.rb +++ b/test/integration/mig_healthcheck/controls/mig_healthcheck.rb @@ -122,7 +122,7 @@ end describe "autoscaler scaling policy" do - it "minNumReplicas should be 4" do + it "minNumReplicas should be 2" do expect(data[0]['autoscaler']['autoscalingPolicy']['minNumReplicas']).to eq(2) end end @@ -159,7 +159,7 @@ end describe "autoscaler scaling policy" do - it "minNumReplicas should be 4" do + it "minNumReplicas should be 2" do expect(data[0]['autoscaler']['autoscalingPolicy']['minNumReplicas']).to eq(2) end end From 8ba1e5d608c24ce0e85bc859ecf64a7fc4a86a58 Mon Sep 17 00:00:00 2001 From: Rauny Date: Fri, 1 Mar 2024 13:13:16 +0100 Subject: [PATCH 7/7] Update README.md --- README.md | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 208945fe..0e48c413 100644 --- a/README.md +++ b/README.md @@ -7,12 +7,20 @@ This is a collection of opinionated submodules that can be used as building bloc * [Unmanaged instance group](modules/umig) ## Compatibility -This module is meant for use with Terraform 0.13+ and tested using Terraform 1.0+. If you find incompatibilities using Terraform >=0.13, please open an issue. - If you haven't -[upgraded](https://www.terraform.io/upgrade-guides/0-13.html) and need a Terraform +This module is meant for use with Terraform 1.3+ and tested using Terraform 1.3+. If you find incompatibilities using Terraform >=1.3, please open an issue. + +If you haven't [upgraded](https://www.terraform.io/upgrade-guides/0-13.html) and need a Terraform 0.12.x-compatible version of this module, the last released version intended for Terraform 0.12.x is [v5.1.0](https://registry.terraform.io/modules/terraform-google-modules/-vm/google/v5.1.0). +Terraform compatibility: + +| Module Version | Terraform Version Required | +|-----------------------|----------------------------| +| >= 12.0.0 | >= 1.3.0 | +| >= 6.0.0 and < 12.0.0 | 0.13 or greater | +| <= 5.1.0 | 0.12 | + ## Examples Examples of how to use these modules can be found in the [examples](examples) folder.