-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paths3-logs.tf
89 lines (72 loc) · 2.16 KB
/
s3-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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# TODO: Raise tfsec issue - unable to conditionally set 'log-delivery-write' acl resource to ignore access logging
#tfsec:ignore:aws-s3-enable-bucket-logging
resource "aws_s3_bucket" "logs" {
count = local.create_logs_bucket ? 1 : 0
bucket = "${local.project_name}-logs"
force_destroy = local.s3_logs_force_destroy
}
resource "aws_s3_bucket_versioning" "logs" {
count = local.create_logs_bucket ? 1 : 0
bucket = aws_s3_bucket.logs[0].id
versioning_configuration {
status = "Enabled"
}
}
resource "aws_s3_bucket_ownership_controls" "logs" {
count = local.create_logs_bucket ? 1 : 0
bucket = aws_s3_bucket.logs[0].id
rule {
object_ownership = "BucketOwnerPreferred"
}
}
resource "aws_s3_bucket_acl" "logs" {
count = local.enable_s3_access_logs ? 1 : 0
bucket = aws_s3_bucket.logs[0].id
acl = "log-delivery-write"
}
resource "aws_s3_bucket_acl" "cloudfront_logs" {
count = local.enable_cloudfront_static_site_logs ? 1 : 0
bucket = aws_s3_bucket.logs[0].id
access_control_policy {
grant {
grantee {
id = data.aws_canonical_user_id.current.id
type = "CanonicalUser"
}
permission = "FULL_CONTROL"
}
grant {
grantee {
id = "c4c1ede66af53448b93c283ce9448c4ba468c9432aa01d700d3878632f77d2d0"
type = "CanonicalUser"
}
permission = "FULL_CONTROL"
}
owner {
id = data.aws_canonical_user_id.current.id
}
}
}
resource "aws_s3_bucket_public_access_block" "logs" {
count = local.create_logs_bucket ? 1 : 0
bucket = aws_s3_bucket.logs[0].id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
#tfsec:ignore:aws-s3-encryption-customer-key
resource "aws_s3_bucket_server_side_encryption_configuration" "logs" {
count = local.create_logs_bucket ? 1 : 0
bucket = aws_s3_bucket.logs[0].bucket
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
resource "aws_s3_bucket_policy" "logs" {
count = local.create_logs_bucket ? 1 : 0
bucket = aws_s3_bucket.logs[0].id
policy = local.logs_bucket_policy
}