From 489cd9dddb95b1bd4cf92b638d387b0c5a72b8ce Mon Sep 17 00:00:00 2001 From: Adit Sinha Date: Wed, 23 Feb 2022 12:33:41 -0500 Subject: [PATCH 1/3] Add option to create an HTTPS health check concat health check syntax copied from https://github.com/terraform-google-modules/terraform-google-vm/blob/v0.1.0/modules/mig/main.tf --- main.tf | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index 665d365..79294c5 100644 --- a/main.tf +++ b/main.tf @@ -45,7 +45,11 @@ resource "google_compute_forwarding_rule" "default" { resource "google_compute_region_backend_service" "default" { project = var.project - name = var.health_check["type"] == "tcp" ? "${var.name}-with-tcp-hc" : "${var.name}-with-http-hc" + name = { + "tcp" = "${var.name}-with-tcp-hc", + "http" = "${var.name}-with-http-hc", + "https" = "${var.name}-with-https-hc", + }[var.health_check["type"]] region = var.region protocol = var.ip_protocol # Do not try to add timeout_sec, as it is has no impact. See https://github.com/terraform-google-modules/terraform-google-lb-internal/issues/53#issuecomment-893427675 @@ -59,7 +63,7 @@ resource "google_compute_region_backend_service" "default" { failover = lookup(backend.value, "failover", null) } } - health_checks = [var.health_check["type"] == "tcp" ? google_compute_health_check.tcp[0].self_link : google_compute_health_check.http[0].self_link] + health_checks = concat(google_compute_health_check.tcp.*.self_link, google_compute_health_check.http.*.self_link, google_compute_health_check.https.*.self_link) } resource "google_compute_health_check" "tcp" { @@ -116,6 +120,34 @@ resource "google_compute_health_check" "http" { } } } + +resource "google_compute_health_check" "https" { + provider = google-beta + count = var.health_check["type"] == "https" ? 1 : 0 + project = var.project + name = "${var.name}-hc-https" + + timeout_sec = var.health_check["timeout_sec"] + check_interval_sec = var.health_check["check_interval_sec"] + healthy_threshold = var.health_check["healthy_threshold"] + unhealthy_threshold = var.health_check["unhealthy_threshold"] + + http_health_check { + port = var.health_check["port"] + request_path = var.health_check["request_path"] + host = var.health_check["host"] + response = var.health_check["response"] + port_name = var.health_check["port_name"] + proxy_header = var.health_check["proxy_header"] + } + + dynamic "log_config" { + for_each = var.health_check["enable_log"] ? [true] : [] + content { + enable = true + } + } +} resource "google_compute_firewall" "default-ilb-fw" { count = var.create_backend_firewall ? 1 : 0 From 0f9230ace0ce2cf862e6e30f0bb28e32dc86c0fd Mon Sep 17 00:00:00 2001 From: Adit Sinha Date: Wed, 23 Feb 2022 12:48:23 -0500 Subject: [PATCH 2/3] update readme --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 1271834..dab0fe0 100644 --- a/README.md +++ b/README.md @@ -45,5 +45,6 @@ module "gce-ilb" { - [`google_compute_region_backend_service.default`](https://www.terraform.io/docs/providers/google/r/compute_region_backend_service): The backend service registered to the given `instance_group`. - [`google_compute_health_check.tcp`](https://www.terraform.io/docs/providers/google/r/compute_health_check): The TCP health check for the `instance_group` targets. - [`google_compute_health_check.http`](https://www.terraform.io/docs/providers/google/r/compute_health_check): The HTTP health check for the `instance_group` targets. +- [`google_compute_health_check.https`](https://www.terraform.io/docs/providers/google/r/compute_health_check): The HTTPS health check for the `instance_group` targets. - [`google_compute_firewall.default-ilb-fw`](https://www.terraform.io/docs/providers/google/r/compute_firewall): Firewall rule that allows traffic from the `source_tags` resources to `target_tags` on the `service_port`. - [`google_compute_firewall.default-hc`](https://www.terraform.io/docs/providers/google/r/compute_firewall): Firewall rule that allows traffic for health checks to the `target_tags` resources. From 02b7fd86c9c09614a26cebf67b4073dcb8241ec4 Mon Sep 17 00:00:00 2001 From: Adit Sinha Date: Wed, 23 Feb 2022 13:00:20 -0500 Subject: [PATCH 3/3] format --- main.tf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.tf b/main.tf index 79294c5..08de76b 100644 --- a/main.tf +++ b/main.tf @@ -44,8 +44,8 @@ resource "google_compute_forwarding_rule" "default" { } resource "google_compute_region_backend_service" "default" { - project = var.project - name = { + project = var.project + name = { "tcp" = "${var.name}-with-tcp-hc", "http" = "${var.name}-with-http-hc", "https" = "${var.name}-with-https-hc", @@ -120,7 +120,7 @@ resource "google_compute_health_check" "http" { } } } - + resource "google_compute_health_check" "https" { provider = google-beta count = var.health_check["type"] == "https" ? 1 : 0