From 2b31071cb3dacf2e5b68e2a71b0499ce87880423 Mon Sep 17 00:00:00 2001 From: Eric Zhao Date: Tue, 29 Nov 2022 12:02:15 +1000 Subject: [PATCH] feat!: support health check logging (#283) * feat: support health check logging * fix: add enable logging in example Co-authored-by: Bharath KKB --- autogen/main.tf.tmpl | 8 ++++++++ autogen/variables.tf.tmpl | 2 ++ autogen/versions.tf.tmpl | 4 ++-- examples/mig/full/variables.tf | 2 ++ examples/mig/healthcheck/main.tf | 1 + examples/mig/healthcheck/versions.tf | 2 +- modules/compute_disk_snapshot/versions.tf | 2 +- modules/compute_instance/versions.tf | 2 +- modules/instance_template/versions.tf | 2 +- modules/mig/README.md | 2 +- modules/mig/main.tf | 8 ++++++++ modules/mig/variables.tf | 2 ++ modules/mig/versions.tf | 4 ++-- modules/mig_with_percent/README.md | 2 +- modules/mig_with_percent/main.tf | 8 ++++++++ modules/mig_with_percent/variables.tf | 2 ++ modules/mig_with_percent/versions.tf | 4 ++-- .../versions.tf | 4 ++-- modules/umig/versions.tf | 2 +- test/setup/versions.tf | 6 +++--- 20 files changed, 51 insertions(+), 18 deletions(-) diff --git a/autogen/main.tf.tmpl b/autogen/main.tf.tmpl index 2c1619f6..58d87549 100644 --- a/autogen/main.tf.tmpl +++ b/autogen/main.tf.tmpl @@ -218,6 +218,10 @@ resource "google_compute_health_check" "http" { response = var.health_check["response"] proxy_header = var.health_check["proxy_header"] } + + log_config { + enable = var.health_check["enable_logging"] + } } resource "google_compute_health_check" "tcp" { @@ -236,4 +240,8 @@ resource "google_compute_health_check" "tcp" { response = var.health_check["response"] proxy_header = var.health_check["proxy_header"] } + + log_config { + enable = var.health_check["enable_logging"] + } } diff --git a/autogen/variables.tf.tmpl b/autogen/variables.tf.tmpl index ddee4e89..45c5b193 100644 --- a/autogen/variables.tf.tmpl +++ b/autogen/variables.tf.tmpl @@ -130,6 +130,7 @@ variable "health_check" { request = string request_path = string host = string + enable_logging = bool }) default = { type = "" @@ -144,6 +145,7 @@ variable "health_check" { request = "" request_path = "/" host = "" + enable_logging = false } } diff --git a/autogen/versions.tf.tmpl b/autogen/versions.tf.tmpl index 334249a0..fe8315d5 100644 --- a/autogen/versions.tf.tmpl +++ b/autogen/versions.tf.tmpl @@ -17,8 +17,8 @@ terraform { required_version = ">=0.13.0" required_providers { - google = ">= 3.43, < 5.0" - google-beta = ">= 3.43, < 5.0" + google = ">= 3.71, < 5.0" + google-beta = ">= 3.71, < 5.0" } provider_meta "google" { module_name = "blueprints/terraform/terraform-google-vm:{% if mig %}mig{% else %}mig_with_percent{% endif %}/v7.9.0" diff --git a/examples/mig/full/variables.tf b/examples/mig/full/variables.tf index a4a70275..69a2c8a7 100644 --- a/examples/mig/full/variables.tf +++ b/examples/mig/full/variables.tf @@ -217,6 +217,7 @@ variable "health_check" { request = string request_path = string host = string + enable_logging = string }) default = { type = "http" @@ -231,6 +232,7 @@ variable "health_check" { request = "" request_path = "/" host = "" + enable_logging = false } } diff --git a/examples/mig/healthcheck/main.tf b/examples/mig/healthcheck/main.tf index 9450901f..f5b2bd35 100644 --- a/examples/mig/healthcheck/main.tf +++ b/examples/mig/healthcheck/main.tf @@ -90,5 +90,6 @@ module "mig" { request = "" request_path = "/" host = "localhost" + enable_logging = false } } diff --git a/examples/mig/healthcheck/versions.tf b/examples/mig/healthcheck/versions.tf index 2ceebb96..32e6123d 100644 --- a/examples/mig/healthcheck/versions.tf +++ b/examples/mig/healthcheck/versions.tf @@ -27,7 +27,7 @@ terraform { } random = { source = "hashicorp/random" - version = "~> 2.2" + version = "~> 3.4" } } } diff --git a/modules/compute_disk_snapshot/versions.tf b/modules/compute_disk_snapshot/versions.tf index 4f4bfe3f..02da8ffb 100644 --- a/modules/compute_disk_snapshot/versions.tf +++ b/modules/compute_disk_snapshot/versions.tf @@ -17,7 +17,7 @@ terraform { required_version = ">=0.13.0" required_providers { - google = ">= 3.43, < 5.0" + google = ">= 3.71, < 5.0" null = ">= 2.1" } provider_meta "google" { diff --git a/modules/compute_instance/versions.tf b/modules/compute_instance/versions.tf index 9f99a1a3..dfa0d217 100644 --- a/modules/compute_instance/versions.tf +++ b/modules/compute_instance/versions.tf @@ -17,7 +17,7 @@ terraform { required_version = ">=0.13.0" required_providers { - google = ">= 3.43, < 5.0" + google = ">= 3.71, < 5.0" } provider_meta "google" { module_name = "blueprints/terraform/terraform-google-vm:compute_instance/v7.9.0" diff --git a/modules/instance_template/versions.tf b/modules/instance_template/versions.tf index 7da41506..9cebd1fd 100644 --- a/modules/instance_template/versions.tf +++ b/modules/instance_template/versions.tf @@ -17,7 +17,7 @@ terraform { required_version = ">=0.13.0" required_providers { - google = ">= 3.43, < 5.0" + google = ">= 3.71, < 5.0" } provider_meta "google" { module_name = "blueprints/terraform/terraform-google-vm:instance_template/v7.9.0" diff --git a/modules/mig/README.md b/modules/mig/README.md index c9317805..3688c9f2 100644 --- a/modules/mig/README.md +++ b/modules/mig/README.md @@ -27,7 +27,7 @@ The current version is 2.X. The following guides are available to assist with up | autoscaling\_scale\_in\_control | Autoscaling, scale-in control block. https://www.terraform.io/docs/providers/google/r/compute_autoscaler#scale_in_control |
object({
fixed_replicas = number
percent_replicas = number
time_window_sec = number
})
|
{
"fixed_replicas": null,
"percent_replicas": null,
"time_window_sec": null
}
| no | | 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\_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
})
|
{
"check_interval_sec": 30,
"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 = 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\_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 | `any` | n/a | yes | diff --git a/modules/mig/main.tf b/modules/mig/main.tf index 76fc9194..7464e7fd 100644 --- a/modules/mig/main.tf +++ b/modules/mig/main.tf @@ -198,6 +198,10 @@ resource "google_compute_health_check" "http" { response = var.health_check["response"] proxy_header = var.health_check["proxy_header"] } + + log_config { + enable = var.health_check["enable_logging"] + } } resource "google_compute_health_check" "tcp" { @@ -216,4 +220,8 @@ resource "google_compute_health_check" "tcp" { response = var.health_check["response"] proxy_header = var.health_check["proxy_header"] } + + log_config { + enable = var.health_check["enable_logging"] + } } diff --git a/modules/mig/variables.tf b/modules/mig/variables.tf index 8f6b51ad..1cfaa7b9 100644 --- a/modules/mig/variables.tf +++ b/modules/mig/variables.tf @@ -115,6 +115,7 @@ variable "health_check" { request = string request_path = string host = string + enable_logging = bool }) default = { type = "" @@ -129,6 +130,7 @@ variable "health_check" { request = "" request_path = "/" host = "" + enable_logging = false } } diff --git a/modules/mig/versions.tf b/modules/mig/versions.tf index 15a4e321..8684a4a9 100644 --- a/modules/mig/versions.tf +++ b/modules/mig/versions.tf @@ -17,8 +17,8 @@ terraform { required_version = ">=0.13.0" required_providers { - google = ">= 3.43, < 5.0" - google-beta = ">= 3.43, < 5.0" + google = ">= 3.71, < 5.0" + google-beta = ">= 3.71, < 5.0" } provider_meta "google" { module_name = "blueprints/terraform/terraform-google-vm:mig/v7.9.0" diff --git a/modules/mig_with_percent/README.md b/modules/mig_with_percent/README.md index f05113ba..57e3d9ea 100644 --- a/modules/mig_with_percent/README.md +++ b/modules/mig_with_percent/README.md @@ -26,7 +26,7 @@ The current version is 2.X. The following guides are available to assist with up | autoscaling\_scale\_in\_control | Autoscaling, scale-in control block. https://www.terraform.io/docs/providers/google/r/compute_autoscaler#scale_in_control |
object({
fixed_replicas = number
percent_replicas = number
time_window_sec = number
})
|
{
"fixed_replicas": null,
"percent_replicas": null,
"time_window_sec": null
}
| no | | 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\_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
})
|
{
"check_interval_sec": 30,
"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 = 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\_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 | `any` | n/a | yes | diff --git a/modules/mig_with_percent/main.tf b/modules/mig_with_percent/main.tf index 3ad4ec2a..ed8d8fc0 100644 --- a/modules/mig_with_percent/main.tf +++ b/modules/mig_with_percent/main.tf @@ -209,6 +209,10 @@ resource "google_compute_health_check" "http" { response = var.health_check["response"] proxy_header = var.health_check["proxy_header"] } + + log_config { + enable = var.health_check["enable_logging"] + } } resource "google_compute_health_check" "tcp" { @@ -227,4 +231,8 @@ resource "google_compute_health_check" "tcp" { response = var.health_check["response"] proxy_header = var.health_check["proxy_header"] } + + log_config { + enable = var.health_check["enable_logging"] + } } diff --git a/modules/mig_with_percent/variables.tf b/modules/mig_with_percent/variables.tf index 9d3ac787..be6285b3 100644 --- a/modules/mig_with_percent/variables.tf +++ b/modules/mig_with_percent/variables.tf @@ -123,6 +123,7 @@ variable "health_check" { request = string request_path = string host = string + enable_logging = bool }) default = { type = "" @@ -137,6 +138,7 @@ variable "health_check" { request = "" request_path = "/" host = "" + enable_logging = false } } diff --git a/modules/mig_with_percent/versions.tf b/modules/mig_with_percent/versions.tf index b7924428..f97be1bf 100644 --- a/modules/mig_with_percent/versions.tf +++ b/modules/mig_with_percent/versions.tf @@ -17,8 +17,8 @@ terraform { required_version = ">=0.13.0" required_providers { - google = ">= 3.43, < 5.0" - google-beta = ">= 3.43, < 5.0" + google = ">= 3.71, < 5.0" + google-beta = ">= 3.71, < 5.0" } provider_meta "google" { module_name = "blueprints/terraform/terraform-google-vm:mig_with_percent/v7.9.0" diff --git a/modules/preemptible_and_regular_instance_templates/versions.tf b/modules/preemptible_and_regular_instance_templates/versions.tf index 03745576..2d3d7df4 100644 --- a/modules/preemptible_and_regular_instance_templates/versions.tf +++ b/modules/preemptible_and_regular_instance_templates/versions.tf @@ -17,8 +17,8 @@ terraform { required_version = ">=0.13.0" required_providers { - google = ">= 3.43, < 5.0" - google-beta = ">= 3.43, < 5.0" + google = ">= 3.71, < 5.0" + google-beta = ">= 3.71, < 5.0" } provider_meta "google" { module_name = "blueprints/terraform/terraform-google-vm:preemptible_and_regular_instance_templates/v7.9.0" diff --git a/modules/umig/versions.tf b/modules/umig/versions.tf index f5da6b01..e430355b 100644 --- a/modules/umig/versions.tf +++ b/modules/umig/versions.tf @@ -17,7 +17,7 @@ terraform { required_version = ">=0.13.0" required_providers { - google = ">= 3.43, < 5.0" + google = ">= 3.71, < 5.0" } provider_meta "google" { module_name = "blueprints/terraform/terraform-google-vm:umig/v7.9.0" diff --git a/test/setup/versions.tf b/test/setup/versions.tf index fd0a2d93..1e09429c 100644 --- a/test/setup/versions.tf +++ b/test/setup/versions.tf @@ -19,11 +19,11 @@ terraform { required_providers { google = { source = "hashicorp/google" - version = ">= 3.0, < 5.0" + version = ">= 3.71, < 5.0" } google-beta = { source = "hashicorp/google-beta" - version = ">= 3.0, < 5.0" + version = ">= 3.71, < 5.0" } null = { source = "hashicorp/null" @@ -31,7 +31,7 @@ terraform { } random = { source = "hashicorp/random" - version = "~> 2.2" + version = "~> 3.4" } } }