-
Notifications
You must be signed in to change notification settings - Fork 982
Route Rules need to be sorted in priority order in module net-lb-app-ext #2095
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Full repro, using examples: module "compute-vm-group-b" {
source = "./fabric/modules/compute-vm"
project_id = var.project_id
zone = "${var.region}-b"
name = "my-ig-b"
network_interfaces = [{
network = var.vpc.self_link
subnetwork = var.subnet.self_link
}]
boot_disk = {
initialize_params = {
image = "cos-cloud/cos-stable"
}
}
group = { named_ports = {} }
}
module "compute-vm-group-c" {
source = "./fabric/modules/compute-vm"
project_id = var.project_id
zone = "${var.region}-c"
name = "my-ig-c"
network_interfaces = [{
network = var.vpc.self_link
subnetwork = var.subnet.self_link
}]
boot_disk = {
initialize_params = {
image = "cos-cloud/cos-stable"
}
}
group = { named_ports = {} }
}
module "glb-0" {
source = "./fabric/modules/net-lb-app-ext"
project_id = var.project_id
name = "glb-test-0"
backend_service_configs = {
default = {
backends = [{
backend = module.compute-vm-group-b.group.id
}]
}
other = {
backends = [{
backend = module.compute-vm-group-c.group.id
}]
}
}
urlmap_config = {
default_service = "default"
host_rules = [{
hosts = ["*"]
path_matcher = "pathmap"
}]
path_matchers = {
pathmap = {
default_service = "default"
route_rules = [
{
priority = 3
service = "default"
header_action = {
request_add = {
test-priority-3 = {
value = "prio-3"
}
}
}
},
{
priority = 10
service = "default"
header_action = {
request_add = {
test-priority-1 = {
value = "prio-1"
}
}
}
},
{
priority = 2
service = "default"
header_action = {
request_add = {
test-priority-2 = {
value = "prio-2"
}
}
}
}
]
}
}
}
}
Fails with expected:
|
@cavila-evoliq for_each = { for value in m.value.route_rules : format("%010d", value.priority) => value } This way, the keys when sorted in lexicographical are still in the same order as numerical order. Can you confirm that this solves your issue? |
Wouldn't it be easier to just use the list in the for_each? This seems to work: locals {
rules = [
{ priority = 2 },
{ priority = 3 },
{ priority = 10 },
{ priority = 150 },
]
}
resource "google_compute_url_map" "urlmap" {
name = "urlmap"
default_service = "service"
project = "myproject"
path_matcher {
name = "name"
dynamic "route_rules" {
for_each = local.rules
content {
priority = route_rules.value.priority
}
}
}
}
|
For some reason I thought dynamic blocks had the same for_each restriction as resources and would require being converted to a set, I assumed that's why it was done in the first place. But yeah, lists maintain their order so since the dynamic block accepts a list, that would be the ideal solution. |
@cavila-evoliq can you try #2096 and confirm if it works for you? |
I was under that impression too but the docs say @wiktorn We should probably check if we have the same issue in other dynamic blocks elsewhere |
Just tested the changes in our dev environment and it works great! |
Awesome. It's merged into main now so I'm closing this. Thanks for the report @cavila-evoliq! |
Describe the bug
In the urlmap_config variable, the route_rules nested under path_matchers are being used as an iterator for a dynamic block here: link.
We are having problems with this approach. When defining priority, the order of the elements is important as the GCP API requires rules be sorted in increasing-priority order. Using
toset()
does not allow us to pass the list in any particular order, so Terraform sorts it. In our case, it kept sorting a rule with priority 120 above a rule with 119, breaking it.Environment
To Reproduce
Define a URL Map Config and create multiple route rules of varying priorities under a single path_matcher.
Expected behavior
Route Rules are defined in the supplied order/priority
Result
Additional context
I was able to work around the problem by converting the route_rules variable type from
list(object)
tomap(object)
and removingtoset()
from the the module in a fork and set the priority as the key but this is also a flawed approach as maps are sorted in lexicographical order so a map of{1: "test", 3: "test", 120: "test"
is sortedI'm not sure what the right solution to this is, hence this issue.
The text was updated successfully, but these errors were encountered: