-
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_cloudfunctions2_function event_filter causes "Provider produced inconsistent final plan" #20969
Comments
Hi @dan-drew I tried to replicate this issue, but everything looks good without errors. have you assigned the correct roles to use You may check the following used code (based on this example: link here) to check if you have the correct configuration:
If after this you are still having issues please share with us your full code of all involved resources WITHOUT USING MODULES, LOCALS OR VARIABLES to make a new try. For sensitive data you could use examples like:
|
Yes, everything works great when I don't hit this error and as I listed in the repro instructions I just have to run the exact same One thing that's different is that for some reason the resource ID in my case has been tagged as sensitive. I never do this explicitly so maybe an issue somewhere else in the google provider. A more full example would be like below with a couple module layers, but maybe you could try something simpler like adding a fake sensitive variable?
variable method_name {
type = string
default = "v1.compute.instances.start"
}
resource function... {
event_filter {
value = var.method_name
}
} Full Exampleterraform-module-1resource google_compute_instance instance {
# ...
}
output gcp_instance {
value = google_compute_instance.instance
} terraform-module-2module gcp_instance {
source = ".../terraform-module-1"
}
output gcp_instance {
value = module.gcp_instance.instance
} my-projectmodule instance {
source = "../terraform-module-2"
}
# NOTE: For some reason module.instance.gcp_instance is now marked SENSITIVE
resource "google_cloudfunctions2_function" "setup" {
# ...
event_trigger {
event_type = "google.cloud.audit.log.v1.written"
retry_policy = "RETRY_POLICY_RETRY"
event_filters {
attribute = "serviceName"
value = "compute.googleapis.com"
}
event_filters {
attribute = "methodName"
value = "v1.compute.instances.start"
}
event_filters {
attribute = "resourceName"
value = module.instance.gcp_instance.id # Marked SENSITIVE
}
}
} |
Sorry @dan-drew this is not clear at all, so were you able to solve it? |
No, just that I'm not blocked because the workaround is to run apply again. This was stated in the steps to reproduce:
The main additional info I added above is about whether "sensitive" values were tripping it up somehow. Previous errors I've gotten were specifically about the sensitive flag being inconsistent. If this isn't making sense or you can't repro, feel free to punt back to me until I have a chance to better repro myself with debug logging on. |
I tried again but everything works fine without errors with just 1 |
I'm experiencing something similar. Upgraded from provider v5.29.1 to v6.17.0 and then get an issue with google_cloud_run_v2_service resource (elided):
The plan shows as deleting all the existing env vars and creating new ones. Here is an elided service definition
Similarly, I was able to |
That's interesting, I've definitely also seen this when the only change was to the function env vars. |
Have you tried with the base terraform resources without using modules? |
@ggtisc is this question for me? no I have not tried that adding to my report, the "double apply" workaround does not actually work for me. or rather, any time there is a change to my cloud run service, the initial apply fails and a second apply is needed. (same error messages relating to env vars) this means that my CI pipelines continually fail, unless I built in double apply to the pipelines which doesn't seem great |
Please do it @micahjsmith, I've tried many times with the base code without modules, which means this is just a mistake in the configuration. |
hi @ggtisc I'm happy to try to debug, but I'm not able to refactor my code to not use modules. was that what you were suggesting?
apologies if I am missing something, but |
After many tries I was not able to reproduce the issue, since I can't access the whole configuration of user's modules and user's can't replicate the shared code I'm forwarding this issue for a deep review |
Ok, trying to debug this a bit. @micahjsmith I'm guessing the issue has to do with the client secret, though I can't be sure. Can you try a couple of steps to see if it resolves the issue?
If the secret is the problem and we can identify what exactly about the string is triggering this we would have a better shot at fixing it. @dan-drew similarly, if you remove the event_filter with the sensitive value, does it fix the issue? |
@slevenick I'll see if I can find time to try things out today or tomorrow. Been down with a flu. |
@slevenick thank you for the constructive suggestion, will try this and let you know shortly |
@slevenick I first confirmed that my code was still failing during apply with the same error message as I reported above. then, followed step 1, and inlined the secret name
the generated plan looked the same as before, where every secret was shown as deleted and then added in the same op however, this time, the apply ran successfully afterwards, I reverted the change, so the secret names were no longer inlined. again, the plan showed all secrets being deleted and added together. this time, the apply also ran successfully. seems like I am now happily on v6.17 after this workaround I have executed this op in my staging environment, but not yet in my prod environment which is presumably still "broken" per above (until later tonight). if helpful I can do any comparisons between the environments that you need, unless I fix prod first |
Very strange that it works with the initial config after the successful apply with the inlined secret. Generally how the "inconsistent final plan" error shows up is that a value is changing between plan and apply time, usually from an unknown value to a known value. That's why inlining the secret name works, because we're getting rid of the dependency and any possibility of that value changing between runs. I don't know why going back to using the reference now works, but I'm glad you have a workaround! |
@micahjsmith I'm guessing here, but it's probably working because you've got the values in state via the successful apply with the inlined secret. Then subsequent applies already "know" the value of the reference so there's no inconsistent result. You may run into this issue again if you fully destroy and recreate the environment. Another possible workaround may be a 2-step apply, where you create the secret data source first in a separate apply, and then create the Cloud Run service in the second apply. Just wanted to flag that as a potential option |
Community Note
Terraform Version & Provider Version(s)
Terraform v1.9.8
on linux amd64
Affected Resource(s)
google_cloudfunctions2_function
Terraform Configuration
Debug Output
Let me know if needed, haven't run yet with full debug logging
Expected Behavior
Changes should apply successfully every time.
Actual Behavior
Every other time the plan runs, the following errors occur:
Steps to reproduce
Apply change for the first time to create the function
Make a change to the function code for example to cause it to need an update
Apply fails with errors described in Actual Behavior.
Immediate run apply again.
Apply succeeds as expected
Important Factoids
Authenticating as a user with full permissions to run the required operations.
References
No response
b/392615192
The text was updated successfully, but these errors were encountered: