Skip to content

Commit

Permalink
feat: Add option to enable health check logging (#49)
Browse files Browse the repository at this point in the history
  • Loading branch information
tnguyen14 authored Apr 12, 2021
1 parent aca0c93 commit 547c932
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 7 deletions.
1 change: 1 addition & 0 deletions examples/minimal/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ locals {
request = ""
request_path = "/"
host = "1.2.3.4"
enable_log = false
}
}

Expand Down
1 change: 1 addition & 0 deletions examples/simple/locals.tf
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,6 @@ locals {
request = ""
request_path = "/"
host = "1.2.3.4"
enable_log = false
}
}
4 changes: 4 additions & 0 deletions examples/simple/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ provider "google" {
version = "~> 3.62.0"
}

provider "google-beta" {
version = "~> 3.62.0"
}

module "gce-lb-fr" {
source = "GoogleCloudPlatform/lb/google"
version = "~> 2.3"
Expand Down
29 changes: 22 additions & 7 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,10 @@ resource "google_compute_region_backend_service" "default" {
}

resource "google_compute_health_check" "tcp" {
count = var.health_check["type"] == "tcp" ? 1 : 0
project = var.project
name = "${var.name}-hc-tcp"
provider = google-beta
count = var.health_check["type"] == "tcp" ? 1 : 0
project = var.project
name = "${var.name}-hc-tcp"

timeout_sec = var.health_check["timeout_sec"]
check_interval_sec = var.health_check["check_interval_sec"]
Expand All @@ -78,12 +79,20 @@ resource "google_compute_health_check" "tcp" {
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_health_check" "http" {
count = var.health_check["type"] == "http" ? 1 : 0
project = var.project
name = "${var.name}-hc-http"
provider = google-beta
count = var.health_check["type"] == "http" ? 1 : 0
project = var.project
name = "${var.name}-hc-http"

timeout_sec = var.health_check["timeout_sec"]
check_interval_sec = var.health_check["check_interval_sec"]
Expand All @@ -98,6 +107,13 @@ resource "google_compute_health_check" "http" {
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" {
Expand Down Expand Up @@ -132,4 +148,3 @@ resource "google_compute_firewall" "default-hc" {
target_tags = var.target_tags
target_service_accounts = var.target_service_accounts
}

1 change: 1 addition & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ variable "health_check" {
request = string
request_path = string
host = string
enable_log = bool
})
}

Expand Down

0 comments on commit 547c932

Please sign in to comment.