Skip to content

Commit

Permalink
keep flow with lambda msg
Browse files Browse the repository at this point in the history
  • Loading branch information
renato-dnx committed Aug 21, 2024
1 parent 73931b4 commit 34da9be
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions aws-event_bridge.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,6 @@ resource "aws_cloudwatch_event_rule" "alarm_notification" {
resource "aws_cloudwatch_event_target" "lambda_target" {
count = length(var.endpoints) > 0 ? 1 : 0
rule = aws_cloudwatch_event_rule.alarm_notification[0].name
target_id = "cloudtrail_alarm_notifications"
arn = var.alarm_protocol == "email" ? aws_lambda_function.lambda[0].arn : aws_sns_topic.alarms[0].arn
target_id = "lambda_notification"
arn = aws_lambda_function.lambda[0].arn
}
8 changes: 4 additions & 4 deletions aws-iam.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
data "aws_iam_policy_document" "lambda_assume_role" {
count = var.alarm_protocol == "email" && length(var.endpoints) > 0 ? 1 : 0
count = length(var.endpoints) > 0 ? 1 : 0
statement {
actions = ["sts:AssumeRole"]
principals {
Expand All @@ -10,14 +10,14 @@ data "aws_iam_policy_document" "lambda_assume_role" {
}

resource "aws_iam_role" "iam_for_lambda" {
count = var.alarm_protocol == "email" && length(var.endpoints) > 0 ? 1 : 0
count = length(var.endpoints) > 0 ? 1 : 0
name = "cloudtrail-cn-role-${data.aws_region.current.name}"
assume_role_policy = data.aws_iam_policy_document.lambda_assume_role[0].json
tags = var.tags
}

resource "aws_iam_policy" "lambda_cw" {

Check failure on line 19 in aws-iam.tf

View workflow job for this annotation

GitHub Actions / scan

CKV_AWS_290: "Ensure IAM policies does not allow write access without constraints"

Check failure on line 19 in aws-iam.tf

View workflow job for this annotation

GitHub Actions / scan

CKV_AWS_355: "Ensure no IAM policies documents allow "*" as a statement's resource for restrictable actions"
count = var.alarm_protocol == "email" && length(var.endpoints) > 0 ? 1 : 0
count = length(var.endpoints) > 0 ? 1 : 0
name = "cloudtrail-cn-policy-${data.aws_region.current.name}"
path = "/"
description = "IAM policy for logging from a lambda"
Expand Down Expand Up @@ -53,7 +53,7 @@ resource "aws_iam_policy" "lambda_cw" {
}

resource "aws_iam_role_policy_attachment" "lambda_cw" {
count = var.alarm_protocol == "email" && length(var.endpoints) > 0 ? 1 : 0
count = length(var.endpoints) > 0 ? 1 : 0
role = aws_iam_role.iam_for_lambda[0].name
policy_arn = aws_iam_policy.lambda_cw[0].arn
}
6 changes: 3 additions & 3 deletions aws-lambda.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
resource "aws_lambda_function" "lambda" {

Check failure on line 1 in aws-lambda.tf

View workflow job for this annotation

GitHub Actions / scan

CKV_AWS_117: "Ensure that AWS Lambda function is configured inside a VPC"

Check failure on line 1 in aws-lambda.tf

View workflow job for this annotation

GitHub Actions / scan

CKV_AWS_173: "Check encryption settings for Lambda environmental variable"

Check failure on line 1 in aws-lambda.tf

View workflow job for this annotation

GitHub Actions / scan

CKV_AWS_272: "Ensure AWS Lambda function is configured to validate code-signing"

Check failure on line 1 in aws-lambda.tf

View workflow job for this annotation

GitHub Actions / scan

CKV_AWS_115: "Ensure that AWS Lambda function is configured for function-level concurrent execution limit"

Check failure on line 1 in aws-lambda.tf

View workflow job for this annotation

GitHub Actions / scan

CKV_AWS_116: "Ensure that AWS Lambda function is configured for a Dead Letter Queue(DLQ)"
count = var.alarm_protocol == "email" && length(var.endpoints) > 0 ? 1 : 0
count = length(var.endpoints) > 0 ? 1 : 0
filename = "${path.module}/lambda.zip"
function_name = var.lambda_name
role = aws_iam_role.iam_for_lambda[0].arn
Expand All @@ -21,7 +21,7 @@ resource "aws_lambda_function" "lambda" {
}

resource "aws_lambda_permission" "default" {
count = var.alarm_protocol == "email" && length(var.endpoints) > 0 ? 1 : 0
count = length(var.endpoints) > 0 ? 1 : 0
statement_id = "AllowExecutionFromEventBridge"
action = "lambda:InvokeFunction"
function_name = aws_lambda_function.lambda[0].function_name
Expand All @@ -30,7 +30,7 @@ resource "aws_lambda_permission" "default" {
}

resource "aws_cloudwatch_log_group" "alarm_lambda" {

Check failure on line 32 in aws-lambda.tf

View workflow job for this annotation

GitHub Actions / scan

CKV_AWS_158: "Ensure that CloudWatch Log Group is encrypted by KMS"
count = var.alarm_protocol == "email" && length(var.endpoints) > 0 ? 1 : 0
count = length(var.endpoints) > 0 ? 1 : 0
name = "/aws/lambda/${var.lambda_name}"
retention_in_days = 365
kms_key_id = var.kms_key
Expand Down

0 comments on commit 34da9be

Please sign in to comment.