terraform-provider-google: Cloud Run: cannot reconcile service edited through console
Community Note
- Please vote on this issue by adding a š reaction to the original issue to help the community and maintainers prioritize this request.
- Please do not leave +1 or me too comments, they generate extra noise for issue followers and do not help prioritize the request.
- If you are interested in working on this issue or have submitted a pull request, please leave a comment.
- If an issue is assigned to the
modular-magicianuser, 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 -v
Terraform v1.2.3
on darwin_arm64
+ provider registry.terraform.io/chainguard-dev/ko v0.0.4
+ provider registry.terraform.io/hashicorp/google v4.47.0
+ provider registry.terraform.io/hashicorp/google-beta v4.47.0
...
Affected Resource(s)
- google_cloud_run_service
Terraform Configuration Files
This should affect virtually any Cloud Run service deployed through terraform.
Debug Output
N/A
Panic Output
N/A
Expected Behavior
terraform reconciles the service
Actual Behavior
After ~20 minutes it times out and prints an error with a 409 because the named revision already exists.
Steps to Reproduce
- Deploy a service via terraform,
- Edit it via the Consoleās editor (not yaml),
- Deploy the service again via terraform.
Important Factoids
The Knative resource model used by Cloud Run supports ābring your own revision nameā where you can use spec.template.metadata.name to name the revision that the Service will create. This is used by the Cloud Run console when edits are made.
If changes are made to the service without removing or updating this name, then things will fail to deploy.
cc @steren
References
b/272367711
About this issue
- Original URL
- State: open
- Created a year ago
- Reactions: 32
- Comments: 39 (1 by maintainers)
Commits related to this issue
- Set revision autogeneration to avoid stuck jobs https://github.com/hashicorp/terraform-provider-google/issues/13410#issuecomment-1487410241 — committed to TresAmigosLtd/pair_dance by jacek-rzrz a year ago
Hey folks! Good news: As of today, the requisite features to resolve the core issue here have been rolled out everywhere.
Prerequisites:
Specific workflow:
google_cloud_run_v2_serviceterraform provider (do not set a revision name), and apply.gcloud run deployor the Cloud Console UIThere should no longer appear any conflict with revision name.
Itās frustrating that v2 was introduced without considering this real-world scenario. We are still fighting this issue and it causes a lot of confusion / errors but at the same time we are forced to use v2 for new features⦠Any timeline on the gcloud fix?!
Hey folks, just wanted to update the thread on what weāre doing on the Cloud Run team to address this issue. As @steren mentioned above, this is an issue with our two major clients (
gcloudCLI and the GCP Console UI) setting a āprettifiedā revision name in the spec.After evaluating, weāre going to change our clients to leave the revision name empty by default. Weāre also updating the behavior of the control plane to use the āprettyā name scheme if a revision name is not specified.
TL;DR - Weāre updating our clients and control plane, that will address the root cause of this problem. Weāll keep this thread posted when thereās an update.
This problem also happens if you provision a cloud run service using terraform
google_cloud_run_v2_serviceand then deploy revisions in CI/CD. Either Terraform will always detect and apply āchangesā because the revision has changed or if you add the revision to lifecycle ignore_changes then you get the errorRevision named ... with different configuration already exists.Hi @justinmahood, I canāt speak for @FabianFrank but it seems like Iām experiencing the same issue as him using
google_cloud_run_v2_service.My resource definition does not include a
revisionfield, even for the initial creation. myignore_changesis set to ignoretemplate[0].containers[0].imagebecause that is the field I want to update outside of the context of terraform (viagcloud run deploy <service> --image <image>)There are two issues Iām running into, neither of which result in the behavior I would ideally want:
with the revision field left out, and also not included in ignore_changes:
gcloud run deploysuccessfully deploys a new revisionso, it seems like the solution to that would be to add this revision field to ignore_changes, and this does solve the problem of creating unnecessary revisions, however if I have to actually make a change to the TF definition after my
gcloud run deploy(for example changingmax_instance_countfrom10to20) that is when I see this other error:even though the
planaction seems to make the correct plan.so⦠the repro steps for my case would be:
revisionshould not be present, andtemplate[0].containers[0].imageas well astemplate[0].revisionshould be in the lifecycle ignore_changes blockgcloud run deploy <service> --image <myimage>1 to change, apply results in above mentioned409When i do a
terraform state show google_cloud_run_v2_service.myservice, i can see that there is a revision in there:and my guess is that a subsequent apply is trying to create another revision with that same name, which explains the 409, but what i want is for it to let google auto-generate a new revision name. is something like that possible?
Hello, any update ? š Same trouble for me. Deploy CR V2 with Terraform and updating image with gcloud, and not able to apply new conf with terraform after that š¦
++
As I described above, the root cause comes from the 2018-ish design choice of having gcloud and Cloud Console name revisions by default because automatic names werenāt so nice. We should change that. Cloud Run API should just generate good names automatically and clients should not implicitly name revisions if they donāt want to.
autogenerate_revision_name = trueingoogle_cloud_run_servicewas probably added to address this problem or to mimic the behavior of other clients. But it is a logic built into the Terraform resource, it basically āpatchesā the root cause.Others on the team could chime in, but I donāt think we want this feature added to
google_cloud_run_v2_service, the idea withgoogle_cloud_run_v2_serviceis that is exactly maps to the Cloud Run Admin API v2 resources. This enables the Cloud Run team to guarantee that any Cloud Run feature added to the Admin API v2 automatically appears ingoogle_cloud_run_v2_service. Therefore, we want to avoid any hand-crafting f the behavior. I am not even sure if the infrastructure used allows it.Itās great that
autogenerate_revision_name = trueexists ingoogle_cloud_run_service, but as I said, we want to fix that at the root, in the Cloud Run API and CLI/UI clientsYes, please see my comment
Any update on a fix for this that doesnāt involve deploying a new revision on every TF apply?
I had this same issue - I deployed a cloudrun service via Terraform (terraform cloud) and then subsequently deployed new revisions with updated image tags via this GitHub actions workflow.
I was getting the same error:
I was able to circumvent this error with 2 code changes. The first - adding the
random_uuidterraform generator, and providing a unique revision name to the terraform resource.Secondly, ignoring the following lifecycle changes:
Not ideal, but a fairly simple workaround that allowed me manage the service from two angles. I hope this helps!
has this been progressed at all? the issue has been open for ~5 months now, Iāve had to upgrade to the v2 resource for other features and now completely stuck on this.
@trriplejay explained it perfectly, that is what I am experiencing!
While I agree this should be fixed, I am also wondering if the same issue occurs in the v2 resources.
I recommend switching to v2 as a workaround.