From 1f39c14986215561e6f5f291d05c2b620fc54c69 Mon Sep 17 00:00:00 2001 From: Arun Patel <ap2261@cam.ac.uk> Date: Thu, 1 Jul 2021 10:49:29 +0100 Subject: [PATCH] Change the behaviour to require image_name --- README.md | 3 +-- locals.tf | 7 ------- main.tf | 6 +----- variables.tf | 10 +++++----- 4 files changed, 7 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 35184a2..ce61e55 100644 --- a/README.md +++ b/README.md @@ -181,5 +181,4 @@ module "webapp" { Originally, the module did not deploy images except on the very first use (using `gcr.io/cloudrun/hello:latest`). -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. +Currently, the module deploys the image from the mandatory variable `image_name`. diff --git a/locals.tf b/locals.tf index 07c2f12..ce0b188 100644 --- a/locals.tf +++ b/locals.tf @@ -51,11 +51,4 @@ 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 : - "" - ) } diff --git a/main.tf b/main.tf index 99ff371..1a0923c 100644 --- a/main.tf +++ b/main.tf @@ -111,11 +111,7 @@ resource "google_cloud_run_service" "webapp" { service_account_name = google_service_account.webapp.email containers { - image = coalesce( - var.image_name, - local.existing_image_name, - "gcr.io/cloudrun/hello:latest", - ) + image = var.image_name resources { limits = { diff --git a/variables.tf b/variables.tf index 27b9a28..8940782 100644 --- a/variables.tf +++ b/variables.tf @@ -306,9 +306,9 @@ EOL variable "image_name" { type = string - default = "" - description = <<-EOL - Optional. The docker image that will be deployed. If unset, the value of - existing_image_name is preferred. -EOL + description = "The URL of the container image to be deployed." + validation { + condition = length(var.image_name) > 0 + error_message = "The image_name value must be a valid URL to a container image." + } } -- GitLab