Skip to content

Support for cloud run function in cloud run v2 resource not building image before deploying #23057

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

Open
roycanani opened this issue May 28, 2025 · 3 comments
Assignees
Labels

Comments

@roycanani
Copy link

roycanani commented May 28, 2025

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 a user, that user is claiming responsibility for the issue.
  • Customers working with a Google Technical Account Manager or Customer Engineer can ask them to reach out internally to expedite investigation and resolution of this issue.

Terraform Version & Provider Version(s)

Terraform v2.7.1
on cloud build default

  • provider registry.terraform.io/hashicorp/google v6.37.0
  • provider registry.terraform.io/hashicorp/google-beta v6.37.0

Affected Resource(s)

google_cloud_run_v2_service

Terraform Configuration

resource "google_cloud_run_v2_service" "default" {
  name     = "test-functions"
  location = "europe-west1"
  deletion_protection = false
  ingress = "INGRESS_TRAFFIC_INTERNAL_ONLY"
  project = <PROJECT_ID>

  template {
    containers {
      image = "gcr.io/cloudrun/placeholder"
      base_image_uri = "europe-west1-docker.pkg.dev/serverless-runtimes/google-22-full/runtimes/python313"
    }

    vpc_access {
      network_interfaces {
        network = <VPC>
        subnetwork = <SUBNET>
      }
      egress = "PRIVATE_RANGES_ONLY"
    }
  }
  build_config {
    source_location = "gs://${google_storage_bucket.bucket.name}/${google_storage_bucket_object.bundle.name}"
    function_target = "hello_http"
    image_uri = <GOOGLE_ARTIFACT_REGISTRY>
    base_image = "europe-west1-docker.pkg.dev/serverless-runtimes/google-22-full/runtimes/python313"
    enable_automatic_updates = true
    worker_pool = <WORKER_POOL>
    environment_variables = {
      FOO_KEY = "FOO_VALUE"
      BAR_KEY = "BAR_VALUE" 
    }
    service_account = google_service_account.cloudbuild_service_account.id
  }
}

Debug Output

No response

Expected Behavior

When deploying a google_cloud_run_v2_service resource with a build configuration specified for a Cloud Run function, the service should build a container image from the provided source code and then deploy the function using this newly built image.

Actual Behavior

The google_cloud_run_v2_service resource, when deployed with a build configuration, does not build an image from the source code. Instead, it deploys the function with a default container image.

Steps to reproduce

  1. Copy current configuration
  2. Run terraform apply
  3. Observe that the deployed Cloud Run service uses a default image rather than one built from the specified source.

Important Factoids

  • This behavior is unexpected because the google_cloudfunctions2_function resource correctly builds an image from source code by default before deploying.
  • The google_cloud_run_v2_service resource is being used specifically for its advanced networking capabilities (e.g., egress control, network interfaces without connectors) that are not available in the google_cloudfunctions2_function resource.
  • The issue seems to be a bug in how the google_cloud_run_v2_service handles build configurations.

References

Terraform Google Provider - google_cloud_run_v2_service documentation: https://registry.terraform.io/providers/hashicorp/google/6.37.0/docs/resources/cloud_run_v2_service#example-usage---cloudrunv2-service-function

Terraform Google Provider - cloudfunctions2_functiondocumentation: https://registry.terraform.io/providers/hashicorp/google/latest/docs/resources/cloudfunctions2_function#example-usage---cloudfunctions2-private-workerpool

@roycanani roycanani added the bug label May 28, 2025
@github-actions github-actions bot added forward/review In review; remove label to forward service/run labels May 28, 2025
@ggtisc ggtisc self-assigned this May 28, 2025
@ggtisc
Copy link
Collaborator

ggtisc commented May 28, 2025

Hi @roycanani

Is this a public image, or do you have an example we can use to replicate this issue?

@roycanani
Copy link
Author

Hey, the base image is public.
The issue is that I don’t want to use the image defined in the resource—I’d like to use the image that should build by the cloud run function. Currently to deploy the desired image I need to go the source code in the console and save and redeploy.

The expected behavior is the same as what happens in the cloudfunctions resource.

@ggtisc
Copy link
Collaborator

ggtisc commented May 30, 2025

Here you are using 2 different images:

Template Containers Image:
image = "gcr.io/cloudrun/placeholder"

build_config image:
image_uri = <GOOGLE_ARTIFACT_REGISTRY>

Which one are you looking to use, because it depends on the code specifications. The suggested is to use in both fields the same image as you can see in terraform registry examples (link here)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants