Search code examples
google-cloud-platformterraformgoogle-cloud-runterraform-provider-gcp

Deploy new container revision to Cloud Run without changing Terraform


I am setting up a CI&CD environment for a GCP project involves Cloud Run. While setting up everything via Terraform is pretty much straightforward, I cannot figure out how to update the environment when the code changes.

The documentation says:

  1. Make a change to the configuration file.

But that couples the application deployment to terraform configuration, which should be responsible only for infrastructure deployment.

Ideally, I use terraform to provision the infrastructure, and another CI step to build and deploy the container.

Is there a best-practice here?

Relevant sources: 1.


Solution

  • I ended up separating Cloud Run service creation (which is still done in Terraform) and deployment to two different workflows.

    The key component was to make terraform ignore the actual deployed image so that when the code deployment workflow is done, terraform won't complained that the Cloud Run image is different from the one it manages. I achieved this by setting ignore_changes = [template[0].spec[0].containers[0].image] on the google_cloud_run_service resource.