Skip to content

Commit e0ea139

Browse files
authored
feat: Make health checks optional to support global NEG backend services (#106)
1 parent ca8a567 commit e0ea139

File tree

18 files changed

+84
-63
lines changed

18 files changed

+84
-63
lines changed

CHANGELOG.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
# Changelog
2+
23
All notable changes to this project will be documented in this file.
34

45
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
56
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
67

78
## [4.1.0](https://www.github.com/terraform-google-modules/terraform-google-lb-http/compare/v4.0.0...v4.1.0) (2020-05-05)
89

9-
1010
### Features
1111

1212
* Add health check logging support ([#98](https://www.github.com/terraform-google-modules/terraform-google-lb-http/issues/98)) ([f2b8f3c](https://www.github.com/terraform-google-modules/terraform-google-lb-http/commit/f2b8f3caf49a5ad06522d703d1ba1a101c561bb7))
1313

1414
## [4.0.0](https://www.github.com/terraform-google-modules/terraform-google-lb-http/compare/v3.2.0...v4.0.0) (2020-04-21)
15+
1516
Please see the [upgrade guide](./docs/upgrading_to_v4.0.md) for details.
1617

1718
### ⚠ BREAKING CHANGES
@@ -27,28 +28,28 @@ Please see the [upgrade guide](./docs/upgrading_to_v4.0.md) for details.
2728

2829
## [3.2.0](https://www.github.com/terraform-google-modules/terraform-google-lb-http/compare/v3.1.0...v3.2.0) (2020-02-13)
2930

30-
3131
### Features
3232

3333
* Add submodule which ignores changes to backend group ([#81](https://www.github.com/terraform-google-modules/terraform-google-lb-http/issues/81)) ([d8d3e33](https://www.github.com/terraform-google-modules/terraform-google-lb-http/commit/d8d3e33dc3a128c8790476d44ae45f8465f9fa51))
3434

3535
## [3.1.0](https://www.github.com/terraform-google-modules/terraform-google-lb-http/compare/v3.0.0...v3.1.0) (2020-01-28)
3636

37-
3837
### Features
3938

4039
* Allow 3.x google provider ([#77](https://www.github.com/terraform-google-modules/terraform-google-lb-http/issues/77)) ([650d639](https://www.github.com/terraform-google-modules/terraform-google-lb-http/commit/650d639beba895dabbaeb312090d013fde9a68bd))
4140

4241
## [3.0.0] - 2019-12-16
4342

4443
### Added
44+
4545
- QUIC protocol support [#57]
4646
- Container Native Load Balancing support via NEGs [#57]
4747
- Allow existing IP address to be used [#25]
4848
- Allow setting a SSL Policy to restrict TLS/Ciphers
4949
- Add http/https target proxies to output to allow binding multiple IPs
5050

5151
### Changed
52+
5253
- Update minimum terraform version to 0.12.6
5354
- Update google providers to 2.15
5455
- Move to using `for_each` for state management [#57]

CONTRIBUTING.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ The following dependencies must be installed on the development system:
1515
Run `make build` to generate new module code.
1616

1717
### Submodules
18+
1819
The main module Terraform code is stored in the [./autogen](./autogen) folder. Changes should be made there and then reflected into the submodules via `make build`.
1920

2021
### Generating Documentation for Inputs and Outputs
@@ -39,14 +40,17 @@ The general strategy for these tests is to verify the behaviour of the
3940
submodules, and example modules are all functionally correct.
4041

4142
### Test Environment
43+
4244
The easiest way to test the module is in an isolated test project. The setup for such a project is defined in [test/setup](./test/setup/) directory.
4345

4446
To use this setup, you need a service account with these permissions (on a Folder or Organization):
47+
4548
- Project Creator
4649
- Project Billing Manager
4750

4851
The project that the service account belongs to must have the following APIs enabled (the setup won't
4952
create any resources on the service account's project):
53+
5054
- Cloud Resource Manager
5155
- Cloud Billing
5256
- Service Usage
@@ -59,13 +63,15 @@ export SERVICE_ACCOUNT_JSON=$(< credentials.json)
5963
```
6064

6165
You will also need to set a few environment variables:
66+
6267
```
6368
export TF_VAR_org_id="your_org_id"
6469
export TF_VAR_folder_id="your_folder_id"
6570
export TF_VAR_billing_account="your_billing_account_id"
6671
```
6772

6873
With these settings in place, you can prepare a test project using Docker:
74+
6975
```
7076
make docker_test_prepare
7177
```

README.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ Modular Global HTTP Load Balancer for GCE using forwarding rules.
44

55
If you would like to allow for backend groups to be managed outside Terraform, such as via GKE services, see the [dynamic backends](./modules/dynamic_backends) submodule.
66

7-
### Load Balancer Types
7+
## Load Balancer Types
8+
89
* [TCP load balancer](https://github.com/terraform-google-modules/terraform-google-lb)
910
* **HTTP/S load balancer**
1011
* [Internal load balancer](https://github.com/terraform-google-modules/terraform-google-lb-internal)
@@ -83,8 +84,9 @@ module "gce-lb-http" {
8384
## Version
8485

8586
Current version is 3.0. Upgrade guides:
86-
- [1.X -> 2.X](https://www.terraform.io/upgrade-guides/0-12.html)
87-
- [2.X -> 3.0](./docs/upgrading-v2.0.0-v3.0.0.md)
87+
88+
* [1.X -> 2.X](https://www.terraform.io/upgrade-guides/0-12.html)
89+
* [2.X -> 3.0](./docs/upgrading-v2.0.0-v3.0.0.md)
8890

8991
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
9092
## Inputs
@@ -125,12 +127,13 @@ Current version is 3.0. Upgrade guides:
125127

126128
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
127129

128-
- [`google_compute_global_forwarding_rule.http`](https://www.terraform.io/docs/providers/google/r/compute_global_forwarding_rule.html): The global HTTP forwarding rule.
129-
- [`google_compute_global_forwarding_rule.https`](https://www.terraform.io/docs/providers/google/r/compute_global_forwarding_rule.html): The global HTTPS forwarding rule created when `ssl` is `true`.
130-
- [`google_compute_target_http_proxy.default`](https://www.terraform.io/docs/providers/google/r/compute_target_http_proxy.html): The HTTP proxy resource that binds the url map. Created when input `ssl` is `false`.
131-
- [`google_compute_target_https_proxy.default`](https://www.terraform.io/docs/providers/google/r/compute_target_https_proxy.html): The HTTPS proxy resource that binds the url map. Created when input `ssl` is `true`.
132-
- [`google_compute_ssl_certificate.default`](https://www.terraform.io/docs/providers/google/r/compute_ssl_certificate.html): The certificate resource created when input `ssl` is `true`.
133-
- [`google_compute_url_map.default`](https://www.terraform.io/docs/providers/google/r/compute_url_map.html): The default URL map resource when input `url_map` is not provided.
134-
- [`google_compute_backend_service.default.*`](https://www.terraform.io/docs/providers/google/r/compute_backend_service.html): The backend services created for each of the `backend_params` elements.
135-
- [`google_compute_health_check.default.*`](https://www.terraform.io/docs/providers/google/r/compute_health_check.html): Health check resources create for each of the backend services.
136-
- [`google_compute_firewall.default-hc`](https://www.terraform.io/docs/providers/google/r/compute_firewall.html): Firewall rule created for each of the backed services to alllow health checks to the instance group.
130+
* [`google_compute_global_forwarding_rule.http`](https://www.terraform.io/docs/providers/google/r/compute_global_forwarding_rule.html): The global HTTP forwarding rule.
131+
* [`google_compute_global_forwarding_rule.https`](https://www.terraform.io/docs/providers/google/r/compute_global_forwarding_rule.html): The global HTTPS forwarding rule created when `ssl` is `true`.
132+
* [`google_compute_target_http_proxy.default`](https://www.terraform.io/docs/providers/google/r/compute_target_http_proxy.html): The HTTP proxy resource that binds the url map. Created when input `ssl` is `false`.
133+
* [`google_compute_target_https_proxy.default`](https://www.terraform.io/docs/providers/google/r/compute_target_https_proxy.html): The HTTPS proxy resource that binds the url map. Created when input `ssl` is `true`.
134+
* [`google_compute_ssl_certificate.default`](https://www.terraform.io/docs/providers/google/r/compute_ssl_certificate.html): The certificate resource created when input `ssl` is `true`.
135+
* [`google_compute_url_map.default`](https://www.terraform.io/docs/providers/google/r/compute_url_map.html): The default URL map resource when input `url_map` is not provided.
136+
* [`google_compute_backend_service.default.*`](https://www.terraform.io/docs/providers/google/r/compute_backend_service.html): The backend services created for each of the `backend_params` elements.
137+
* [`google_compute_health_check.default.*`](https://www.terraform.io/docs/providers/google/r/compute_health_check.html):
138+
Health check resources created for each of the (non global NEG) backend services.
139+
* [`google_compute_firewall.default-hc`](https://www.terraform.io/docs/providers/google/r/compute_firewall.html): Firewall rule created for each of the backed services to allow health checks to the instance group.

autogen/README.md

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ This submodule allows for configuring dynamic backend outside Terraform.
99
As such, any changes to the `backends.groups` variable after creation will be ignored.
1010
{% endif %}
1111

12-
### Load Balancer Types
12+
## Load Balancer Types
13+
1314
* [TCP load balancer](https://github.com/terraform-google-modules/terraform-google-lb)
1415
* **HTTP/S load balancer**
1516
* [Internal load balancer](https://github.com/terraform-google-modules/terraform-google-lb-internal)
@@ -88,8 +89,9 @@ module "gce-lb-http" {
8889
## Version
8990

9091
Current version is 3.0. Upgrade guides:
91-
- [1.X -> 2.X](https://www.terraform.io/upgrade-guides/0-12.html)
92-
- [2.X -> 3.0](./docs/upgrading-v2.0.0-v3.0.0.md)
92+
93+
* [1.X -> 2.X](https://www.terraform.io/upgrade-guides/0-12.html)
94+
* [2.X -> 3.0](./docs/upgrading-v2.0.0-v3.0.0.md)
9395

9496
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
9597
## Inputs
@@ -129,12 +131,13 @@ Current version is 3.0. Upgrade guides:
129131

130132
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
131133

132-
- [`google_compute_global_forwarding_rule.http`](https://www.terraform.io/docs/providers/google/r/compute_global_forwarding_rule.html): The global HTTP forwarding rule.
133-
- [`google_compute_global_forwarding_rule.https`](https://www.terraform.io/docs/providers/google/r/compute_global_forwarding_rule.html): The global HTTPS forwarding rule created when `ssl` is `true`.
134-
- [`google_compute_target_http_proxy.default`](https://www.terraform.io/docs/providers/google/r/compute_target_http_proxy.html): The HTTP proxy resource that binds the url map. Created when input `ssl` is `false`.
135-
- [`google_compute_target_https_proxy.default`](https://www.terraform.io/docs/providers/google/r/compute_target_https_proxy.html): The HTTPS proxy resource that binds the url map. Created when input `ssl` is `true`.
136-
- [`google_compute_ssl_certificate.default`](https://www.terraform.io/docs/providers/google/r/compute_ssl_certificate.html): The certificate resource created when input `ssl` is `true`.
137-
- [`google_compute_url_map.default`](https://www.terraform.io/docs/providers/google/r/compute_url_map.html): The default URL map resource when input `url_map` is not provided.
138-
- [`google_compute_backend_service.default.*`](https://www.terraform.io/docs/providers/google/r/compute_backend_service.html): The backend services created for each of the `backend_params` elements.
139-
- [`google_compute_health_check.default.*`](https://www.terraform.io/docs/providers/google/r/compute_health_check.html): Health check resources create for each of the backend services.
140-
- [`google_compute_firewall.default-hc`](https://www.terraform.io/docs/providers/google/r/compute_firewall.html): Firewall rule created for each of the backed services to alllow health checks to the instance group.
134+
* [`google_compute_global_forwarding_rule.http`](https://www.terraform.io/docs/providers/google/r/compute_global_forwarding_rule.html): The global HTTP forwarding rule.
135+
* [`google_compute_global_forwarding_rule.https`](https://www.terraform.io/docs/providers/google/r/compute_global_forwarding_rule.html): The global HTTPS forwarding rule created when `ssl` is `true`.
136+
* [`google_compute_target_http_proxy.default`](https://www.terraform.io/docs/providers/google/r/compute_target_http_proxy.html): The HTTP proxy resource that binds the url map. Created when input `ssl` is `false`.
137+
* [`google_compute_target_https_proxy.default`](https://www.terraform.io/docs/providers/google/r/compute_target_https_proxy.html): The HTTPS proxy resource that binds the url map. Created when input `ssl` is `true`.
138+
* [`google_compute_ssl_certificate.default`](https://www.terraform.io/docs/providers/google/r/compute_ssl_certificate.html): The certificate resource created when input `ssl` is `true`.
139+
* [`google_compute_url_map.default`](https://www.terraform.io/docs/providers/google/r/compute_url_map.html): The default URL map resource when input `url_map` is not provided.
140+
* [`google_compute_backend_service.default.*`](https://www.terraform.io/docs/providers/google/r/compute_backend_service.html): The backend services created for each of the `backend_params` elements.
141+
* [`google_compute_health_check.default.*`](https://www.terraform.io/docs/providers/google/r/compute_health_check.html):
142+
Health check resources created for each of the (non global NEG) backend services.
143+
* [`google_compute_firewall.default-hc`](https://www.terraform.io/docs/providers/google/r/compute_firewall.html): Firewall rule created for each of the backed services to allow health checks to the instance group.

autogen/main.tf.tmpl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616

1717

1818
locals {
19-
address = var.create_address ? join("", google_compute_global_address.default.*.address) : var.address
20-
url_map = var.create_url_map ? join("", google_compute_url_map.default.*.self_link) : var.url_map
19+
address = var.create_address ? join("", google_compute_global_address.default.*.address) : var.address
20+
url_map = var.create_url_map ? join("", google_compute_url_map.default.*.self_link) : var.url_map
21+
health_checked_backends = { for backend_index, backend_value in var.backends : backend_index => backend_value if backend_value["health_check"] != null }
2122
}
2223

2324
resource "google_compute_global_forwarding_rule" "http" {
@@ -99,7 +100,7 @@ resource "google_compute_backend_service" "default" {
99100
connection_draining_timeout_sec = lookup(each.value, "connection_draining_timeout_sec", null)
100101
enable_cdn = lookup(each.value, "enable_cdn", false)
101102
security_policy = var.security_policy
102-
health_checks = [google_compute_health_check.default[each.key].self_link]
103+
health_checks = lookup(each.value, "health_check", null) == null ? null : [google_compute_health_check.default[each.key].self_link]
103104
session_affinity = lookup(each.value, "session_affinity", null)
104105
affinity_cookie_ttl_sec = lookup(each.value, "affinity_cookie_ttl_sec", null)
105106

@@ -136,7 +137,7 @@ resource "google_compute_backend_service" "default" {
136137

137138
resource "google_compute_health_check" "default" {
138139
provider = google-beta
139-
for_each = var.backends
140+
for_each = local.health_checked_backends
140141
project = var.project
141142
name = "${var.name}-hc-${each.key}"
142143

autogen/versions.tf.tmpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
terraform {
1818
required_version = "~> 0.12.6"
1919
required_providers {
20-
google = ">= 3.17, <4.0.0"
21-
google-beta = ">= 3.17, <4.0.0"
20+
google = ">= 3.32, <4.0.0"
21+
google-beta = ">= 3.32, <4.0.0"
2222
}
2323
}

docs/upgrading-v2.0.0-v3.0.0.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ The new version allows you to specify all of your backend configuration, includi
5656
```HCL
5757
module "gce-lb-http" {
5858
source = "GoogleCloudPlatform/lb-http/google"
59-
version = "3.0.0"
59+
version = "3.0.0"
6060
6161
name = "group-http-lb"
6262
target_tags = [module.mig1.target_tags, module.mig2.target_tags]
@@ -118,6 +118,7 @@ resource 'projects/[PROJECT]/global/httpHealthChecks/multi-mig-lb-http-backend-0
118118
is already being used by 'projects/[PROJECT]/global/backendServices/multi-mig-lb-http-backend-0',
119119
resourceInUseByAnotherResource
120120
```
121+
121122
The reason for this is that when we are changing the backend service and health check around, then must be destroyed and then re-created.
122123
The dependencies here are as follows:
123124

@@ -158,5 +159,3 @@ gcloud compute url-maps set-default-service multi-mig-lb-http-url-map \
158159
```
159160

160161
This will cut over your URL map to the new service. After that you'll only need to run `terraform apply` twice more to destroy the old backend and healthcheck resources. You'll do it twice because the backend takes a second to go away and the healthcheck can't be destroyed until the resources using it are also destroyed.
161-
162-

docs/upgrading_to_v4.0.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ The v4.0 release contains backwards-incompatible
44
changes to the backend config.
55

66
## Backend Config
7+
78
`session_affinity`, `affinity_cookie_ttl_sec`, and `log_config` must now be specified
89
for backends. To use the default value, specify `null`.
910

examples/multi-backend-multi-mig-bucket-https-lb/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ echo https://${EXTERNAL_IP}/group1/
7373
> You should see the GCP logo and instance details from the group in us-west1.
7474
7575
4. Open URL to route mapped to us-central1 instance group:
76+
7677
```
7778
echo https://${EXTERNAL_IP}/group2/
7879
```

examples/multiple-certs/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ echo https://${EXTERNAL_IP}/group1/
6969
> You should see the GCP logo and instance details from the group in us-west1.
7070
7171
4. Open URL to route mapped to us-central1 instance group:
72+
7273
```
7374
echo https://${EXTERNAL_IP}/group2/
7475
```

0 commit comments

Comments
 (0)