Skip to content

Commit b7e6236

Browse files
committed
Fix error when cloudfront-to-lambda doesn't exist
Fix problem wherein this module fails if the caller attempts to disable the subscription filter if the cloudfront-to-splunk lambda function doesn't exist. This was the result of a data source not having a count, causing the lambda function to be looked up even when it wasn't needed.
1 parent 5ffc3dc commit b7e6236

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

outputs.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ output "arn" {
33
}
44

55
output "lambda_function_arn" {
6-
value = data.aws_lambda_function.selected.qualified_arn
6+
value = var.disable_subscription_filter ? null : data.aws_lambda_function.selected[0].qualified_arn
77
}

subscription-filter.tf

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ data "aws_region" "current" {}
88

99
# Get lambda function name and ARN.
1010
data "aws_lambda_function" "selected" {
11+
count = var.disable_subscription_filter ? 0 : 1
1112
function_name = local.function_name
1213
}
1314

1415
resource "aws_lambda_permission" "default" {
1516
count = var.disable_subscription_filter ? 0 : 1
1617
action = "lambda:InvokeFunction"
17-
function_name = data.aws_lambda_function.selected.function_name
18+
function_name = data.aws_lambda_function.selected[0].function_name
1819
principal = local.principal
1920
source_arn = format("%s:*", aws_cloudwatch_log_group.default.arn)
2021
}
@@ -24,6 +25,6 @@ resource "aws_cloudwatch_log_subscription_filter" "default" {
2425
name = "filter"
2526
log_group_name = aws_cloudwatch_log_group.default.name
2627
filter_pattern = var.filter_pattern
27-
destination_arn = data.aws_lambda_function.selected.arn
28+
destination_arn = data.aws_lambda_function.selected[0].arn
2829
depends_on = [aws_lambda_permission.default]
2930
}

0 commit comments

Comments
 (0)