Skip to content

Commit 5926dfc

Browse files
authored
feat: Fix healthchecks inconsistency. (#56)
BREAKING CHANGE: Health check variables and resources were reorganized in this backwards-incompatible release. See the [upgrade guide](./docs/upgrading_to_mig_v2.0.md) for details.
1 parent d0d71d2 commit 5926dfc

File tree

21 files changed

+320
-298
lines changed

21 files changed

+320
-298
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ All notable changes to this project will be documented in this file. See [standa
99

1010
* derive project id for instance from instance template ([#63](https://github.com/terraform-google-modules/terraform-google-vm/issues/63)) ([3e2c8cd](https://github.com/terraform-google-modules/terraform-google-vm/commit/3e2c8cdeb2d0e6f1fe53bc2d0a9369c9dc59f013))
1111

12+
### Changed
13+
14+
- Replace health check related variables with a single object type parameter called `health_check` on the `mig` and
15+
`mig_with_percent` submodules. [#56]
16+
1217
## [1.4.0] - 2020-01-08
1318

1419
### Added
@@ -92,4 +97,5 @@ All notable changes to this project will be documented in this file. See [standa
9297
[#43]: https://github.com/terraform-google-modules/terraform-google-vm/pull/43
9398
[#44]: https://github.com/terraform-google-modules/terraform-google-vm/pull/44
9499
[#52]: https://github.com/terraform-google-modules/terraform-google-vm/pull/52
100+
[#56]: https://github.com/terraform-google-modules/terraform-google-vm/pull/56
95101
[#57]: https://github.com/terraform-google-modules/terraform-google-vm/pull/57

Makefile

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,16 +81,16 @@ docker_generate_docs:
8181
/bin/bash -c 'source /usr/local/bin/task_helper_functions.sh && generate_docs'
8282

8383
# Generate files from autogen
84-
.PHONY: docker_generate
85-
docker_generate:
84+
.PHONY: docker_generate_modules
85+
docker_generate_modules:
8686
docker run --rm -it \
87-
-v "$(CURDIR)":/workspace \
88-
$(REGISTRY_URL)/${DOCKER_IMAGE_DEVELOPER_TOOLS}:${DOCKER_TAG_VERSION_DEVELOPER_TOOLS} \
89-
/bin/bash -c 'source /usr/local/bin/task_helper_functions.sh && generate'
87+
-v "$(CURDIR)":/workspace \
88+
$(REGISTRY_URL)/${DOCKER_IMAGE_DEVELOPER_TOOLS}:${DOCKER_TAG_VERSION_DEVELOPER_TOOLS} \
89+
/bin/bash -c 'source /usr/local/bin/task_helper_functions.sh && generate_modules'
9090

9191
# Alias for backwards compatibility
9292
.PHONY: generate_docs
9393
generate_docs: docker_generate_docs
9494

95-
.PHONY: generate
96-
generate: docker_generate
95+
.PHONY: generate_modules
96+
generate_modules: docker_generate_modules

autogen/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ This module allows you to set the percentage ratio of second version of instance
1414

1515
See the [simple example](../../examples/{{ module_name }}/simple) for a usage example.
1616

17+
## Upgrading
18+
19+
The current version is 2.X. The following guides are available to assist with upgrades:
20+
21+
- [1.X -> 2.0](../../docs/upgrading_to_mig_v2.0.md)
22+
1723
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
1824

1925
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->

autogen/main.tf.tmpl

Lines changed: 34 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2018 Google LLC
2+
* Copyright 2019 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -18,8 +18,8 @@
1818

1919
locals {
2020
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,
2323
)
2424
distribution_policy_zones_base = {
2525
default = data.google_compute_zones.available.names
@@ -73,9 +73,12 @@ resource "google_compute_region_instance_group_manager" "{{ module_name }}" {
7373
target_pools = var.target_pools
7474
target_size = var.autoscaling_enabled ? var.min_replicas : var.target_size
7575

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+
}
7982
}
8083

8184
distribution_policy_zones = local.distribution_policy_zones
@@ -139,35 +142,39 @@ resource "google_compute_region_autoscaler" "autoscaler" {
139142
{% endif %}
140143
}
141144

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"
147149

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"]
152154

153155
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"]
156161
}
157162
}
158163

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"
164168

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"]
169173

170174
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"]
172179
}
173180
}

autogen/outputs.tf.tmpl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2018 Google LLC
2+
* Copyright 2019 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

autogen/variables.tf.tmpl

Lines changed: 31 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2018 Google LLC
2+
* Copyright 2019 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -89,49 +89,36 @@ variable "update_policy" {
8989
# Healthcheck
9090
##############
9191

92-
variable "http_healthcheck_enable" {
93-
description = "Enable HTTP healthcheck"
94-
default = "false"
95-
}
96-
97-
variable "tcp_healthcheck_enable" {
98-
description = "Enable TCP healthcheck"
99-
default = "false"
100-
}
101-
102-
variable "hc_initial_delay_sec" {
103-
description = "Health check, intial delay in seconds."
104-
default = 30
105-
}
106-
107-
variable "hc_interval_sec" {
108-
description = "Health check interval in seconds."
109-
default = 30
110-
}
111-
112-
variable "hc_timeout_sec" {
113-
description = "Health check timeout in seconds."
114-
default = 10
115-
}
116-
117-
variable "hc_healthy_threshold" {
118-
description = "Health check healthy threshold."
119-
default = 1
120-
}
121-
122-
variable "hc_unhealthy_threshold" {
123-
description = "Health check unhealthy threshold."
124-
default = 5
125-
}
126-
127-
variable "hc_path" {
128-
description = "Health check http path to check."
129-
default = "/"
130-
}
131-
132-
variable "hc_port" {
133-
description = "Health check port."
134-
default = ""
92+
variable "health_check" {
93+
description = "Health check to determine whether instances are responsive and able to do work"
94+
type = object({
95+
type = string
96+
initial_delay_sec = number
97+
check_interval_sec = number
98+
healthy_threshold = number
99+
timeout_sec = number
100+
unhealthy_threshold = number
101+
response = string
102+
proxy_header = string
103+
port = number
104+
request = string
105+
request_path = string
106+
host = string
107+
})
108+
default = {
109+
type = ""
110+
initial_delay_sec = 30
111+
check_interval_sec = 30
112+
healthy_threshold = 1
113+
timeout_sec = 10
114+
unhealthy_threshold = 5
115+
response = ""
116+
proxy_header = "NONE"
117+
port = 80
118+
request = ""
119+
request_path = "/"
120+
host = ""
121+
}
135122
}
136123

137124
#############

autogen/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2018 Google LLC
2+
* Copyright 2019 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.

docs/upgrading_to_mig_v2.0.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# Upgrading to MIG v2.0 (from v1.X)
2+
3+
The v2.0 release of MIG is a backwards incompatible release. The health check related variables `http_healthcheck_enable`, `tcp_healthcheck_enable`, `hc_initial_delay_sec`, `hc_interval_sec`, `hc_timeout_sec`, `hc_healthy_threshold`, `hc_unhealthy_threshold`, `hc_path` and `hc_port` were replaced with the new object type parameter called `health_check`.
4+
5+
## Migration Instructions
6+
7+
### Health Check Arguments Changes
8+
9+
Version 1.X of MIG used the optional health check variables:
10+
11+
```hcl
12+
13+
module "vm_mig" {
14+
source = "terraform-google-modules/vm/google//modules/mig"
15+
version = "1.3.0"
16+
...
17+
/* health checks */
18+
http_healthcheck_enable = true
19+
tcp_healthcheck_enable = false
20+
hc_initial_delay_sec = 30
21+
hc_interval_sec = 30
22+
hc_timeout_sec = 10
23+
hc_healthy_threshold = 1
24+
hc_unhealthy_threshold = 5
25+
hc_path = "/"
26+
hc_port = 80
27+
}
28+
```
29+
30+
Version 2.X of MIG uses the new object parameter named `health_check`:
31+
32+
```hcl
33+
module "mig" {
34+
source = "terraform-google-modules/vm/google//modules/mig"
35+
version = "1.3.0"
36+
...
37+
health_check = {
38+
type = "http"
39+
initial_delay_sec = 30
40+
check_interval_sec = 30
41+
healthy_threshold = 1
42+
timeout_sec = 10
43+
unhealthy_threshold = 5
44+
response = ""
45+
proxy_header = "NONE"
46+
port = 80
47+
request = ""
48+
request_path = "/"
49+
host = ""
50+
}
51+
}
52+
```
53+

examples/mig/full/main.tf

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,8 @@ module "mig" {
7272
update_policy = var.update_policy
7373
named_ports = var.named_ports
7474

75-
/* health checks */
76-
http_healthcheck_enable = var.http_healthcheck_enable
77-
tcp_healthcheck_enable = var.tcp_healthcheck_enable
78-
hc_initial_delay_sec = var.hc_initial_delay_sec
79-
hc_interval_sec = var.hc_interval_sec
80-
hc_timeout_sec = var.hc_timeout_sec
81-
hc_healthy_threshold = var.hc_healthy_threshold
82-
hc_unhealthy_threshold = var.hc_unhealthy_threshold
83-
hc_path = var.hc_path
84-
hc_port = var.hc_port
75+
/* health check */
76+
health_check = var.health_check
8577

8678
/* autoscaler */
8779
autoscaling_enabled = var.autoscaling_enabled

0 commit comments

Comments
 (0)