-
Notifications
You must be signed in to change notification settings - Fork 4
/
aws_cloudtrail.account.tf
68 lines (62 loc) · 1.88 KB
/
aws_cloudtrail.account.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
63
64
65
66
67
68
resource "aws_cloudtrail" "account" {
name = var.trail["name"]
cloud_watch_logs_role_arn = aws_iam_role.cloudtrail.arn
depends_on = [aws_s3_bucket.trails]
enable_log_file_validation = true
enable_logging = var.enable_logging
include_global_service_events = var.trail["include_global_service_events"]
is_multi_region_trail = var.is_multi_region_trail
is_organization_trail = var.is_organization_trail
kms_key_id = aws_kms_key.cloudtrail.arn
s3_bucket_name = aws_s3_bucket.trails.id
s3_key_prefix = var.trail["s3_key_prefix"]
sns_topic_name = aws_sns_topic.cloudtrail.name
cloud_watch_logs_group_arn = "${aws_cloudwatch_log_group.trails.arn}:*"
}
resource "aws_iam_role" "cloudtrail" {
assume_role_policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "",
"Effect": "Allow",
"Principal": {
"Service": "cloudtrail.amazonaws.com"
},
"Action": "sts:AssumeRole"
}
]
}
POLICY
}
resource "aws_iam_role_policy" "cloudtrail" {
role = aws_iam_role.cloudtrail.name
policy = <<POLICY
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "AWSCloudTrailCreateLogStream2014110",
"Effect": "Allow",
"Action": [
"logs:CreateLogStream"
],
"Resource": [
"arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:log-group:${var.log_group_name}:log-stream:*"
]
},
{
"Sid": "AWSCloudTrailPutLogEvents20141101",
"Effect": "Allow",
"Action": [
"logs:PutLogEvents"
],
"Resource": [
"arn:aws:logs:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:log-group:${var.log_group_name}:log-stream:*"
]
}
]
}
POLICY
}