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

Cloud Run update image after creation using Terraform

I am trying to create Cloud Run with ESPV2. This requires me to

1. Reserve a cloud run address by deploying a dummy cloud run instance.
2. Use the address and API spec file to build an endpoints container image
3. Update the service created at step 1 with the Hello image with newly created at step 2.

Link for Google Documentation is here https://cloud.google.com/endpoints/docs/openapi/set-up-cloud-functions-espv2

Can you suggest a way to implement this using Terraform ??
I don’t mind during this in two steps (having two terraform configurations). But I am not sure how to update an existing instance without creating it in the same terraform config. (the second one tries to recreate it).

Any help is highly appreciated.

5 1 1,388
1 REPLY 1

Hi @DeepakShevre,

Welcome to Google Cloud Community!

Updating Cloud Run Image with ESPv2 after Creation

While Terraform can't directly update an existing Cloud Run service's image, here are alternative approaches:

  1. Separate Terraform Configurations:
  1. Cloud Build Triggers:
  • Store your image in a container registry.
  • Configure a Cloud Build trigger to:
    • Build and deploy on new image push.
    • Access Cloud Run service address from Secret Manager.
    • Build Endpoints image with retrieved address and API spec.
    • Deploy the new image as a revision. (https://cloud.google.com/build/docs/overview)
  1. Cloud Deployment Manager (IaC):

Consideration:

Terraform recreates resources on configuration changes, leading to downtime. These approaches offer a more controlled update process.

Top Labels in this Space
Top Solution Authors