Skip to content

Commit

Permalink
Do not allow to create logs by Lambda@Edge in all regions
Browse files Browse the repository at this point in the history
  • Loading branch information
Tomasz Rychlewicz committed May 16, 2023
1 parent 424ec17 commit bcff87b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion iam.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ locals {
# The region part of the LogGroup ARN is then replaced with a wildcard (*) so Lambda@Edge is able to log in every region
log_group_arn_regional = try(data.aws_cloudwatch_log_group.lambda[0].arn, aws_cloudwatch_log_group.lambda[0].arn, "")
log_group_name = try(data.aws_cloudwatch_log_group.lambda[0].name, aws_cloudwatch_log_group.lambda[0].name, "")
log_group_arn = local.create_role && var.lambda_at_edge ? format("arn:%s:%s:%s:%s:%s", data.aws_arn.log_group_arn[0].partition, data.aws_arn.log_group_arn[0].service, "*", data.aws_arn.log_group_arn[0].account, data.aws_arn.log_group_arn[0].resource) : local.log_group_arn_regional
log_group_arn = local.create_role && var.lambda_at_edge ? format("arn:%s:%s:%s:%s:%s", data.aws_arn.log_group_arn[0].partition, data.aws_arn.log_group_arn[0].service, var.lambda_at_edge_logs_all_regions ? "*" : "us-east-1", data.aws_arn.log_group_arn[0].account, data.aws_arn.log_group_arn[0].resource) : local.log_group_arn_regional

# Defaulting to "*" (an invalid character for an IAM Role name) will cause an error when
# attempting to plan if the role_name and function_name are not set. This is a workaround
Expand Down
6 changes: 6 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ variable "lambda_at_edge" {
default = false
}

variable "lambda_at_edge_logs_all_regions" {
description = "Whether to specify a wildcard in IAM policy used by Lambda@Edge to allow logging in all regions"
type = bool
default = true
}

variable "function_name" {
description = "A unique name for your Lambda Function"
type = string
Expand Down

0 comments on commit bcff87b

Please sign in to comment.