Skip to content

Commit 580c5a8

Browse files
committed
refactor(logs): move cloudwatch resources in dedicated file
Move all Cloudwatch-related resources into a dedicated iam.tf file to improve code organization and maintainability. No functional changes, purely organizational improvement.
1 parent 9ba7b73 commit 580c5a8

File tree

2 files changed

+25
-37
lines changed

2 files changed

+25
-37
lines changed

cloudwatch.tf

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
resource "aws_cloudwatch_event_rule" "this" {
2+
name = "trigger-lambda-scheduler-${var.name}"
3+
description = "Trigger lambda scheduler"
4+
schedule_expression = var.cloudwatch_schedule_expression
5+
tags = var.tags
6+
}
7+
8+
resource "aws_cloudwatch_event_target" "this" {
9+
arn = aws_lambda_function.this.arn
10+
rule = aws_cloudwatch_event_rule.this.name
11+
}
12+
13+
resource "aws_lambda_permission" "this" {
14+
statement_id = "AllowExecutionFromCloudWatch"
15+
action = "lambda:InvokeFunction"
16+
principal = "events.amazonaws.com"
17+
function_name = aws_lambda_function.this.function_name
18+
source_arn = aws_cloudwatch_event_rule.this.arn
19+
}
20+
21+
resource "aws_cloudwatch_log_group" "this" {
22+
name = "/aws/lambda/${var.name}"
23+
retention_in_days = 14
24+
tags = var.tags
25+
}

main.tf

-37
Original file line numberDiff line numberDiff line change
@@ -37,40 +37,3 @@ resource "aws_lambda_function" "this" {
3737

3838
tags = var.tags
3939
}
40-
41-
################################################
42-
#
43-
# CLOUDWATCH EVENT
44-
#
45-
################################################
46-
47-
resource "aws_cloudwatch_event_rule" "this" {
48-
name = "trigger-lambda-scheduler-${var.name}"
49-
description = "Trigger lambda scheduler"
50-
schedule_expression = var.cloudwatch_schedule_expression
51-
tags = var.tags
52-
}
53-
54-
resource "aws_cloudwatch_event_target" "this" {
55-
arn = aws_lambda_function.this.arn
56-
rule = aws_cloudwatch_event_rule.this.name
57-
}
58-
59-
resource "aws_lambda_permission" "this" {
60-
statement_id = "AllowExecutionFromCloudWatch"
61-
action = "lambda:InvokeFunction"
62-
principal = "events.amazonaws.com"
63-
function_name = aws_lambda_function.this.function_name
64-
source_arn = aws_cloudwatch_event_rule.this.arn
65-
}
66-
67-
################################################
68-
#
69-
# CLOUDWATCH LOG
70-
#
71-
################################################
72-
resource "aws_cloudwatch_log_group" "this" {
73-
name = "/aws/lambda/${var.name}"
74-
retention_in_days = 14
75-
tags = var.tags
76-
}

0 commit comments

Comments
 (0)