-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackend-s3.tf
44 lines (36 loc) · 966 Bytes
/
backend-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
resource "aws_s3_bucket" "uploads" {
bucket_prefix = "parkingspace-uploads-"
}
resource "aws_s3_bucket_cors_configuration" "uploads" {
bucket = aws_s3_bucket.uploads.id
cors_rule {
allowed_headers = ["*"]
allowed_methods = ["POST"]
allowed_origins = [aws_route53_record.cloudfront.name]
expose_headers = ["ETag"]
max_age_seconds = 3000
}
}
resource "aws_s3_bucket_website_configuration" "uploads" {
bucket = aws_s3_bucket.uploads.id
error_document {
key = "index.html"
}
index_document {
suffix = "index.html"
}
}
data "aws_iam_policy_document" "uploads" {
statement {
actions = ["s3:GetObject"]
resources = ["${aws_s3_bucket.uploads.arn}/*"]
principals {
type = "AWS"
identifiers = [aws_cloudfront_origin_access_identity.cfoai.iam_arn]
}
}
}
resource "aws_s3_bucket_policy" "uploads" {
bucket = aws_s3_bucket.uploads.id
policy = data.aws_iam_policy_document.uploads.json
}