@@ -405,13 +405,18 @@ module "alb" {
405405 target_type = " lambda"
406406 lambda_multi_value_headers_enabled = true
407407 targets = {
408- # Lambda function permission should be granted before
409- # it is used. There can be an error:
410- # NB: Error registering targets with target group:
411- # AccessDenied: elasticloadbalancing principal does not
412- # have permission to invoke ... from target group ...
413- my_lambda = {
414- target_id = module.lambda_function.lambda_function_arn
408+ lambda_with_allowed_triggers = {
409+ target_id = module.lambda_with_allowed_triggers.lambda_function_arn
410+ }
411+ }
412+ },
413+ {
414+ name_prefix = " l2-"
415+ target_type = " lambda"
416+ targets = {
417+ lambda_without_allowed_triggers = {
418+ target_id = module.lambda_without_allowed_triggers.lambda_function_arn
419+ attach_lambda_permission = true
415420 }
416421 }
417422 },
@@ -500,12 +505,12 @@ resource "null_resource" "download_package" {
500505 }
501506}
502507
503- module "lambda_function " {
508+ module "lambda_with_allowed_triggers " {
504509 source = " terraform-aws-modules/lambda/aws"
505510 version = " ~> 3.0"
506511
507- function_name = " ${ random_pet . this . id } -lambda "
508- description = " My awesome lambda function"
512+ function_name = " ${ random_pet . this . id } -with-allowed-triggers "
513+ description = " My awesome lambda function (with allowed triggers) "
509514 handler = " index.lambda_handler"
510515 runtime = " python3.8"
511516
@@ -523,3 +528,23 @@ module "lambda_function" {
523528
524529 depends_on = [null_resource. download_package ]
525530}
531+
532+ module "lambda_without_allowed_triggers" {
533+ source = " terraform-aws-modules/lambda/aws"
534+ version = " ~> 3.0"
535+
536+ function_name = " ${ random_pet . this . id } -without-allowed-triggers"
537+ description = " My awesome lambda function (without allowed triggers)"
538+ handler = " index.lambda_handler"
539+ runtime = " python3.8"
540+
541+ publish = true
542+
543+ create_package = false
544+ local_existing_package = local. downloaded
545+
546+ # Allowed triggers will be managed by ALB module
547+ allowed_triggers = {}
548+
549+ depends_on = [null_resource. download_package ]
550+ }
0 commit comments