-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
google_compute_backend_service failing to apply multiple backends #3937
Comments
I have the same issue:
I also use dynamic block, funny thing is that is I apply again, it works... nevertheless it's quite annoying. |
I believe this is a variant of #4328, although I'm not sure. I haven't gotten the chance to dig in more, and likely won't for a while so I'm unassigning myself so someone else can pick it up if they're available. |
Similar issue using dynamic over backend block
error after apply:
If I apply it just one more time does works |
@rileykarson - I had a read through of that issue, but perhaps someone could explain it layman's terms? My rough interpretation is that going forwards in the provider that you can't use I've revisited this and I am in a similar place to @vigohe - except I cannot apply my plan more than once. When I re-plan with TF I get the following output:
(where I REDACTED_URL - the urls were right to the correct instance groups) So I checked in the UI and the
^ same error for all 3 similar backend_service. For reference this is my code snippets: # From my cluster moduel
output "K8S_INSTANCE_GROUP_URLS" {
value = data.google_container_cluster.information.instance_group_urls
description = "URLs to the instance groups for all nodes"
}
# Var in put in lb module
variable "backend_group_list" {
description = "Map backend indices to list of backend maps."
type = list
default = []
}
# main.tf that call lb module
...
backend_group_list = module.cluster.K8S_INSTANCE_GROUP_URLS
...
# The backen_service dynamic block
...
dynamic "backend" {
for_each = var.backend_group_list
content {
group = backend.value
// adding null values otherwise reapplication fails
balancing_mode = null
capacity_scaler = null
description = null
max_connections = null
max_connections_per_instance = null
max_rate = null
max_rate_per_instance = null
max_utilization = null
}
}
... Going back to the linked issue - the output Does TF not render dynamic blocks at planning? Even if the input is already available to iterate over? My TF commands for reference:
And some up to date version when testing today
Note - I upgraded providers & same issue. eg. provider.google v2.18.0 |
The linked issue doesn't seem to be related, we encounter a similar error when values change at apply time. The proposal in the issue is that we set the value from the user's config in state instead of the API-returned value. They're equivalent, but Terraform Core can't tell. Terraform This looks related to dynamic blocks instead, and is probably a |
👍 for speedy reply. It looks to be getting the right response back from google in terms of all the nulls have been replaced with the default values for the instance groups. But that about as much as I can gleam from there. |
@paddycarver can you take a look? You've got the key + probably more context on dynamic than I do. |
So I've worked out that at least in my instance, the issue seems not to be build time as it will build fresh as desired even if the plan doesn't show you the dynamic block output. (destroyed all the module.cluster-lb resources and built fresh) The issue is once the Whilst I rarely make changes to a |
Same issue. The solution by @vigohe works for me. I have to apply twice, but it works. Changes/deletes/adds after that all work as expected.
In this case, var.lb_service_groups is a map |
We're seeing this issue with our integration tests, because idempotency is one thing we're testing for, would prefer not to simply reapply. |
I bit the bullet and moved one of my projects to use my 0.12 updated code. Unfortunately I don't seem to be able apply again in my case, as suggested in other comments. I use the following commands:
I checked it wasn't due to
Version are:
Note that my input to the dynamic block GROUPS = [
"https://www.googleapis.com/compute/v1/projects/<redacted>..",
"https://www.googleapis.com/compute/v1/projects/<redacted>..",
"https://www.googleapis.com/compute/v1/projects/<redacted>..",
] I am also not using the @ogreface - do you generate |
Actually think I have resolved my issue after some poking around. tl;drIssue was passing the results of a data lookup (on the k8s cluster) as an output in one module(gcloud-k8s), and trying to use those as the input to another module (gcloud-lb-custom). longer readI had a setup as such:
What I was doingIn each environment, I'd call my module ( Then I'd build the load balancer through my next module ( backend_group_list = module.cluster.K8S_INSTANCE_GROUP_URLS This has been erroring ever since upgrading to 0.12. It used to work in 0.11. Hence raising this issue. What I changed to see if my loop was correctI basically took the output from This made me think the issue was something to do with me passing input to one module from the output of another. What I'm now doingI've moved that data lookup into the lb module ( module "cluster-lb" {
source = "../terraform-modules/gcloud-lb-custom"
cluster = module.cluster.K8S_NAME
cluster_zone = module.cluster.K8S_ZONE
...
} Inside the cluster module: data "google_container_cluster" "hack" {
name = var.cluster
zone = var.cluster_zone
project = var.project
} And further down in the module, use that lookup to pass in the list of dynamic "backend" {
for_each = data.google_container_cluster.hack.instance_group_urls
content {
group = backend.value
// adding null values otherwise reapplication fails
balancing_mode = "UTILIZATION"
capacity_scaler = 1
description = null
max_connections = 0
max_connections_per_instance = 0
max_rate = 0
max_rate_per_instance = 0
max_utilization = 0.8
}
} It seems to work fairly well now so far. I did also upgrade the google provider to latest:
TILProbably not the first or last time I'll be bitten by passing things from one module to another. Arguably its cleaner to fetch the urls inside the load balancer module but I would have thought the output would be stored in state and used during the plan (probably misunderstanding internal workings of terraform plan). As a side effect, I have yet to see that error message again, but will be doing lots of testing around this. |
Not data providers technically, but they are references to other blocks in the same module. Glad you have a solution though! |
Same issue. Errors on first apply, passes on second apply I've tried the work around described by @hawksight however based on the way that I'm dynamically assigning the backend blocks I get a splat error instead. This may or may not be related to how the dependency graph gets walked.
So next, I tried to pass the attribute to the module as a variable.
This seems to works, but now gives me the same error as @vigohe
Main concern:
|
Not 100% sure if it's the cause of this or not, but one thing we noticed is that for resource creation, the dependency order is "backend => urlmap"; for deletion it's "urlmap => backend". For modification, it will try to use the same order as creation |
* suppress diff for secret_access_key on bigquery data transfer params * add sensitiveParams for secret access key * add customize diff, fix spelling * add custom import and post create Signed-off-by: Modular Magician <[email protected]>
* suppress diff for secret_access_key on bigquery data transfer params * add sensitiveParams for secret access key * add customize diff, fix spelling * add custom import and post create Signed-off-by: Modular Magician <[email protected]>
- dynamic backend issue hashicorp/terraform-provider-google#3937
- dynamic backend issue hashicorp/terraform-provider-google#3937
@c2thorn could you take a look to verify whether these are duplicates? |
After discussing offline, it is likely that #4543 gets resolved as the same time as this, but we'll keep this bug open since it stems from a different user action. |
Community Note
Description of Problem
I'm experiencing issues when trying to build a
google_compute_backend_service
with multiplebackends
(instance groups) in order to target all the nodes of my GKE cluster.I have
cluster
module & acluster-lb
module which I execute from an environment terraform configuration. I am outputting the instance groups at the end of the cluster module based on a data resource to ensure I get the urls to all cluster nodes eg..For simplicity sake I am taking a variable in the
cluster-lb
module which is that list.In my module code I am trying to configure the
backend
subblock as described here, which has a specific format of (i think):(seems to be what this imples)
or backend block is specified twice?
The topic of documentation is covered in #3498 and I initially added some error logs in this comment.
Terraform Version
Affected Resource(s)
Terraform Configuration Files
cluster-lb
module backendsDebug Output
I've posted the encrypted version (sing hashicorp key from keybase) in this gist:
https://gist.github.com/hawksight/bde83268020c8701fc9ac35c1b6d3fb8
Used the following to encrypt:
Wasn't confident there wouldn't be any sensitive details in the debug log, hence encryption.
Let me know if I need to share another way.
Panic Output
None
Expected Behavior
I have three backends which I am manually specifying with different names. They are all backends to the same set of GKE nodes. Our clusters use multi-zone node pools and usually have two node pools. In GKE, this means you have an instance group for each zone for each node pool. In the example I am showing here, I have setup with two node pools in a single zone, so two instance groups equating to two backends to specify.
In the plan I expect to see two
backend
blocks as I am using the dynamic` provisioner from 0.12 to generate a block for each group URL / self-link passed in.In the application I expect the backend to be created and have both instance groups as its target, not the fail with the error provided.
Actual Behavior
The plan worked although it only specifies one backend in the output.
It only knows the groups after application, which I find unhelpful.
Even when the cluster is prebuilt the plan still doesn't see that I have more than one instance group to add. This is probably something to with the way terraform plans things, but unsure on specifics.
Here's an example plan output:
I get the following errors when trying to apply:
Steps to Reproduce
Create a backend_service and try to pass multiple groups to it by dynamically generating using a dyanmic block or other loop method. Use my coder as an example?
Try to plan and see if you get multiple backends specified
Apply and see if you get errors.
Important Factoids
I've recently been upgrading to 0.12, so I really don't know if my
dyanmic
block is the right solution, or if I can use afor_each
instead or some combination. I've found it quite hard toi distinguish from the limited examples when each variation / combination of:for
,for_each
anddynamic
should be used.My code works perfectly when there is only on instance group in the list. But I only tried that to prove out the code if TF compliant. My real world use case always has many instance groups to add.
Notice on my private backend service, I have explicitly set all the other block options to null. This is because when I did successfully build with one instance group, the subsequent application failed because the attributes were not set. So on re-application those parameters seem to not be optional anymore, hence the
null
values. Thanks to the author of this comment for the example.I also tried turning my input list into the format:
References
b/374162106
The text was updated successfully, but these errors were encountered: