From 25a3d06ea0b3e9752798125b1193cb04e31c11ce Mon Sep 17 00:00:00 2001 From: Stefan Wessels Beljaars Date: Mon, 10 Jun 2024 19:23:31 +0200 Subject: [PATCH] bug: Refactor role_arn variable to list of strings to cope with 'Invalid count' error Signed-off-by: Stefan Wessels Beljaars --- main.tf | 5 +++-- outputs.tf | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/main.tf b/main.tf index 35bf24e..243f95b 100644 --- a/main.tf +++ b/main.tf @@ -8,10 +8,11 @@ locals { source_code_hash = var.source_code_hash != null ? var.source_code_hash : var.filename != null ? filebase64sha256(var.filename) : null tracing_config = var.tracing_config_mode != null ? { create : true } : {} vpc_config = var.subnet_ids != null ? { create : true } : {} + role_arn = [var.role_arn] } module "lambda_role" { - count = var.role_arn == null ? 1 : 0 + count = length(local.role_arn) == 0 ? 1 : 0 source = "github.com/schubergphilis/terraform-aws-mcaf-role?ref=v0.3.3" name = join("-", compact([var.role_prefix, "LambdaRole", var.name])) @@ -140,7 +141,7 @@ resource "aws_lambda_function" "default" { memory_size = var.memory_size publish = var.publish reserved_concurrent_executions = var.reserved_concurrency - role = var.role_arn != null ? var.role_arn : module.lambda_role[0].arn + role = length(local.role_arn) > 0 ? local.role_arn[0] : module.lambda_role[0].arn runtime = var.runtime s3_bucket = var.s3_bucket s3_key = var.s3_key diff --git a/outputs.tf b/outputs.tf index ca018b3..6a4ad1f 100644 --- a/outputs.tf +++ b/outputs.tf @@ -19,7 +19,7 @@ output "qualified_arn" { } output "role_arn" { - value = var.role_arn != null ? var.role_arn : module.lambda_role[0].arn + value = length(local.role_arn) > 0 ? local.role_arn[0] : module.lambda_role[0].arn description = "ARN of the lambda execution role" }