-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paths3.tf
67 lines (55 loc) · 1.64 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
resource "aws_s3_bucket" "client" {
bucket = replace("${local.product_information.context.product}_${local.product_information.context.service}", "_", "-")
force_destroy = true
tags = local.tags
}
resource "aws_s3_bucket_acl" "bucket_acl" {
bucket = aws_s3_bucket.client.id
acl = "private"
}
resource "aws_s3_bucket_website_configuration" "client_website" {
count = var.enable_bucket_website ? 1 : 0
bucket = aws_s3_bucket.client.bucket
index_document {
suffix = "index.html"
}
error_document {
key = "index.html"
}
}
resource "aws_s3_bucket_ownership_controls" "client_website_bucket_ownership" {
count = var.enable_bucket_website ? 1 : 0
bucket = aws_s3_bucket.client.bucket
rule {
object_ownership = "ObjectWriter"
}
}
resource "aws_s3_bucket_public_access_block" "client_website_bucket_public_access" {
count = var.enable_bucket_website ? 1 : 0
bucket = aws_s3_bucket.client.id
block_public_acls = false
block_public_policy = false
ignore_public_acls = false
restrict_public_buckets = false
}
resource "aws_s3_bucket_policy" "allow_client_website_access_from_internet" {
count = var.enable_bucket_website ? 1 : 0
bucket = aws_s3_bucket.client.id
policy = data.aws_iam_policy_document.allow_client_website_access_from_internet.json
}
data "aws_iam_policy_document" "allow_client_website_access_from_internet" {
statement {
sid = "PublicReadGetObject"
effect = "Allow"
actions = [
"s3:GetObject",
]
principals {
type = "*"
identifiers = ["*"]
}
resources = [
"${aws_s3_bucket.client.arn}/*",
]
}
}