Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to use a HTTPS health check #86

Merged
merged 3 commits into from
Mar 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
38 changes: 35 additions & 3 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,12 @@ 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"
project = var.project
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
Expand All @@ -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" {
Expand Down Expand Up @@ -117,6 +121,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
project = var.network_project == "" ? var.project : var.network_project
Expand Down