-
Notifications
You must be signed in to change notification settings - Fork 7
/
main.tf
57 lines (47 loc) · 1.48 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
// Global Content Delivery Network
// S3 + Cloudfront
// Content of this bucket will be populated manually
data "aws_iam_policy_document" "s3_policy" {
statement {
actions = ["s3:GetObject"]
resources = ["arn:aws:s3:::${var.site_name}${replace(var.domain, ".", "-")}/*"]
principals {
type = "AWS"
identifiers = ["${aws_cloudfront_origin_access_identity.origin_access_identity.iam_arn}"]
}
}
statement {
actions = ["s3:ListBucket"]
resources = ["arn:aws:s3:::${var.site_name}${replace(var.domain, ".", "-")}"]
principals {
type = "AWS"
identifiers = ["${aws_cloudfront_origin_access_identity.origin_access_identity.iam_arn}"]
}
}
}
resource "aws_s3_bucket" "main" {
bucket = "${var.site_name}${replace(var.domain, ".", "-")}"
acl = "public-read"
policy = "${data.aws_iam_policy_document.s3_policy.json}"
website {
index_document = "index.html"
error_document = "404.html"
}
}
# Add record on DNS for minion instance
resource "aws_route53_record" "site" {
zone_id = "${var.public_dns_zone}"
name = "${var.site_name}${var.domain}"
type = "A"
alias {
name = "${aws_cloudfront_distribution.s3_distribution.domain_name}"
zone_id = "${aws_cloudfront_distribution.s3_distribution.hosted_zone_id}"
evaluate_target_health = true
}
}
output "bucket" {
value = "${aws_s3_bucket.main.id}"
}
output "bucket_arn" {
value = "${aws_s3_bucket.main.arn}"
}