forked from willfarrell/terraform-vpc-module
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlogs.tf
50 lines (44 loc) · 1.25 KB
/
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
# Logs
resource "aws_flow_log" "logs" {
log_destination_type = "cloud-watch-logs"
log_destination = aws_cloudwatch_log_group.logs.arn
iam_role_arn = aws_iam_role.logs.arn
vpc_id = aws_vpc.main.id
traffic_type = "ALL"
}
resource "aws_cloudwatch_log_group" "logs" {
name = "/aws/vpc/${aws_vpc.main.id}"
retention_in_days = var.retention_in_days
kms_key_id = var.kms_key_arn
}
resource "aws_iam_role" "logs" {
name = "${local.name}-vpc-logs-role"
assume_role_policy = data.aws_iam_policy_document.role-logs.json
}
data "aws_iam_policy_document" "role-logs" {
statement {
effect = "Allow"
principals {
identifiers = ["vpc-flow-logs.amazonaws.com"]
type = "Service"
}
actions = ["sts:AssumeRole"]
}
}
resource "aws_iam_role_policy" "logs" {
name = "${local.name}-vpc-logs-policy"
role = aws_iam_role.logs.id
policy = data.aws_iam_policy_document.logs.json
}
data "aws_iam_policy_document" "logs" {
statement {
sid = "CloudWatchLogs"
effect = "Allow"
actions = ["logs:CreateLogGroup",
"logs:CreateLogStream",
"logs:PutLogEvents",
"logs:DescribeLogGroups",
"logs:DescribeLogStreams"]
resources = ["${aws_cloudwatch_log_group.logs.arn}"]
}
}