-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy paths3_bucket.tf
54 lines (46 loc) · 1.19 KB
/
s3_bucket.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
resource "aws_s3_bucket" "static" {
bucket = var.s3_bucket
}
resource "aws_s3_bucket_server_side_encryption_configuration" "static" {
bucket = aws_s3_bucket.static.bucket
rule {
bucket_key_enabled = true
apply_server_side_encryption_by_default {
sse_algorithm = "AES256"
}
}
}
resource "aws_s3_bucket_website_configuration" "static" {
bucket = aws_s3_bucket.static.bucket
index_document {
suffix = "index.html"
}
}
resource "aws_s3_bucket_policy" "static" {
bucket = aws_s3_bucket.static.id
policy = <<POLICY
{
"Version": "2012-10-17",
"Id": "Cloudfront only access policy",
"Statement": [
{
"Sid": "Allow get requests from CF referer",
"Effect": "Allow",
"Principal": "*",
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::${var.s3_bucket}/*",
"Condition": {
"StringEquals": {
"aws:Referer": "cloudfront-${var.s3_origin_id}"
}
}
}
]
}
POLICY
}
resource "aws_s3_bucket_public_access_block" "static" {
bucket = aws_s3_bucket.static.id
block_public_acls = true
ignore_public_acls = true
}