-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.tf
52 lines (41 loc) · 1.24 KB
/
main.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
resource "aws_cloudwatch_log_group" "vpc_flow_logs" {
name = "${var.name_prefix}-vpc-flow-logs-cw"
retention_in_days = var.retention_in_days != "" ? var.retention_in_days : null
kms_key_id = var.kms_key_id
tags = var.tags
}
resource "aws_iam_role" "vpc_flow_logs" {
name = "${var.name_prefix}-vpc-flow-logs-role"
assume_role_policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"Service": "vpc-flow-logs.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
EOF
tags = var.tags
}
resource "aws_flow_log" "vpc_flow_logs" {
log_destination_type = "cloud-watch-logs"
log_destination = aws_cloudwatch_log_group.vpc_flow_logs.arn
iam_role_arn = aws_iam_role.vpc_flow_logs.arn
vpc_id = var.vpc_id
traffic_type = var.traffic_type
max_aggregation_interval = var.max_aggregation_interval
tags = var.tags
}
resource "aws_iam_policy" "vpc_flow_logs" {
name = "${var.name_prefix}-flow-logs-policy"
policy = templatefile("${path.module}/policies/vpc_flow_logs_policy.json", {})
}
resource "aws_iam_role_policy_attachment" "vpc_flow_logs" {
policy_arn = aws_iam_policy.vpc_flow_logs.arn
role = aws_iam_role.vpc_flow_logs.name
}