Skip to content

Commit

Permalink
fix: optional google_compute_image
Browse files Browse the repository at this point in the history
  • Loading branch information
d-costa committed Dec 3, 2024
1 parent c260331 commit b29e458
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 2 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
Expand Down Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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."
}

Expand Down

0 comments on commit b29e458

Please sign in to comment.