Skip to content

Commit bf86778

Browse files
committed
fix: added validation in internal_forwarding_rules_cnfig variable
1 parent 5c9e933 commit bf86778

File tree

4 files changed

+12
-7
lines changed

4 files changed

+12
-7
lines changed

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,10 @@ module "internal-lb-http-frontend" {
120120
{
121121
"region" : "us-east1",
122122
"subnetwork" : module.internal-lb-subnet.subnets["us-east1/int-lb-subnet-a"].id,
123-
"create_proxy_only_subnet" : false,
124123
},
125124
{
126125
"region" : "us-south1",
127126
"subnetwork" : module.internal-lb-subnet.subnets["us-south1/int-lb-subnet-b"].id,
128-
"create_proxy_only_subnet" : false,
129127
}
130128
]
131129
}

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\_rules\_config | List of internal managed forwarding rules config. One of 'address' or 'subnetwork' is required for each. If 'create\_proxy\_only\_subnet' is true, 'proxy\_only\_subnet\_ip' is required. It is only applicable for internal load balancer. | <pre>list(object({<br> region = string<br> address = optional(string)<br> subnetwork = optional(string)<br> create_proxy_only_subnet = bool<br> proxy_only_subnet_ip = 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. If 'create\_proxy\_only\_subnet' is true, 'proxy\_only\_subnet\_ip' is required. It is only applicable for internal load balancer. | <pre>list(object({<br> region = string<br> address = optional(string)<br> subnetwork = optional(string)<br> create_proxy_only_subnet = optional(bool, false)<br> proxy_only_subnet_ip = optional(string, "10.127.0.0/23")<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, INTERNAL\_MANAGED for internal load balancer and INTERNAL\_SELF\_MANAGED for traffic director) | `string` | `"EXTERNAL_MANAGED"` | no |

modules/frontend/metadata.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -196,8 +196,8 @@ spec:
196196
region = string
197197
address = optional(string)
198198
subnetwork = optional(string)
199-
create_proxy_only_subnet = bool
200-
proxy_only_subnet_ip = optional(string)
199+
create_proxy_only_subnet = optional(bool, false)
200+
proxy_only_subnet_ip = optional(string, "10.127.0.0/23")
201201
}))
202202
defaultValue: []
203203
outputs:

modules/frontend/variables.tf

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,15 @@ variable "internal_forwarding_rules_config" {
205205
region = string
206206
address = optional(string)
207207
subnetwork = optional(string)
208-
create_proxy_only_subnet = bool
209-
proxy_only_subnet_ip = optional(string)
208+
create_proxy_only_subnet = optional(bool, false)
209+
proxy_only_subnet_ip = optional(string, "10.127.0.0/23")
210210
}))
211211
default = []
212+
validation {
213+
condition = alltrue([
214+
for rule in var.internal_forwarding_rules_config :
215+
rule.address != null || rule.subnetwork != null
216+
])
217+
error_message = "Each internal forwarding rule config must specify either 'address' or 'subnetwork'."
218+
}
212219
}

0 commit comments

Comments
 (0)