Skip to content

Commit 898f21c

Browse files
committed
fix: added allow_proxy firewall rule to create connection between fw rule and mig
1 parent e70f5d4 commit 898f21c

File tree

4 files changed

+35
-0
lines changed

4 files changed

+35
-0
lines changed

modules/backend/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This module creates `google_compute_backend_service` resource and its dependenci
1717
| enable\_cdn | Enable Cloud CDN for this BackendService. | `bool` | `false` | no |
1818
| firewall\_networks | Names of the networks to create firewall rules in | `list(string)` | <pre>[<br> "default"<br>]</pre> | no |
1919
| firewall\_projects | Names of the projects to create firewall rules in | `list(string)` | <pre>[<br> "default"<br>]</pre> | no |
20+
| firewall\_source\_ranges | Source ranges for global Application Load Balancer's proxies. This should be set to ip\_cidr\_range of your REGIONAL\_MANAGED\_PROXY subnet. | `list(string)` | <pre>[<br> "10.129.0.0/23"<br>]</pre> | no |
2021
| groups | The list of backend instance group which serves the traffic. | <pre>list(object({<br> group = string<br> description = optional(string)<br><br> balancing_mode = optional(string)<br> capacity_scaler = optional(number)<br> max_connections = optional(number)<br> max_connections_per_instance = optional(number)<br> max_connections_per_endpoint = optional(number)<br> max_rate = optional(number)<br> max_rate_per_instance = optional(number)<br> max_rate_per_endpoint = optional(number)<br> max_utilization = optional(number)<br> }))</pre> | `[]` | no |
2122
| health\_check | Input for creating HttpHealthCheck or HttpsHealthCheck resource for health checking this BackendService. A health check must be specified unless the backend service uses an internet or serverless NEG as a backend. | <pre>object({<br> host = optional(string, null)<br> request_path = optional(string, null)<br> request = optional(string, null)<br> response = optional(string, null)<br> port = optional(number, null)<br> port_name = optional(string, null)<br> proxy_header = optional(string, null)<br> port_specification = optional(string, null)<br> protocol = optional(string, null)<br> check_interval_sec = optional(number, 5)<br> timeout_sec = optional(number, 5)<br> healthy_threshold = optional(number, 2)<br> unhealthy_threshold = optional(number, 2)<br> logging = optional(bool, false)<br> })</pre> | `null` | no |
2223
| host\_path\_mappings | The list of host/path for which traffic could be sent to the backend service | <pre>list(object({<br> host = string<br> path = string<br> }))</pre> | <pre>[<br> {<br> "host": "*",<br> "path": "/*"<br> }<br>]</pre> | no |

modules/backend/main.tf

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -289,3 +289,24 @@ resource "google_compute_firewall" "default-hc" {
289289
ports = var.health_check.port != null ? [var.health_check.port] : null
290290
}
291291
}
292+
293+
resource "google_compute_firewall" "allow_proxy" {
294+
count = var.health_check != null ? length(var.firewall_networks) : 0
295+
project = length(var.firewall_networks) == 1 && var.firewall_projects[0] == "default" ? var.project_id : var.firewall_projects[count.index]
296+
name = "${var.name}-fw-allow-proxies-${count.index}"
297+
network = var.firewall_networks[count.index]
298+
source_ranges = var.firewall_source_ranges
299+
target_tags = length(var.target_tags) > 0 ? var.target_tags : null
300+
allow {
301+
ports = ["443"]
302+
protocol = "tcp"
303+
}
304+
allow {
305+
ports = ["80"]
306+
protocol = "tcp"
307+
}
308+
allow {
309+
ports = ["8080"]
310+
protocol = "tcp"
311+
}
312+
}

modules/backend/metadata.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ spec:
5252
location: examples/https-redirect
5353
- name: internal-lb-cloud-run
5454
location: examples/internal-lb-cloud-run
55+
- name: internal-lb-gce-mig
56+
location: examples/internal-lb-gce-mig
5557
- name: lb-http-separate-frontend-and-backend
5658
location: examples/lb-http-separate-frontend-and-backend
5759
- name: mig-nat-http-lb
@@ -286,6 +288,11 @@ spec:
286288
description: List of target service accounts for health check firewall rule. Exactly one of target_tags or target_service_accounts should be specified.
287289
varType: list(string)
288290
defaultValue: []
291+
- name: firewall_source_ranges
292+
description: Source ranges for global Application Load Balancer's proxies. This should be set to ip_cidr_range of your REGIONAL_MANAGED_PROXY subnet.
293+
varType: list(string)
294+
defaultValue:
295+
- 10.129.0.0/23
289296
outputs:
290297
- name: backend_service_info
291298
description: Host, path and backend service mapping

modules/backend/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,9 @@ variable "target_service_accounts" {
269269
type = list(string)
270270
default = []
271271
}
272+
273+
variable "firewall_source_ranges" {
274+
description = "Source ranges for global Application Load Balancer's proxies. This should be set to ip_cidr_range of your REGIONAL_MANAGED_PROXY subnet."
275+
type = list(string)
276+
default = ["10.129.0.0/23"]
277+
}

0 commit comments

Comments
 (0)