terraform-aws-modules/terraform-aws-lambda

Creating a lambda with lambda_role_arn instead of role_name is failing

himanshu-agarwl opened this issue · 2 comments

Description

Hi Team,

The change merged today 7df6bbf seems to break lambda creation when the IAM role is not getting created via module. We do pass

lambda_role   = data.aws_iam_role.service.arn
create_role   = false

and getting error

╷
│ Error: Error in function call
│ 
│   on .terraform/modules/braze_webhook_lambda/iam.tf line 15, in locals:
│   15:   policy_name = coalesce(var.policy_name, local.role_name)
│     ├────────────────
│     │ local.role_name is null
│     │ var.policy_name is null
│ 
│ Call to function "coalesce" failed: no non-null, non-empty-string
│ arguments.

This is because we don't expect module to create the role and thus don't pass role_name or policy_name and both of them are null which coalesce is complaining about.

Versions

  • Module version [Required]:

  • Terraform version:
    Terraform v1.2.8
    on darwin_amd64

  • Provider version(s):

  • provider registry.terraform.io/hashicorp/aws v4.37.0
  • provider registry.terraform.io/hashicorp/external v2.2.2
  • provider registry.terraform.io/hashicorp/local v2.2.3
  • provider registry.terraform.io/hashicorp/null v3.2.0

Reproduction Code [Required]

module "braze_consumer_lambda" {
  source = "terraform-aws-modules/lambda/aws"

  function_name = <name of function>
  description   = "Sends events to braze"
  handler       = "main.lambda_handler"
  runtime       = "python3.8"
  lambda_role   = <role-arn>
  create_role   = false

  timeout                = 30
  create_package         = false
  local_existing_package = <path>

  tags = {
    Name = local.braze_consumer_lambda_name
  }
}

Steps to reproduce the behavior:

yes yes running terraform apply with latest module and reproducible code should reproduce the issue.

Expected behavior

Expected to set policy_name to null when create_role is false.

Actual behavior

Applying the module errors out with

╷
│ Error: Error in function call
│ 
│   on .terraform/modules/braze_webhook_lambda/iam.tf line 15, in locals:
│   15:   policy_name = coalesce(var.policy_name, local.role_name)
│     ├────────────────
│     │ local.role_name is null
│     │ var.policy_name is null
│ 
│ Call to function "coalesce" failed: no non-null, non-empty-string
│ arguments.

Terminal Output Screenshot(s)

Additional context

This issue has been resolved in version 4.4.1 🎉

I'm going to lock this issue because it has been closed for 30 days . This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.