Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

cloud build docker_repository configuration throws error about format but format is right

When I deploy a cloud function v2 using terraform trying to specify a docker_repository, I get this error

Error: Error creating function: googleapi: Error 400: Repository name `projects/org-service-accounts-401323/locations/us/repositories/gcr.io` has an invalid format. It should match the pattern `projects/{project}/locations/{location}/repositories/{repository}`.

But the format looks correct....

Using terraform 1.9.5 and google provider 5.42.0

Here are the configs I tried

build_config {
runtime = "nodejs18"
entry_point = "onRequest" # Set the entry point
# docker_repository = "us-east1-docker.pkg.dev/my-project/my-repo/my-image"
docker_repository = "projects/${var.common_project_id}/locations/us/repositories/${var.registry_name}"
# docker_repository = "${var.common_project_id}/us/${var.registry_name}"
 
source {
storage_source {
bucket = google_storage_bucket.default.name
object = google_storage_bucket_object.default.name
}
}
0 1 206
1 REPLY 1

Hi @suncoast-system,

Welcome to the Google Cloud Community!

Just a heads up, Container Registry is deprecated and scheduled for shutdown on March 18, 2025. This means that gcr.io repositories hosted on Container Registry will be unavailable unless they’re migrated to Artifact Registry.

An error status 400 generally indicates a Bad Request, which may come from improper formatting or invalid parameters. Here’s a few steps I suggest that may help resolve the issue:

If these steps didn’t work, you may create a bug on the Google Cloud issue tracker for Cloud Functions or Artifact Registry, or contact Google Cloud support.

Hope this helped!