forked from nozaq/terraform-aws-secure-baseline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbucket.tf
66 lines (60 loc) · 1.68 KB
/
bucket.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
resource "aws_s3_bucket" "logs" {
bucket = var.audit_s3_bucket_name
force_destroy = true
}
resource "aws_s3_bucket_acl" "logs" {
bucket = aws_s3_bucket.logs.id
acl = "private"
}
data "aws_iam_policy_document" "logs_bucket_policy" {
statement {
sid = "AWSCloudTrailAclCheckForConfig"
actions = ["s3:GetBucketAcl"]
principals {
type = "Service"
identifiers = ["config.amazonaws.com"]
}
resources = [aws_s3_bucket.logs.arn]
}
statement {
sid = "AWSCloudTrailWriteForConfig"
actions = ["s3:PutObject"]
principals {
type = "Service"
identifiers = ["config.amazonaws.com"]
}
resources = ["${aws_s3_bucket.logs.arn}/config/AWSLogs/${data.aws_caller_identity.current.account_id}/Config/*"]
condition {
test = "StringEquals"
variable = "s3:x-amz-acl"
values = ["bucket-owner-full-control"]
}
}
statement {
sid = "AWSCloudTrailAclCheckForCloudTrail"
actions = ["s3:GetBucketAcl"]
principals {
type = "Service"
identifiers = ["cloudtrail.amazonaws.com"]
}
resources = [aws_s3_bucket.logs.arn]
}
statement {
sid = "AWSCloudTrailWriteForCloudTrail"
actions = ["s3:PutObject"]
principals {
type = "Service"
identifiers = ["cloudtrail.amazonaws.com"]
}
resources = ["${aws_s3_bucket.logs.arn}/cloudtrail/AWSLogs/*"]
condition {
test = "StringEquals"
variable = "s3:x-amz-acl"
values = ["bucket-owner-full-control"]
}
}
}
resource "aws_s3_bucket_policy" "logs" {
bucket = aws_s3_bucket.logs.id
policy = data.aws_iam_policy_document.logs_bucket_policy.json
}