Fix health checks in net-ilb and compute-mig modules (#69)
* fix health checks in ilb module * fix health check in compute-mig and add basic tests
This commit is contained in:
committed by
GitHub
parent
a51c8be101
commit
fa29a8e26f
@@ -257,9 +257,9 @@ resource "google_compute_region_instance_group_manager" "default" {
|
||||
}
|
||||
}
|
||||
|
||||
resource "google_compute_health_check" "default" {
|
||||
resource "google_compute_health_check" "http" {
|
||||
provider = google-beta
|
||||
count = var.health_check_config == null ? 0 : 1
|
||||
count = try(var.health_check_config.type, null) == "http" ? 1 : 0
|
||||
project = var.project_id
|
||||
name = var.name
|
||||
description = "Terraform managed."
|
||||
@@ -269,92 +269,132 @@ resource "google_compute_health_check" "default" {
|
||||
timeout_sec = try(var.health_check_config.config.timeout_sec, null)
|
||||
unhealthy_threshold = try(var.health_check_config.config.unhealthy_threshold, null)
|
||||
|
||||
dynamic http_health_check {
|
||||
for_each = (
|
||||
try(var.health_check_config.type, null) == "http"
|
||||
? [var.health_check_config.check]
|
||||
: []
|
||||
)
|
||||
iterator = check
|
||||
content {
|
||||
host = try(check.value.host, null)
|
||||
port = try(check.value.port, null)
|
||||
port_name = try(check.value.port_name, null)
|
||||
port_specification = try(check.value.port_specification, null)
|
||||
proxy_header = try(check.value.proxy_header, null)
|
||||
request_path = try(check.value.request_path, null)
|
||||
response = try(check.value.response, null)
|
||||
}
|
||||
}
|
||||
|
||||
dynamic https_health_check {
|
||||
for_each = (
|
||||
try(var.health_check_config.type, null) == "https"
|
||||
? [var.health_check_config.check]
|
||||
: []
|
||||
)
|
||||
iterator = check
|
||||
content {
|
||||
host = try(check.value.host, null)
|
||||
port = try(check.value.port, null)
|
||||
port_name = try(check.value.port_name, null)
|
||||
port_specification = try(check.value.port_specification, null)
|
||||
proxy_header = try(check.value.proxy_header, null)
|
||||
request_path = try(check.value.request_path, null)
|
||||
response = try(check.value.response, null)
|
||||
}
|
||||
}
|
||||
|
||||
dynamic tcp_health_check {
|
||||
for_each = (
|
||||
try(var.health_check_config.type, null) == "tcp"
|
||||
? [var.health_check_config.check]
|
||||
: []
|
||||
)
|
||||
iterator = check
|
||||
content {
|
||||
port = try(check.value.port, null)
|
||||
port_name = try(check.value.port_name, null)
|
||||
port_specification = try(check.value.port_specification, null)
|
||||
proxy_header = try(check.value.proxy_header, null)
|
||||
request = try(check.value.request, null)
|
||||
response = try(check.value.response, null)
|
||||
}
|
||||
}
|
||||
|
||||
dynamic ssl_health_check {
|
||||
for_each = (
|
||||
try(var.health_check_config.type, null) == "ssl"
|
||||
? [var.health_check_config.check]
|
||||
: []
|
||||
)
|
||||
iterator = check
|
||||
content {
|
||||
port = try(check.value.port, null)
|
||||
port_name = try(check.value.port_name, null)
|
||||
port_specification = try(check.value.port_specification, null)
|
||||
proxy_header = try(check.value.proxy_header, null)
|
||||
request = try(check.value.request, null)
|
||||
response = try(check.value.response, null)
|
||||
}
|
||||
}
|
||||
|
||||
dynamic http2_health_check {
|
||||
for_each = (
|
||||
try(var.health_check_config.type, null) == "http2"
|
||||
? [var.health_check_config.check]
|
||||
: []
|
||||
)
|
||||
iterator = check
|
||||
content {
|
||||
host = try(check.value.host, null)
|
||||
port = try(check.value.port, null)
|
||||
port_name = try(check.value.port_name, null)
|
||||
port_specification = try(check.value.port_specification, null)
|
||||
proxy_header = try(check.value.proxy_header, null)
|
||||
request_path = try(check.value.request_path, null)
|
||||
response = try(check.value.response, null)
|
||||
}
|
||||
http_health_check {
|
||||
host = try(var.health_check_config.check.host, null)
|
||||
port = try(var.health_check_config.check.port, null)
|
||||
port_name = try(var.health_check_config.check.port_name, null)
|
||||
port_specification = try(var.health_check_config.check.port_specification, null)
|
||||
proxy_header = try(var.health_check_config.check.proxy_header, null)
|
||||
request_path = try(var.health_check_config.check.request_path, null)
|
||||
response = try(var.health_check_config.check.response, null)
|
||||
}
|
||||
|
||||
dynamic log_config {
|
||||
for_each = try(var.health_check_config.logging, false) ? [""] : []
|
||||
content {
|
||||
enable = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "google_compute_health_check" "https" {
|
||||
provider = google-beta
|
||||
count = try(var.health_check_config.type, null) == "https" ? 1 : 0
|
||||
project = var.project_id
|
||||
name = var.name
|
||||
description = "Terraform managed."
|
||||
|
||||
check_interval_sec = try(var.health_check_config.config.check_interval_sec, null)
|
||||
healthy_threshold = try(var.health_check_config.config.healthy_threshold, null)
|
||||
timeout_sec = try(var.health_check_config.config.timeout_sec, null)
|
||||
unhealthy_threshold = try(var.health_check_config.config.unhealthy_threshold, null)
|
||||
|
||||
https_health_check {
|
||||
host = try(var.health_check_config.check.host, null)
|
||||
port = try(var.health_check_config.check.port, null)
|
||||
port_name = try(var.health_check_config.check.port_name, null)
|
||||
port_specification = try(var.health_check_config.check.port_specification, null)
|
||||
proxy_header = try(var.health_check_config.check.proxy_header, null)
|
||||
request_path = try(var.health_check_config.check.request_path, null)
|
||||
response = try(var.health_check_config.check.response, null)
|
||||
}
|
||||
|
||||
dynamic log_config {
|
||||
for_each = try(var.health_check_config.logging, false) ? [""] : []
|
||||
content {
|
||||
enable = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "google_compute_health_check" "tcp" {
|
||||
provider = google-beta
|
||||
count = try(var.health_check_config.type, null) == "tcp" ? 1 : 0
|
||||
project = var.project_id
|
||||
name = var.name
|
||||
description = "Terraform managed."
|
||||
|
||||
check_interval_sec = try(var.health_check_config.config.check_interval_sec, null)
|
||||
healthy_threshold = try(var.health_check_config.config.healthy_threshold, null)
|
||||
timeout_sec = try(var.health_check_config.config.timeout_sec, null)
|
||||
unhealthy_threshold = try(var.health_check_config.config.unhealthy_threshold, null)
|
||||
|
||||
tcp_health_check {
|
||||
port = try(var.health_check_config.check.port, null)
|
||||
port_name = try(var.health_check_config.check.port_name, null)
|
||||
port_specification = try(var.health_check_config.check.port_specification, null)
|
||||
proxy_header = try(var.health_check_config.check.proxy_header, null)
|
||||
request = try(var.health_check_config.check.request, null)
|
||||
response = try(var.health_check_config.check.response, null)
|
||||
}
|
||||
|
||||
dynamic log_config {
|
||||
for_each = try(var.health_check_config.logging, false) ? [""] : []
|
||||
content {
|
||||
enable = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "google_compute_health_check" "ssl" {
|
||||
provider = google-beta
|
||||
count = try(var.health_check_config.type, null) == "ssl" ? 1 : 0
|
||||
project = var.project_id
|
||||
name = var.name
|
||||
description = "Terraform managed."
|
||||
|
||||
check_interval_sec = try(var.health_check_config.config.check_interval_sec, null)
|
||||
healthy_threshold = try(var.health_check_config.config.healthy_threshold, null)
|
||||
timeout_sec = try(var.health_check_config.config.timeout_sec, null)
|
||||
unhealthy_threshold = try(var.health_check_config.config.unhealthy_threshold, null)
|
||||
|
||||
ssl_health_check {
|
||||
port = try(var.health_check_config.check.port, null)
|
||||
port_name = try(var.health_check_config.check.port_name, null)
|
||||
port_specification = try(var.health_check_config.check.port_specification, null)
|
||||
proxy_header = try(var.health_check_config.check.proxy_header, null)
|
||||
request = try(var.health_check_config.check.request, null)
|
||||
response = try(var.health_check_config.check.response, null)
|
||||
}
|
||||
|
||||
dynamic log_config {
|
||||
for_each = try(var.health_check_config.logging, false) ? [""] : []
|
||||
content {
|
||||
enable = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "google_compute_health_check" "http2" {
|
||||
provider = google-beta
|
||||
count = try(var.health_check_config.type, null) == "http2" ? 1 : 0
|
||||
project = var.project_id
|
||||
name = var.name
|
||||
description = "Terraform managed."
|
||||
|
||||
check_interval_sec = try(var.health_check_config.config.check_interval_sec, null)
|
||||
healthy_threshold = try(var.health_check_config.config.healthy_threshold, null)
|
||||
timeout_sec = try(var.health_check_config.config.timeout_sec, null)
|
||||
unhealthy_threshold = try(var.health_check_config.config.unhealthy_threshold, null)
|
||||
|
||||
http2_health_check {
|
||||
host = try(var.health_check_config.check.host, null)
|
||||
port = try(var.health_check_config.check.port, null)
|
||||
port_name = try(var.health_check_config.check.port_name, null)
|
||||
port_specification = try(var.health_check_config.check.port_specification, null)
|
||||
proxy_header = try(var.health_check_config.check.proxy_header, null)
|
||||
request_path = try(var.health_check_config.check.request_path, null)
|
||||
response = try(var.health_check_config.check.response, null)
|
||||
}
|
||||
|
||||
dynamic log_config {
|
||||
@@ -363,5 +403,4 @@ resource "google_compute_health_check" "default" {
|
||||
enable = true
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -34,7 +34,16 @@ output "group_manager" {
|
||||
|
||||
output "health_check" {
|
||||
description = "Auto-created health-check resource."
|
||||
value = var.health_check_config == null ? null : try(
|
||||
google_compute_health_check.default.0, {}
|
||||
value = (
|
||||
var.health_check_config == null
|
||||
? null
|
||||
: try(
|
||||
google_compute_health_check.http.0,
|
||||
google_compute_health_check.https.0,
|
||||
google_compute_health_check.tcp.0,
|
||||
google_compute_health_check.ssl.0,
|
||||
google_compute_health_check.http2.0,
|
||||
{}
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -51,7 +51,7 @@ variable "default_version" {
|
||||
}
|
||||
|
||||
variable "health_check_config" {
|
||||
description = "Optional auto-created helth check configuration, use the output self-link to set it in the auto healing policy. Refer to examples for usage."
|
||||
description = "Optional auto-created health check configuration, use the output self-link to set it in the auto healing policy. Refer to examples for usage."
|
||||
type = object({
|
||||
type = string # http https tcp ssl http2
|
||||
check = map(any) # actual health check block attributes
|
||||
|
||||
@@ -17,9 +17,17 @@
|
||||
|
||||
locals {
|
||||
health_check = (
|
||||
var.health_check == null
|
||||
? try(google_compute_health_check.default.0.self_link, null)
|
||||
: var.health_check
|
||||
var.health_check != null
|
||||
? var.health_check
|
||||
: try(local.health_check_resource.self_link, null)
|
||||
)
|
||||
health_check_resource = try(
|
||||
google_compute_health_check.http.0,
|
||||
google_compute_health_check.https.0,
|
||||
google_compute_health_check.tcp.0,
|
||||
google_compute_health_check.ssl.0,
|
||||
google_compute_health_check.http2.0,
|
||||
{}
|
||||
)
|
||||
}
|
||||
|
||||
@@ -81,9 +89,9 @@ resource "google_compute_region_backend_service" "default" {
|
||||
|
||||
}
|
||||
|
||||
resource "google_compute_health_check" "default" {
|
||||
resource "google_compute_health_check" "http" {
|
||||
provider = google-beta
|
||||
count = var.health_check == null ? 1 : 0
|
||||
count = try(var.health_check_config.type, null) == "http" ? 1 : 0
|
||||
project = var.project_id
|
||||
name = var.name
|
||||
description = "Terraform managed."
|
||||
@@ -93,92 +101,14 @@ resource "google_compute_health_check" "default" {
|
||||
timeout_sec = try(var.health_check_config.config.timeout_sec, null)
|
||||
unhealthy_threshold = try(var.health_check_config.config.unhealthy_threshold, null)
|
||||
|
||||
dynamic http_health_check {
|
||||
for_each = (
|
||||
try(var.health_check_config.type, null) == "http"
|
||||
? [var.health_check_config.check]
|
||||
: []
|
||||
)
|
||||
iterator = check
|
||||
content {
|
||||
host = try(check.value.host, null)
|
||||
port = try(check.value.port, null)
|
||||
port_name = try(check.value.port_name, null)
|
||||
port_specification = try(check.value.port_specification, null)
|
||||
proxy_header = try(check.value.proxy_header, null)
|
||||
request_path = try(check.value.request_path, null)
|
||||
response = try(check.value.response, null)
|
||||
}
|
||||
}
|
||||
|
||||
dynamic https_health_check {
|
||||
for_each = (
|
||||
try(var.health_check_config.type, null) == "https"
|
||||
? [var.health_check_config.check]
|
||||
: []
|
||||
)
|
||||
iterator = check
|
||||
content {
|
||||
host = try(check.value.host, null)
|
||||
port = try(check.value.port, null)
|
||||
port_name = try(check.value.port_name, null)
|
||||
port_specification = try(check.value.port_specification, null)
|
||||
proxy_header = try(check.value.proxy_header, null)
|
||||
request_path = try(check.value.request_path, null)
|
||||
response = try(check.value.response, null)
|
||||
}
|
||||
}
|
||||
|
||||
dynamic tcp_health_check {
|
||||
for_each = (
|
||||
try(var.health_check_config.type, null) == "tcp"
|
||||
? [var.health_check_config.check]
|
||||
: []
|
||||
)
|
||||
iterator = check
|
||||
content {
|
||||
port = try(check.value.port, null)
|
||||
port_name = try(check.value.port_name, null)
|
||||
port_specification = try(check.value.port_specification, null)
|
||||
proxy_header = try(check.value.proxy_header, null)
|
||||
request = try(check.value.request, null)
|
||||
response = try(check.value.response, null)
|
||||
}
|
||||
}
|
||||
|
||||
dynamic ssl_health_check {
|
||||
for_each = (
|
||||
try(var.health_check_config.type, null) == "ssl"
|
||||
? [var.health_check_config.check]
|
||||
: []
|
||||
)
|
||||
iterator = check
|
||||
content {
|
||||
port = try(check.value.port, null)
|
||||
port_name = try(check.value.port_name, null)
|
||||
port_specification = try(check.value.port_specification, null)
|
||||
proxy_header = try(check.value.proxy_header, null)
|
||||
request = try(check.value.request, null)
|
||||
response = try(check.value.response, null)
|
||||
}
|
||||
}
|
||||
|
||||
dynamic http2_health_check {
|
||||
for_each = (
|
||||
try(var.health_check_config.type, null) == "http2"
|
||||
? [var.health_check_config.check]
|
||||
: []
|
||||
)
|
||||
iterator = check
|
||||
content {
|
||||
host = try(check.value.host, null)
|
||||
port = try(check.value.port, null)
|
||||
port_name = try(check.value.port_name, null)
|
||||
port_specification = try(check.value.port_specification, null)
|
||||
proxy_header = try(check.value.proxy_header, null)
|
||||
request_path = try(check.value.request_path, null)
|
||||
response = try(check.value.response, null)
|
||||
}
|
||||
http_health_check {
|
||||
host = try(var.health_check_config.check.host, null)
|
||||
port = try(var.health_check_config.check.port, null)
|
||||
port_name = try(var.health_check_config.check.port_name, null)
|
||||
port_specification = try(var.health_check_config.check.port_specification, null)
|
||||
proxy_header = try(var.health_check_config.check.proxy_header, null)
|
||||
request_path = try(var.health_check_config.check.request_path, null)
|
||||
response = try(var.health_check_config.check.response, null)
|
||||
}
|
||||
|
||||
dynamic log_config {
|
||||
@@ -187,5 +117,123 @@ resource "google_compute_health_check" "default" {
|
||||
enable = true
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
resource "google_compute_health_check" "https" {
|
||||
provider = google-beta
|
||||
count = try(var.health_check_config.type, null) == "https" ? 1 : 0
|
||||
project = var.project_id
|
||||
name = var.name
|
||||
description = "Terraform managed."
|
||||
|
||||
check_interval_sec = try(var.health_check_config.config.check_interval_sec, null)
|
||||
healthy_threshold = try(var.health_check_config.config.healthy_threshold, null)
|
||||
timeout_sec = try(var.health_check_config.config.timeout_sec, null)
|
||||
unhealthy_threshold = try(var.health_check_config.config.unhealthy_threshold, null)
|
||||
|
||||
https_health_check {
|
||||
host = try(var.health_check_config.check.host, null)
|
||||
port = try(var.health_check_config.check.port, null)
|
||||
port_name = try(var.health_check_config.check.port_name, null)
|
||||
port_specification = try(var.health_check_config.check.port_specification, null)
|
||||
proxy_header = try(var.health_check_config.check.proxy_header, null)
|
||||
request_path = try(var.health_check_config.check.request_path, null)
|
||||
response = try(var.health_check_config.check.response, null)
|
||||
}
|
||||
|
||||
dynamic log_config {
|
||||
for_each = try(var.health_check_config.logging, false) ? [""] : []
|
||||
content {
|
||||
enable = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "google_compute_health_check" "tcp" {
|
||||
provider = google-beta
|
||||
count = try(var.health_check_config.type, null) == "tcp" ? 1 : 0
|
||||
project = var.project_id
|
||||
name = var.name
|
||||
description = "Terraform managed."
|
||||
|
||||
check_interval_sec = try(var.health_check_config.config.check_interval_sec, null)
|
||||
healthy_threshold = try(var.health_check_config.config.healthy_threshold, null)
|
||||
timeout_sec = try(var.health_check_config.config.timeout_sec, null)
|
||||
unhealthy_threshold = try(var.health_check_config.config.unhealthy_threshold, null)
|
||||
|
||||
tcp_health_check {
|
||||
port = try(var.health_check_config.check.port, null)
|
||||
port_name = try(var.health_check_config.check.port_name, null)
|
||||
port_specification = try(var.health_check_config.check.port_specification, null)
|
||||
proxy_header = try(var.health_check_config.check.proxy_header, null)
|
||||
request = try(var.health_check_config.check.request, null)
|
||||
response = try(var.health_check_config.check.response, null)
|
||||
}
|
||||
|
||||
dynamic log_config {
|
||||
for_each = try(var.health_check_config.logging, false) ? [""] : []
|
||||
content {
|
||||
enable = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "google_compute_health_check" "ssl" {
|
||||
provider = google-beta
|
||||
count = try(var.health_check_config.type, null) == "ssl" ? 1 : 0
|
||||
project = var.project_id
|
||||
name = var.name
|
||||
description = "Terraform managed."
|
||||
|
||||
check_interval_sec = try(var.health_check_config.config.check_interval_sec, null)
|
||||
healthy_threshold = try(var.health_check_config.config.healthy_threshold, null)
|
||||
timeout_sec = try(var.health_check_config.config.timeout_sec, null)
|
||||
unhealthy_threshold = try(var.health_check_config.config.unhealthy_threshold, null)
|
||||
|
||||
ssl_health_check {
|
||||
port = try(var.health_check_config.check.port, null)
|
||||
port_name = try(var.health_check_config.check.port_name, null)
|
||||
port_specification = try(var.health_check_config.check.port_specification, null)
|
||||
proxy_header = try(var.health_check_config.check.proxy_header, null)
|
||||
request = try(var.health_check_config.check.request, null)
|
||||
response = try(var.health_check_config.check.response, null)
|
||||
}
|
||||
|
||||
dynamic log_config {
|
||||
for_each = try(var.health_check_config.logging, false) ? [""] : []
|
||||
content {
|
||||
enable = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
resource "google_compute_health_check" "http2" {
|
||||
provider = google-beta
|
||||
count = try(var.health_check_config.type, null) == "http2" ? 1 : 0
|
||||
project = var.project_id
|
||||
name = var.name
|
||||
description = "Terraform managed."
|
||||
|
||||
check_interval_sec = try(var.health_check_config.config.check_interval_sec, null)
|
||||
healthy_threshold = try(var.health_check_config.config.healthy_threshold, null)
|
||||
timeout_sec = try(var.health_check_config.config.timeout_sec, null)
|
||||
unhealthy_threshold = try(var.health_check_config.config.unhealthy_threshold, null)
|
||||
|
||||
http2_health_check {
|
||||
host = try(var.health_check_config.check.host, null)
|
||||
port = try(var.health_check_config.check.port, null)
|
||||
port_name = try(var.health_check_config.check.port_name, null)
|
||||
port_specification = try(var.health_check_config.check.port_specification, null)
|
||||
proxy_header = try(var.health_check_config.check.proxy_header, null)
|
||||
request_path = try(var.health_check_config.check.request_path, null)
|
||||
response = try(var.health_check_config.check.response, null)
|
||||
}
|
||||
|
||||
dynamic log_config {
|
||||
for_each = try(var.health_check_config.logging, false) ? [""] : []
|
||||
content {
|
||||
enable = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -51,15 +51,15 @@ output "forwarding_rule_self_link" {
|
||||
|
||||
output "health_check" {
|
||||
description = "Auto-created health-check resource."
|
||||
value = try(google_compute_health_check.default.0, {})
|
||||
value = local.health_check_resource
|
||||
}
|
||||
|
||||
output "health_check_self_id" {
|
||||
description = "Auto-created health-check self id."
|
||||
value = try(google_compute_health_check.default.0.id, null)
|
||||
value = try(local.health_check_resource.id, null)
|
||||
}
|
||||
|
||||
output "health_check_self_link" {
|
||||
description = "Auto-created health-check self link."
|
||||
value = try(google_compute_health_check.default.0.self_link, null)
|
||||
value = try(local.health_check_resource.self_link, null)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user