Skip to content

Commit 599fbcd

Browse files
committed
fix: using list of object type for the new variable
1 parent 4da3558 commit 599fbcd

File tree

5 files changed

+25
-17
lines changed

5 files changed

+25
-17
lines changed

examples/internal-lb-cloud-run/main.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,14 +116,14 @@ module "internal-lb-http-frontend" {
116116
url_map_input = module.internal-lb-http-backend.backend_service_info
117117
network = module.internal-lb-network.network_name
118118
load_balancing_scheme = "INTERNAL_MANAGED"
119-
internal_forwarding_rule_configs = {
120-
"1" : {
119+
internal_forwarding_rules_config = [
120+
{
121121
"subnetwork" : module.internal-lb-subnet.subnets["us-east1/int-lb-subnet-a"].id
122122
},
123-
"2" : {
123+
{
124124
"subnetwork" : module.internal-lb-subnet.subnets["us-south1/int-lb-subnet-b"].id
125125
}
126-
}
126+
]
127127
}
128128

129129
resource "google_vpc_access_connector" "internal_lb_vpc_connector" {

modules/frontend/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ This module creates `HTTP(S) forwarding rule` and its dependencies. This modules
1919
| http\_port | The port for the HTTP load balancer | `number` | `80` | no |
2020
| https\_port | The port for the HTTPS load balancer | `number` | `443` | no |
2121
| https\_redirect | Set to `true` to enable https redirect on the lb. | `bool` | `false` | no |
22-
| internal\_forwarding\_rule\_configs | Map of internal managed forwarding rule configs. One of 'address' or 'subnetwork' is required for each. | <pre>map(object({<br> address = optional(string)<br> subnetwork = optional(string)<br> }))</pre> | `{}` | no |
22+
| internal\_forwarding\_rules\_config | List of internal managed forwarding rules config. One of 'address' or 'subnetwork' is required for each. | <pre>list(object({<br> address = optional(string)<br> subnetwork = optional(string)<br> }))</pre> | `[]` | no |
2323
| ipv6\_address | An existing IPv6 address to use (the actual IP address value) | `string` | `null` | no |
2424
| labels | The labels to attach to resources created by this module | `map(string)` | `{}` | no |
2525
| load\_balancing\_scheme | Load balancing scheme type (EXTERNAL for classic external load balancer, EXTERNAL\_MANAGED for Envoy-based load balancer, and INTERNAL\_SELF\_MANAGED for traffic director) | `string` | `"EXTERNAL_MANAGED"` | no |

modules/frontend/main.tf

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ resource "google_compute_global_forwarding_rule" "http" {
5858
}
5959

6060
resource "google_compute_global_forwarding_rule" "internal_managed_http" {
61-
for_each = local.create_http_forward && local.is_internal_managed ? var.internal_forwarding_rule_configs : {}
61+
for_each = local.create_http_forward && local.is_internal_managed ? {
62+
for index, config in var.internal_forwarding_rules_config : index => config
63+
} : {}
6264

6365
provider = google-beta
6466
project = var.project_id
@@ -86,7 +88,9 @@ resource "google_compute_global_forwarding_rule" "https" {
8688
}
8789

8890
resource "google_compute_global_forwarding_rule" "internal_managed_https" {
89-
for_each = var.ssl && local.is_internal_managed ? var.internal_forwarding_rule_configs : {}
91+
for_each = var.ssl && local.is_internal_managed ? {
92+
for index, config in var.internal_forwarding_rules_config : index => config
93+
} : {}
9094

9195
provider = google-beta
9296
project = var.project_id
@@ -125,7 +129,9 @@ resource "google_compute_global_forwarding_rule" "http_ipv6" {
125129
}
126130

127131
resource "google_compute_global_forwarding_rule" "internal_managed_http_ipv6" {
128-
for_each = var.enable_ipv6 && local.create_http_forward && local.is_internal_managed ? var.internal_forwarding_rule_configs : {}
132+
for_each = var.enable_ipv6 && local.create_http_forward && local.is_internal_managed ? {
133+
for index, config in var.internal_forwarding_rules_config : index => config
134+
} : {}
129135

130136
provider = google-beta
131137
project = var.project_id
@@ -152,7 +158,9 @@ resource "google_compute_global_forwarding_rule" "https_ipv6" {
152158
}
153159

154160
resource "google_compute_global_forwarding_rule" "internal_managed_https_ipv6" {
155-
for_each = var.enable_ipv6 && var.ssl && local.is_internal_managed ? var.internal_forwarding_rule_configs : {}
161+
for_each = var.enable_ipv6 && var.ssl && local.is_internal_managed ? {
162+
for index, config in var.internal_forwarding_rules_config : index => config
163+
} : {}
156164

157165
provider = google-beta
158166
project = var.project_id

modules/frontend/metadata.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,14 @@ spec:
187187
- name: http_keep_alive_timeout_sec
188188
description: Specifies how long to keep a connection open, after completing a response, while there is no matching traffic (in seconds).
189189
varType: number
190-
- name: internal_forwarding_rule_configs
191-
description: Map of internal managed forwarding rule configs. One of 'address' or 'subnetwork' is required for each.
190+
- name: internal_forwarding_rules_config
191+
description: List of internal managed forwarding rules config. One of 'address' or 'subnetwork' is required for each.
192192
varType: |-
193-
map(object({
193+
list(object({
194194
address = optional(string)
195195
subnetwork = optional(string)
196196
}))
197-
defaultValue: {}
197+
defaultValue: []
198198
outputs:
199199
- name: external_ip
200200
description: The external IPv4 assigned to the global fowarding rule.

modules/frontend/variables.tf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -199,11 +199,11 @@ variable "http_keep_alive_timeout_sec" {
199199
default = null
200200
}
201201

202-
variable "internal_forwarding_rule_configs" {
203-
description = "Map of internal managed forwarding rule configs. One of 'address' or 'subnetwork' is required for each."
204-
type = map(object({
202+
variable "internal_forwarding_rules_config" {
203+
description = "List of internal managed forwarding rules config. One of 'address' or 'subnetwork' is required for each."
204+
type = list(object({
205205
address = optional(string)
206206
subnetwork = optional(string)
207207
}))
208-
default = {}
208+
default = []
209209
}

0 commit comments

Comments
 (0)