From b29e45836511d8cd48ad74a58a2d4c30d8d47fb7 Mon Sep 17 00:00:00 2001 From: David Costa Date: Tue, 3 Dec 2024 16:50:26 +0000 Subject: [PATCH] fix: optional google_compute_image --- main.tf | 3 ++- outputs.tf | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index 815b347..a8e137a 100644 --- a/main.tf +++ b/main.tf @@ -22,6 +22,7 @@ resource "random_string" "random" { } data "google_compute_image" "cos" { + count = var.machine_image == null ? 1 : 0 family = "cos-stable" project = "cos-cloud" } @@ -159,7 +160,7 @@ resource "google_compute_instance_template" "default" { # Ephemeral OS boot disk disk { - source_image = var.machine_image != null ? var.machine_image : data.google_compute_image.cos.self_link + source_image = var.machine_image != null ? var.machine_image : data.google_compute_image.cos[0].self_link auto_delete = true boot = true disk_type = "pd-ssd" diff --git a/outputs.tf b/outputs.tf index 1cc1eec..9047d5c 100644 --- a/outputs.tf +++ b/outputs.tf @@ -4,7 +4,7 @@ output "ip_address" { } output "cos_image_id" { - value = data.google_compute_image.cos.image_id + value = var.machine_image == null ? data.google_compute_image.cos[0].image_id : element(split("/", var.machine_image), length(split("/", var.machine_image)) - 1) description = "The unique identifier of the Container-Optimized OS image used to create the Compute Engine instance." }