Skip to content

Commit

Permalink
bug: Refactor role_arn variable to list of strings to cope with 'Inva…
Browse files Browse the repository at this point in the history
…lid count' error

Signed-off-by: Stefan Wessels Beljaars <[email protected]>
  • Loading branch information
stefanwb committed Jun 11, 2024
1 parent a13af2c commit 25a3d06
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
5 changes: 3 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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]))
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}

Expand Down

0 comments on commit 25a3d06

Please sign in to comment.