-
Notifications
You must be signed in to change notification settings - Fork 0
/
preview.tf
154 lines (127 loc) · 3.43 KB
/
preview.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
terraform {
backend "s3" {
bucket = "gatech-me-robojackets-bpm-preview-statefiles"
region = "us-east-1"
}
required_providers {
aws = {
source = "hashicorp/aws"
version = "5.78.0"
}
}
}
provider "aws" {
}
variable "ref" {
type = string
description = "The git ref being deployed"
}
locals {
s3_origin_id = "bpm-preview"
}
resource "aws_s3_bucket" "bucket" {
bucket = "gatech-me-robojackets-bpm-preview-${replace(var.ref, "/", "-")}"
force_destroy = true
}
resource "aws_s3_bucket_public_access_block" "block_public_access" {
bucket = aws_s3_bucket.bucket.id
block_public_acls = true
block_public_policy = true
ignore_public_acls = true
restrict_public_buckets = true
}
data "aws_iam_policy_document" "s3_policy" {
statement {
actions = ["s3:GetObject"]
resources = ["${aws_s3_bucket.bucket.arn}/*"]
principals {
type = "Service"
identifiers = [
"cloudfront.amazonaws.com",
]
}
condition {
test = "StringEquals"
values = [
aws_cloudfront_distribution.cloudfront.arn
]
variable = "AWS:SourceArn"
}
}
statement {
actions = ["s3:ListBucket"]
resources = [aws_s3_bucket.bucket.arn]
principals {
type = "Service"
identifiers = [
"cloudfront.amazonaws.com",
]
}
condition {
test = "StringEquals"
values = [
aws_cloudfront_distribution.cloudfront.arn
]
variable = "AWS:SourceArn"
}
}
}
resource "aws_s3_bucket_policy" "bucket_policy" {
bucket = aws_s3_bucket.bucket.id
policy = data.aws_iam_policy_document.s3_policy.json
}
resource "aws_cloudfront_origin_access_control" "allow_cloudfront_access_to_s3" {
name = "bpm-preview-${replace(var.ref, "/", "-")}"
origin_access_control_origin_type = "s3"
signing_behavior = "always"
signing_protocol = "sigv4"
}
resource "aws_cloudfront_distribution" "cloudfront" {
origin {
domain_name = aws_s3_bucket.bucket.bucket_regional_domain_name
origin_id = local.s3_origin_id
origin_access_control_id = aws_cloudfront_origin_access_control.allow_cloudfront_access_to_s3.id
}
default_cache_behavior {
allowed_methods = ["HEAD", "GET", "OPTIONS"]
cached_methods = ["HEAD", "GET"]
compress = true
viewer_protocol_policy = "https-only"
target_origin_id = local.s3_origin_id
forwarded_values {
query_string = false
cookies {
forward = "none"
}
}
function_association {
event_type = "viewer-request"
function_arn = "arn:aws:cloudfront::771971951923:function/dirhtml-uri-support"
}
}
default_root_object = "index.html"
enabled = true
is_ipv6_enabled = true
price_class = "PriceClass_100"
http_version = "http3"
wait_for_deployment = false
restrictions {
geo_restriction {
restriction_type = "none"
}
}
viewer_certificate {
cloudfront_default_certificate = true
minimum_protocol_version = "TLSv1"
ssl_support_method = "sni-only"
}
}
output "s3_bucket_name" {
value = aws_s3_bucket.bucket.id
}
output "cloudfront_distribution_id" {
value = aws_cloudfront_distribution.cloudfront.id
}
output "cloudfront_domain" {
value = aws_cloudfront_distribution.cloudfront.domain_name
}