Open wouterdegeus opened 2 years ago
Note: This may be fairly complicated- ordering objects in the provider correctly when they're not ordered that way in config pretty easily causes Terraform to have a permadiff
Has anyone managed to get this working with the current provider lacking the required functionality? I really need this, but every workaround thus far has been a dead end. Thought I'd at least ask here to potentially save a lot of time.
Honestly I don't think there is a viable workaround, also given this https://github.com/hashicorp/terraform/issues/30841
Hi - me again. Glad to tell you I've found a viable fix.
What you need to do, is that the dynamic blocks you use - will ALWAYS have an increasing priority in your plan. Terraform isn't executing parrallel API requests that is causing this issue, rather it's constructing a single request in which the order of the routing rules are in a wrong order. So if you fix the order, you fix the problem.
The reason you get the 100 prio error, is becausing the 200 prio routing rule is before it. Hence it errors. Switch it around and it will work.
Example of how your plan should look like;
A general (anonymized) example how how I did this (this ensure Terraform sorts based on prio correctly as well - hence the format);
locals {
bypass_paths = distinct([
"/log1",
"/health1",
"/log2",
"/health2",
])
}
dynamic route_rules {
for_each = { for idx, path in local.bypass_paths : format("%03d", idx) => path }
content {
priority = route_rules.key
service = google_compute_backend_service.lb_backend_without_iap.id
match_rules {
full_path_match = route_rules.value
}
}
}
You can chain multiple dynamic blocks as well, by adding e.g. the length of a tuple as part of the for loop idx.
@rileykarson What is the suggested solution to this problem then? As you said a regular manual fix can lead to problems. @fancybear-dev proved there is a simple way to use priorities here. Gcloud also doesn't reorder given input. Is this just "as designed"?
Community Note
modular-magician
user, it is either in the process of being autogenerated, or is planned to be autogenerated soon. If an issue is assigned to a user, that user is claiming responsibility for the issue. If an issue is assigned tohashibot
, a community member has claimed the issue already.Terraform Version
Terraform v1.0.11 on darwin_amd64
Affected Resource(s)
Terraform Configuration Files
In this case I was trying to create a url_map with multiple routing routes that have different priorities and matching rules, in this case one with a header match and one without. Both using a regex_match.
Expected Behavior
I expected the URL Map to be created properly, with multiple routing rules depending on the iap flag.
Actual Behavior
Plan output looked sane, multiple routing rules with different priorities are shown.![image](https://user-images.githubusercontent.com/56300370/152809878-4fc83609-c50d-4b32-af74-d9687509408d.png)
However, the apply errors with:
Since I can not influence the order in which for_each iterates over the set, this can not be fixed easily by the user. The provider should do the sensible thing here and order the routing rules by priority as demanded.
Steps to Reproduce
terraform apply
Important Factoids
References
0000
b/312911334