FAQ | This is a LIVE service | Changelog

Skip to content
Snippets Groups Projects
Commit 245f7ad6 authored by Arun Patel's avatar Arun Patel Committed by Wajdi Hajji
Browse files

Add explicit image name and reads current deployed image

This works with Terraform v0.14.10; the data source is read before
the plan walk, so the existing deployed image can be determined.
However, it is suggested that future Terraform may combine the
refresh and plan walks which *may* result in a cyclic dependancy.
parent 4f6113a1
No related branches found
No related tags found
1 merge request!32Resolve "Adding LB config for load-balanced Cloud Run services"
......@@ -181,18 +181,5 @@ module "webapp" {
Originally, the module did not deploy images except on the very first use (using
`gcr.io/cloudrun/hello:latest`).
Currently, deploy the image from `image_name` if specified, otherwise keep the
Currently, the module deploys the image from `image_name` if specified, otherwise keep the
current image, if that doesn't exist fall-back to the "hello" image.
The name of the currently deployed image needs to be sourced outside of
this module and supplied as `existing_image_name` to prevent a cyclic dependency
problem. This can be extracted from an existing deployment and included in the
root module with:
```tf
existing_image_name = (
data.google_cloud_run_service.webapp.template != null ?
data.google_cloud_run_service.webapp.template[0].spec[0].containers[0].image :
""
)
```
......@@ -51,4 +51,11 @@ locals {
[trimsuffix(trimprefix(google_cloud_run_service.webapp.status[0].url, "https://"), "/")],
var.allow_unauthenticated_invocations ? local.dns_names : [],
)
# If a cloud run revision is present, get the full URL of the deployed image.
existing_image_name = (
data.google_cloud_run_service.webapp.template != null ?
data.google_cloud_run_service.webapp.template[0].spec[0].containers[0].image :
""
)
}
......@@ -113,7 +113,7 @@ resource "google_cloud_run_service" "webapp" {
containers {
image = coalesce(
var.image_name,
var.existing_image_name,
local.existing_image_name,
"gcr.io/cloudrun/hello:latest",
)
......
......@@ -308,16 +308,7 @@ variable "image_name" {
type = string
default = ""
description = <<-EOL
The docker image that will be deployed. If unset, the value of existing_image_name
is preferred.
EOL
}
variable "existing_image_name" {
type = string
default = ""
description = <<-EOL
The image currently deployed, which needs to be passed into this module to
avoid a cyclic dependency. If unset, the hello container will be deployed.
Optional. The docker image that will be deployed. If unset, the value of
existing_image_name is preferred.
EOL
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment