hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.36k stars 1.75k forks source link

Missing URL for service of google_cloud_run_v2 #15119

Open tomerslice opened 1 year ago

tomerslice commented 1 year ago

Community Note

Description

Hey, on google_cloud_run_v2 I can't access its url. It's an internal http service that needs to answer other services http requests. I need to give them a url to give the requests to.

New or Affected Resource(s)

References

b/298050680

rileykarson commented 1 year ago

Note: Cloud Run may not be returning the service URL through its API in time, if that gets populated asynchronously.

roaks3 commented 1 year ago

I'm not sure this is quite in a workable state yet, so holding off on forwarding.

@tomerslice Could you please provide your Terraform config and the output you are receiving?

tomerslice commented 1 year ago

If this is not in workable state yet, I will wait with my question for a future time. I just wanted to pass it's url as env variable to another service.

TaylorMutch commented 1 year ago

I have this same issue.

I have to work around this by using a data reference like this:

resource "google_cloud_run_v2_service" "my-app" {
  name     = "my-app"
  location = "us-central1"
  project = local.project
  ...
}

# Build a data source to get the URL of the Cloud Run service.
# This seems like a bug on the cloud run v2 provider to not provide the URL of the service
data "google_cloud_run_service" "my-app" {
  location = "us-central1"
  project = local.project
  name = google_cloud_run_v2_service.my-app.name
}

output "app-url" {
  value = data.google_cloud_run_service.my-app.status[0].url
}

Would be nice if the v2 resource exposed a status URL!

roaks3 commented 1 year ago

It seems to me that the URIs you're looking for are output-only fields in the schema, but they may not be reconciled, as @rileykarson mentioned. See more info under the reconciling field description.

It looks like @TaylorMutch has a workaround, which may be working because it introduces a short delay. Ideally, it might be nice to have a way to instruct Terraform to wait for reconciliation.

TaylorMutch commented 1 year ago

After returning to this the next day I can do


output "app-url" {
  value = google_cloud_run_v2_service.my-app.uri
}

Which works, but its not desirable to have to wait for the output to succeed a terraform run. On initial deployment the output variable won't have the uri field populated so it just looks like an empty string, which isn't expected.