-
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
Use of a "set" for containers.env prevents lifecycle ignoring individual environment variables #20663
Comments
I was able to devise a pretty terrible workaround. By pre-reading the existing job as a data source, and using a data "google_cloud_run_v2_service" "example" {
name = "example"
location = "europe-west1"
} dynamic "env" {
for_each = toset([
for env in data.google_cloud_run_v2_service.example.template[0].containers[0].env :
env if contains(["DYNAMIC_FOO"], env.name)
])
content {
name = env.value.name
value = env.value.value
}
} |
It's not apparent to me what we can do about this from the provider code. The lifecycle argument is controlled by core Terraform. Making the field a set is our best known fix for diffs related to the list ordering, which is what #17607 was. Unless another solution can be found, I'm marking this as blocked by upstream Terraform hashicorp/terraform#26359 |
@c2thorn How about a map like |
If I'm understanding what you mean, you want to represent container.env which is a list/set of objects in the API into a map where the key is the env I suppose that could be done as a new field, with custom expander/flattener logic that translates to and from the API's structure. We normally do not want to deviate from the API's structure where possible, and we would definitely not want to change the original container.env field's structure yet again just to fix this issue. A new Terraform-only field to workaround this problem could be possible, but very non-standard and would need to be maintained going forward. I'll leave it to the Cloud run service team to determine if this is the route they want to go for this issue. |
@c2thorn That's exactly right. I think that would solve both the problem of ordering and addressability; which seems to me like it would make this resource a lot more usable for the end user. I definitely understand the concern about making the resource more complicated to maintain and would also be fine with any other workaround; I'm just not sure how you'd do it with the current limitations of Terraform itself and my impression from the discussion in that issue is that there isn't an easy fix they can do either. |
Community Note
Terraform Version & Provider Version(s)
Terraform v1.10.1
on darwin_arm64
Affected Resource(s)
Terraform Configuration
Debug Output
No response
Expected Behavior
It does not seem like that uncommon of a use case to have some environment variables that are managed by Terraform, and other "dynamic" environment variables managed by another process. Perhaps a common example would be a "RELEASE" environment variable that is being auto-incremented by a continuous deployment process.
To that end, I would like to be able to use
lifecycle ignore_changes
on mygoogle_cloud_run_v2_job
environment.When the
env
was retyped from ARRAY to SET in this PR: GoogleCloudPlatform/magic-modules#11199The suggested workaround is to index by hash:
I would expect to be able to use this method for lifecycle ignores.
Actual Behavior
It is not possible to lifecycle ignore an item in a set, due to this Terraform issue: hashicorp/terraform#26359
Steps to reproduce
google_cloud_run_v2_job
with lifecycle ignored environment variableterraform plan
Important Factoids
No response
References
No response
b/384073894
The text was updated successfully, but these errors were encountered: