|
1 | 1 | /** |
2 | | - * Copyright 2018 Google LLC |
| 2 | + * Copyright 2019 Google LLC |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
18 | 18 |
|
19 | 19 | locals { |
20 | 20 | healthchecks = concat( |
21 | | - google_compute_health_check.http_healthcheck.*.self_link, |
22 | | - google_compute_health_check.tcp_healthcheck.*.self_link, |
| 21 | + google_compute_health_check.http.*.self_link, |
| 22 | + google_compute_health_check.tcp.*.self_link, |
23 | 23 | ) |
24 | 24 | distribution_policy_zones_base = { |
25 | 25 | default = data.google_compute_zones.available.names |
@@ -73,9 +73,12 @@ resource "google_compute_region_instance_group_manager" "{{ module_name }}" { |
73 | 73 | target_pools = var.target_pools |
74 | 74 | target_size = var.autoscaling_enabled ? var.min_replicas : var.target_size |
75 | 75 |
|
76 | | - auto_healing_policies { |
77 | | - health_check = length(local.healthchecks) > 0 ? local.healthchecks[0] : "" |
78 | | - initial_delay_sec = length(local.healthchecks) > 0 ? var.hc_initial_delay_sec : 0 |
| 76 | + dynamic "auto_healing_policies" { |
| 77 | + for_each = local.healthchecks |
| 78 | + content { |
| 79 | + health_check = auto_healing_policies.value |
| 80 | + initial_delay_sec = var.health_check["initial_delay_sec"] |
| 81 | + } |
79 | 82 | } |
80 | 83 |
|
81 | 84 | distribution_policy_zones = local.distribution_policy_zones |
@@ -139,35 +142,39 @@ resource "google_compute_region_autoscaler" "autoscaler" { |
139 | 142 | {% endif %} |
140 | 143 | } |
141 | 144 |
|
142 | | -resource "google_compute_health_check" "http_healthcheck" { |
143 | | - provider = google |
144 | | - count = var.http_healthcheck_enable ? 1 : 0 |
145 | | - name = "${var.hostname}-http-healthcheck" |
146 | | - project = var.project_id |
| 145 | +resource "google_compute_health_check" "http" { |
| 146 | + count = var.health_check["type"] == "http" ? 1 : 0 |
| 147 | + project = var.project_id |
| 148 | + name = "${var.hostname}-http-healthcheck" |
147 | 149 |
|
148 | | - check_interval_sec = var.hc_interval_sec |
149 | | - timeout_sec = var.hc_timeout_sec |
150 | | - healthy_threshold = var.hc_healthy_threshold |
151 | | - unhealthy_threshold = var.hc_unhealthy_threshold |
| 150 | + check_interval_sec = var.health_check["check_interval_sec"] |
| 151 | + healthy_threshold = var.health_check["healthy_threshold"] |
| 152 | + timeout_sec = var.health_check["timeout_sec"] |
| 153 | + unhealthy_threshold = var.health_check["unhealthy_threshold"] |
152 | 154 |
|
153 | 155 | http_health_check { |
154 | | - request_path = var.hc_path |
155 | | - port = var.hc_port |
| 156 | + port = var.health_check["port"] |
| 157 | + request_path = var.health_check["request_path"] |
| 158 | + host = var.health_check["host"] |
| 159 | + response = var.health_check["response"] |
| 160 | + proxy_header = var.health_check["proxy_header"] |
156 | 161 | } |
157 | 162 | } |
158 | 163 |
|
159 | | -resource "google_compute_health_check" "tcp_healthcheck" { |
160 | | - provider = google |
161 | | - count = var.tcp_healthcheck_enable ? 1 : 0 |
162 | | - project = var.project_id |
163 | | - name = "${var.hostname}-tcp-healthcheck" |
| 164 | +resource "google_compute_health_check" "tcp" { |
| 165 | + count = var.health_check["type"] == "tcp" ? 1 : 0 |
| 166 | + project = var.project_id |
| 167 | + name = "${var.hostname}-tcp-healthcheck" |
164 | 168 |
|
165 | | - check_interval_sec = var.hc_interval_sec |
166 | | - timeout_sec = var.hc_timeout_sec |
167 | | - healthy_threshold = var.hc_healthy_threshold |
168 | | - unhealthy_threshold = var.hc_unhealthy_threshold |
| 169 | + timeout_sec = var.health_check["timeout_sec"] |
| 170 | + check_interval_sec = var.health_check["check_interval_sec"] |
| 171 | + healthy_threshold = var.health_check["healthy_threshold"] |
| 172 | + unhealthy_threshold = var.health_check["unhealthy_threshold"] |
169 | 173 |
|
170 | 174 | tcp_health_check { |
171 | | - port = var.hc_port |
| 175 | + port = var.health_check["port"] |
| 176 | + request = var.health_check["request"] |
| 177 | + response = var.health_check["response"] |
| 178 | + proxy_header = var.health_check["proxy_header"] |
172 | 179 | } |
173 | 180 | } |
0 commit comments