From bc633636a6d9cb7a62ee2358ca8eea682d5bbd12 Mon Sep 17 00:00:00 2001 From: Ayrton Vieyra Date: Wed, 16 Aug 2023 13:05:53 -0700 Subject: [PATCH] Update main.tf - fix coalesce ami and ami_ssm_parameter function from always failing when ami var defined --- main.tf | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/main.tf b/main.tf index 1034fd22..2ef7d265 100644 --- a/main.tf +++ b/main.tf @@ -19,7 +19,7 @@ data "aws_ssm_parameter" "this" { resource "aws_instance" "this" { count = local.create && !var.ignore_ami_changes && !var.create_spot_instance ? 1 : 0 - ami = try(coalesce(var.ami, nonsensitive(data.aws_ssm_parameter.this[0].value)), null) + ami = try(coalesce(try(var.ami, null), try(nonsensitive(data.aws_ssm_parameter.this[0].value), null), null)) instance_type = var.instance_type cpu_core_count = var.cpu_core_count cpu_threads_per_core = var.cpu_threads_per_core @@ -187,7 +187,7 @@ resource "aws_instance" "this" { resource "aws_instance" "ignore_ami" { count = local.create && var.ignore_ami_changes && !var.create_spot_instance ? 1 : 0 - ami = try(coalesce(var.ami, nonsensitive(data.aws_ssm_parameter.this[0].value)), null) + ami = try(coalesce(try(var.ami, null), try(nonsensitive(data.aws_ssm_parameter.this[0].value), null), null)) instance_type = var.instance_type cpu_core_count = var.cpu_core_count cpu_threads_per_core = var.cpu_threads_per_core @@ -361,7 +361,7 @@ resource "aws_instance" "ignore_ami" { resource "aws_spot_instance_request" "this" { count = local.create && var.create_spot_instance ? 1 : 0 - ami = try(coalesce(var.ami, nonsensitive(data.aws_ssm_parameter.this[0].value)), null) + ami = try(coalesce(try(var.ami, null), try(nonsensitive(data.aws_ssm_parameter.this[0].value), null), null)) instance_type = var.instance_type cpu_core_count = var.cpu_core_count cpu_threads_per_core = var.cpu_threads_per_core