-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
73 lines (62 loc) · 1.67 KB
/
main.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
resource "aws_s3_bucket" "bucket" {
bucket = var.bucket
}
resource "aws_s3_bucket_website_configuration" "bucket_website_config" {
bucket = aws_s3_bucket.bucket.id
index_document {
suffix = var.index_document["suffix"]
}
error_document {
key = var.error_document["key"]
}
}
resource "aws_s3_bucket_server_side_encryption_configuration" "bucket_ss_encryption_config" {
bucket = aws_s3_bucket.bucket.id
rule {
bucket_key_enabled = var.rule["bucket_key_enabled"]
apply_server_side_encryption_by_default {
sse_algorithm = var.rule.apply_server_side_encryption_by_default["sse_algorithm"]
}
}
}
resource "aws_s3_bucket_ownership_controls" "controls" {
bucket = aws_s3_bucket.bucket.id
rule {
object_ownership = "BucketOwnerPreferred"
}
}
resource "aws_s3_bucket_public_access_block" "public_access" {
bucket = aws_s3_bucket.bucket.id
block_public_acls = false
block_public_policy = false
ignore_public_acls = false
restrict_public_buckets = false
}
resource "aws_s3_bucket_acl" "acl" {
depends_on = [
aws_s3_bucket_ownership_controls.controls,
aws_s3_bucket_public_access_block.public_access,
]
bucket = aws_s3_bucket.bucket.id
acl = "public-read"
}
resource "aws_s3_bucket_policy" "bucket_policy" {
bucket = aws_s3_bucket.bucket.bucket
policy = jsonencode({
Version = "2012-10-17"
Id = "bucket_policy"
Statement = [
{
Sid = "PublicReadGetObject"
Effect = "Allow"
Principal = "*"
Action = [
"s3:GetObject"
]
Resource = [
"${aws_s3_bucket.bucket.arn}/*",
]
},
]
})
}