-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy paths3_website.tf
66 lines (57 loc) · 1.37 KB
/
s3_website.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
# AWS S3 bucket for website static hosting
resource "aws_s3_bucket" "this" {
count = var.r53_failover_enabled ? 1 : 0
bucket = var.fqdn
tags = {
Terraform = "true"
Name = "${var.env}-${var.name}"
}
}
resource "aws_s3_bucket_policy" "this" {
bucket = aws_s3_bucket.this[0].id
policy = <<EOF
{
"Version": "2008-10-17",
"Statement": [
{
"Sid": "PublicReadForS3BucketObjects",
"Effect": "Allow",
"Principal": {
"AWS": "*"
},
"Action": "s3:GetObject",
"Resource": "arn:aws:s3:::${var.fqdn}/*"
}
]
}
EOF
}
resource "aws_s3_bucket_acl" "this" {
bucket = aws_s3_bucket.this[0].id
acl = "public-read"
}
resource "aws_s3_bucket_website_configuration" "this" {
count = var.r53_failover_enabled ? 1 : 0
bucket = aws_s3_bucket.this[0].id
index_document {
suffix = "index.html"
}
error_document {
key = "index.html"
}
}
resource "aws_route53_record" "this" {
count = var.r53_failover_enabled ? 1 : 0
zone_id = data.aws_route53_zone.this.zone_id
name = var.fqdn
type = "A"
alias {
name = aws_s3_bucket_website_configuration.this[0].website_domain
zone_id = aws_s3_bucket.this[0].hosted_zone_id
evaluate_target_health = false
}
failover_routing_policy {
type = "SECONDARY"
}
set_identifier = "${var.fqdn}-SECONDARY"
}