-
Notifications
You must be signed in to change notification settings - Fork 2
/
vpc-flow-logs.tf
62 lines (51 loc) · 1.8 KB
/
vpc-flow-logs.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
resource "aws_flow_log" "this" {
log_destination_type = "cloud-watch-logs"
log_destination = aws_cloudwatch_log_group.flow_log.arn
log_format = var.flow_log_log_format
iam_role_arn = aws_iam_role.vpc_flow_log_cloudwatch.arn
traffic_type = var.flow_log_traffic_type
vpc_id = aws_vpc.main.id
max_aggregation_interval = 600
}
resource "aws_cloudwatch_log_group" "flow_log" {
name = "/aws/vpc-flow-log/${aws_vpc.main.id}"
retention_in_days = var.flow_log_cloudwatch_log_group_retention_in_days
kms_key_id = var.flow_log_cloudwatch_log_group_kms_key_id
}
resource "aws_iam_role" "vpc_flow_log_cloudwatch" {
name_prefix = "vpc-flow-log-role-"
assume_role_policy = data.aws_iam_policy_document.flow_log_cloudwatch_assume_role.json
}
data "aws_iam_policy_document" "flow_log_cloudwatch_assume_role" {
statement {
principals {
type = "Service"
identifiers = ["vpc-flow-logs.amazonaws.com"]
}
effect = "Allow"
actions = ["sts:AssumeRole"]
}
}
resource "aws_iam_role_policy_attachment" "vpc_flow_log_cloudwatch" {
role = aws_iam_role.vpc_flow_log_cloudwatch.name
policy_arn = aws_iam_policy.vpc_flow_log_cloudwatch.arn
}
resource "aws_iam_policy" "vpc_flow_log_cloudwatch" {
name_prefix = "vpc-flow-log-to-cloudwatch-"
policy = data.aws_iam_policy_document.vpc_flow_log_cloudwatch.json
}
#tfsec:ignore:aws-iam-no-policy-wildcards
data "aws_iam_policy_document" "vpc_flow_log_cloudwatch" {
statement {
sid = "AWSVPCFlowLogsPushToCloudWatch"
effect = "Allow"
actions = [
"logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:DescribeLogGroups",
"logs:DescribeLogStreams",
]
resources = ["*"]
}
}