This repository has been archived by the owner on Oct 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathcloudtrail.tf
57 lines (53 loc) · 1.63 KB
/
cloudtrail.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
# #########################################
# Cloudtrail
# #########################################
resource "aws_cloudtrail" "cloudtrail" {
count = local.enable_cloudtrail_count
enable_log_file_validation = true
include_global_service_events = true
is_multi_region_trail = true
name = format("%s-cloudtrail", module.labels.id)
s3_bucket_name = aws_s3_bucket.cloudtrail[0].id
tags = module.labels.tags
}
resource "aws_s3_bucket" "cloudtrail" {
count = local.enable_cloudtrail_count
bucket = local.cloudtrail_s3_bucket_name
policy = <<EOF
{
"Version": "2012-10-17",
"Statement": [
{
"Action": "s3:GetBucketAcl",
"Effect": "Allow",
"Principal": { "Service": "cloudtrail.amazonaws.com" },
"Resource": "arn:aws:s3:::${local.cloudtrail_s3_bucket_name}",
"Sid": "AWSCloudTrailAclCheck"
},
{
"Action": "s3:PutObject",
"Condition": {
"StringEquals": {
"s3:x-amz-acl": "bucket-owner-full-control"
}
},
"Effect": "Allow",
"Principal": { "Service": "cloudtrail.amazonaws.com" },
"Resource": "arn:aws:s3:::${local.cloudtrail_s3_bucket_name}/*",
"Sid": "AWSCloudTrailWrite"
}
]
}
EOF
versioning {
enabled = true
}
}
resource "aws_s3_bucket_public_access_block" "default" {
count = local.enable_cloudtrail_count
bucket = aws_s3_bucket.cloudtrail[0].id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}