DEV Community

Thierry Njike for Zenika

Posted on • Updated on

Fix Cloud run resource locations constraint error (Error 412)

Image description

You have a project that you would like to deploy on Google Cloud using Cloud run, but due to some organisation's restrictions, you get an error like below:

ERROR: (gcloud.run.deploy) HTTPError 412: '$region' violates constraint 'constraints/gcpresourceLocations'

This error could come from the fact that you should use a low carbon region, and not all Google Cloud regions satisfy this condition.
Even if you pass the region as an argument, you have some steps of the deployment process that you don't manage because they are automated. So, you have to do it another way.
In this article, I will explain step by step how to solve that problem.

**

1 - Create the repository yourself

**

If we use the default gcloud run command, It will create a repository in the artifact registry, and use it to create the image to deploy.
That image is by default multiregion and it includes prohibited regions. So, you have to build the image yourself manually and specify it as an argument in the command. To do so, you have to create a repository in the Artifact Registry as shown below:

Image description

When creating the repository, make sure to select a low carbon region. Once the repository is created, open it and copy its path.

Image description

**

2 - Let's build the image

**

At this step, you should have created a repository. Now, let's build the image. Paste the command below in your cloud shell at the same level with your Dockerfile:

gcloud builds submit --region=$region --gcs-source-staging-dir=$path_to_the_cloud_storage_bucket --tag $path_to_the_repo/image_name:version

Enter fullscreen mode Exit fullscreen mode

Image description

The image was successfully built! Copy the image URL, you will need it at the next step.

**

3 - Deploy your image

**
Now your image is created, let's deploy it on Cloud Run. Paste the command below in your cloud shell

gcloud run deploy $service_name --image $image_url:tag
Enter fullscreen mode Exit fullscreen mode

Now you should have your app link in your cloud shell!

Hope this article will help 🚀

Top comments (0)