-
Notifications
You must be signed in to change notification settings - Fork 39
/
s3.tf
113 lines (88 loc) · 2.63 KB
/
s3.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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
resource "aws_s3_bucket" "www" {
bucket = "${var.prefix}-${var.munki_s3_bucket}"
}
resource "aws_s3_bucket_public_access_block" "www_access_block" {
bucket = aws_s3_bucket.www.id
block_public_acls = false
block_public_policy = false
ignore_public_acls = false
restrict_public_buckets = false
}
resource "aws_s3_bucket_logging" "www_logging" {
bucket = aws_s3_bucket.www.id
target_bucket = aws_s3_bucket.log_bucket.id
target_prefix = "logs/"
}
resource "aws_s3_bucket_public_access_block" "log_bucket_access_block" {
bucket = aws_s3_bucket.log_bucket.id
block_public_acls = false
block_public_policy = false
ignore_public_acls = false
restrict_public_buckets = false
}
resource "aws_s3_bucket_server_side_encryption_configuration" "bucket_sse_config" {
bucket = aws_s3_bucket.www.id
rule {
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
resource "aws_s3_bucket_ownership_controls" "www_ownership_controls" {
bucket = aws_s3_bucket.www.id
rule {
object_ownership = "ObjectWriter"
}
}
resource "aws_s3_bucket_ownership_controls" "log_bucket_ownership_controls" {
bucket = aws_s3_bucket.log_bucket.id
rule {
object_ownership = "ObjectWriter"
}
}
resource "aws_s3_bucket_acl" "private_acl" {
depends_on = [aws_s3_bucket_ownership_controls.www_ownership_controls]
bucket = aws_s3_bucket.www.id
acl = "private"
}
data "aws_iam_policy_document" "s3_policy" {
statement {
actions = ["s3:GetObject"]
resources = ["${aws_s3_bucket.www.arn}/*"]
principals {
type = "AWS"
identifiers = [aws_cloudfront_origin_access_identity.origin_access_identity.iam_arn]
}
}
statement {
actions = ["s3:ListBucket"]
resources = [aws_s3_bucket.www.arn]
principals {
type = "AWS"
identifiers = [aws_cloudfront_origin_access_identity.origin_access_identity.iam_arn]
}
}
}
resource "aws_s3_bucket_policy" "www" {
bucket = aws_s3_bucket.www.id
policy = data.aws_iam_policy_document.s3_policy.json
}
resource "aws_s3_bucket" "log_bucket" {
bucket = "${var.prefix}-${var.munki_s3_bucket}-logs"
}
resource "aws_s3_bucket_acl" "log_bucket_acl" {
depends_on = [aws_s3_bucket_ownership_controls.log_bucket_ownership_controls]
bucket = aws_s3_bucket.log_bucket.id
acl = "log-delivery-write"
}
resource aws_s3_bucket_lifecycle_configuration "log_bucket_lifecycle" {
bucket = aws_s3_bucket.log_bucket.id
rule {
id = "log_bucket_lifecycle"
status = "Enabled"
transition {
days = "30"
storage_class = "STANDARD_IA"
}
}
}