-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy paths3.tf
85 lines (69 loc) · 1.81 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
resource "aws_s3_bucket" "buckets" {
for_each = { for idx, name in var.bucket_names : idx => name }
bucket = each.value
}
resource "aws_s3_bucket_cors_configuration" "buckets" {
for_each = aws_s3_bucket.buckets
bucket = each.value.id
cors_rule {
allowed_headers = ["*"]
allowed_methods = ["GET", "HEAD"]
allowed_origins = ["*"]
expose_headers = ["ETag"]
max_age_seconds = 3000
}
}
resource "aws_s3_bucket_acl" "buckets" {
for_each = aws_s3_bucket.buckets
bucket = each.value.id
acl = "public-read"
depends_on = [aws_s3_bucket_ownership_controls.s3_bucket_acl_ownership]
}
resource "aws_s3_bucket_ownership_controls" "s3_bucket_acl_ownership" {
for_each = aws_s3_bucket.buckets
bucket = each.value.id
rule {
object_ownership = "BucketOwnerPreferred"
}
depends_on = [aws_s3_bucket_public_access_block.a_block]
}
resource "aws_s3_bucket_public_access_block" "a_block" {
for_each = aws_s3_bucket.buckets
bucket = each.value.id
block_public_acls = false
block_public_policy = false
ignore_public_acls = false
restrict_public_buckets = false
}
resource "aws_s3_bucket_policy" "prod" {
for_each = aws_s3_bucket.buckets
bucket = each.value.id
policy = jsonencode({
Version = "2012-10-17"
Statement = [
{
Sid = "PublicListBucket"
Effect = "Allow"
Principal = "*"
Action = [
"s3:ListBucket"
]
Resource = [
"${each.value.arn}",
]
},
{
Sid = "PublicGetObject"
Effect = "Allow"
Principal = "*"
Action = [
"s3:GetObject"
]
Resource = [
"${each.value.arn}/*",
]
},
]
})
depends_on = [aws_s3_bucket_public_access_block.a_block]
}