From ba771e6e05c76620b85ff82ee30b2189fefe6107 Mon Sep 17 00:00:00 2001 From: Kevin Gunn Date: Tue, 14 Mar 2023 11:27:43 -0400 Subject: [PATCH 1/3] AMI Id does not need to be sensitive --- main.tf | 4 ++-- outputs.tf | 5 +++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index a13e6e00..346710d3 100644 --- a/main.tf +++ b/main.tf @@ -19,7 +19,7 @@ data "aws_ssm_parameter" "this" { resource "aws_instance" "this" { count = local.create && !var.create_spot_instance ? 1 : 0 - ami = try(coalesce(var.ami, data.aws_ssm_parameter.this[0].value), null) + ami = nonsensitive(try(coalesce(var.ami, data.aws_ssm_parameter.this[0].value), null)) instance_type = var.instance_type cpu_core_count = var.cpu_core_count cpu_threads_per_core = var.cpu_threads_per_core @@ -167,7 +167,7 @@ resource "aws_instance" "this" { resource "aws_spot_instance_request" "this" { count = local.create && var.create_spot_instance ? 1 : 0 - ami = try(coalesce(var.ami, data.aws_ssm_parameter.this[0].value), null) + ami = nonsensitive(try(coalesce(var.ami, data.aws_ssm_parameter.this[0].value), null)) instance_type = var.instance_type cpu_core_count = var.cpu_core_count cpu_threads_per_core = var.cpu_threads_per_core diff --git a/outputs.tf b/outputs.tf index 45f42545..1fc2b80a 100644 --- a/outputs.tf +++ b/outputs.tf @@ -78,6 +78,11 @@ output "spot_instance_id" { value = try(aws_spot_instance_request.this[0].spot_instance_id, "") } +output "ami" { + description = "AMI ID that was used to create the instance." + value = try(aws_instance.this[0].ami, aws_spot_instance_request.this[0].ami, "") +} + ################################################################################ # IAM Role / Instance Profile ################################################################################ From 765ba4cf20a122704071effb8d68a31a0eab98b2 Mon Sep 17 00:00:00 2001 From: Kevin Gunn Date: Tue, 14 Mar 2023 11:47:18 -0400 Subject: [PATCH 2/3] Need to only mark aws_ssm_parameter as nonsensitive - otherwise we'll generate an error for redundancy --- main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/main.tf b/main.tf index 346710d3..8d7695d8 100644 --- a/main.tf +++ b/main.tf @@ -19,7 +19,7 @@ data "aws_ssm_parameter" "this" { resource "aws_instance" "this" { count = local.create && !var.create_spot_instance ? 1 : 0 - ami = nonsensitive(try(coalesce(var.ami, data.aws_ssm_parameter.this[0].value), null)) + ami = try(coalesce(var.ami, nonsensitive(data.aws_ssm_parameter.this[0].value)), null) instance_type = var.instance_type cpu_core_count = var.cpu_core_count cpu_threads_per_core = var.cpu_threads_per_core @@ -167,7 +167,7 @@ resource "aws_instance" "this" { resource "aws_spot_instance_request" "this" { count = local.create && var.create_spot_instance ? 1 : 0 - ami = nonsensitive(try(coalesce(var.ami, data.aws_ssm_parameter.this[0].value), null)) + ami = try(coalesce(var.ami, nonsensitive(data.aws_ssm_parameter.this[0].value)), null) instance_type = var.instance_type cpu_core_count = var.cpu_core_count cpu_threads_per_core = var.cpu_threads_per_core From eca04efbce733ffb0e9a239f1c30b7d1815b37d0 Mon Sep 17 00:00:00 2001 From: Kevin Gunn Date: Tue, 14 Mar 2023 11:54:31 -0400 Subject: [PATCH 3/3] Ran pre-commit - updated README --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index cdd8766f..9cc79d8d 100644 --- a/README.md +++ b/README.md @@ -265,6 +265,7 @@ No modules. | Name | Description | |------|-------------| +| [ami](#output\_ami) | AMI ID that was used to create the instance. | | [arn](#output\_arn) | The ARN of the instance | | [capacity\_reservation\_specification](#output\_capacity\_reservation\_specification) | Capacity reservation specification of the instance | | [iam\_instance\_profile\_arn](#output\_iam\_instance\_profile\_arn) | ARN assigned by AWS to the instance profile |