File tree 8 files changed +147
-0
lines changed
8 files changed +147
-0
lines changed Original file line number Diff line number Diff line change
1
+ .terraform /
2
+ terraform.tfstate
3
+ * .tfstate.backup
4
+ aws-auth.ini
Original file line number Diff line number Diff line change
1
+ Licensed under the Apache License, Version 2.0 (the "License");
2
+ you may not use this file except in compliance with the License.
3
+ You may obtain a copy of the License at
4
+
5
+ http://www.apache.org/licenses/LICENSE-2.0
6
+
7
+ Unless required by applicable law or agreed to in writing, software
8
+ distributed under the License is distributed on an "AS IS" BASIS,
9
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10
+ See the License for the specific language governing permissions and
11
+ limitations under the License.
Original file line number Diff line number Diff line change
1
+ # Terraform Gatsby AWS
2
+
Original file line number Diff line number Diff line change
1
+ resource "aws_cloudfront_distribution" "cloudfront" {
2
+ origin {
3
+ domain_name = aws_s3_bucket. bucket . website_endpoint
4
+ origin_id = " s3_website"
5
+
6
+ custom_origin_config {
7
+ http_port = 80
8
+ https_port = 443
9
+ origin_keepalive_timeout = 15
10
+ origin_protocol_policy = " http-only"
11
+ origin_read_timeout = 30
12
+ origin_ssl_protocols = [" TLSv1.1" , " TLSv1.2" ]
13
+ }
14
+ }
15
+
16
+ enabled = true
17
+ is_ipv6_enabled = true
18
+ http_version = " http2"
19
+ default_root_object = " index.html"
20
+
21
+ aliases = [
22
+ var . domain_name
23
+ ]
24
+
25
+ default_cache_behavior {
26
+ allowed_methods = [" GET" , " HEAD" , " OPTIONS" ]
27
+ cached_methods = [" GET" , " HEAD" ]
28
+ target_origin_id = " s3_website"
29
+
30
+ forwarded_values {
31
+ query_string = false
32
+
33
+ headers = [
34
+ " Origin"
35
+ ]
36
+
37
+ cookies {
38
+ forward = " none"
39
+ }
40
+ }
41
+
42
+ viewer_protocol_policy = " redirect-to-https"
43
+ compress = true
44
+ smooth_streaming = false
45
+ }
46
+
47
+ restrictions {
48
+ geo_restriction {
49
+ restriction_type = " none"
50
+ }
51
+ }
52
+
53
+ price_class = " PriceClass_All"
54
+
55
+ viewer_certificate {
56
+ acm_certificate_arn = var. https_certificate_arn
57
+ minimum_protocol_version = " TLSv1.1_2016"
58
+ ssl_support_method = " sni-only"
59
+ }
60
+ }
61
+
Original file line number Diff line number Diff line change
1
+ resource "aws_route53_record" "dns" {
2
+ zone_id = var. route53_zone_id
3
+ name = var. domain_name
4
+ type = " A"
5
+
6
+ alias {
7
+ evaluate_target_health = false
8
+ name = aws_cloudfront_distribution. cloudfront . domain_name
9
+ zone_id = aws_cloudfront_distribution. cloudfront . hosted_zone_id
10
+ }
11
+
12
+ lifecycle {
13
+ create_before_destroy = true
14
+ }
15
+ }
16
+
Original file line number Diff line number Diff line change
1
+ resource "aws_s3_bucket" "bucket" {
2
+ bucket = var. domain_name
3
+ acl = " public-read"
4
+ policy = << EOF
5
+ {
6
+ "Id": "bucket_policy_site",
7
+ "Version": "2012-10-17",
8
+ "Statement": [
9
+ {
10
+ "Sid": "bucket_policy_site_main",
11
+ "Action": [
12
+ "s3:GetObject"
13
+ ],
14
+ "Effect": "Allow",
15
+ "Resource": "arn:aws:s3:::${ var . domain_name } /*",
16
+ "Principal": "*"
17
+ }
18
+ ]
19
+ }
20
+ EOF
21
+
22
+ website {
23
+ index_document = " index.html"
24
+ error_document = " 404.html"
25
+ }
26
+
27
+ force_destroy = true
28
+ }
29
+
30
+ resource "aws_s3_bucket_public_access_block" "bucket_public_access" {
31
+ bucket = aws_s3_bucket. bucket . id
32
+
33
+ block_public_acls = false
34
+ block_public_policy = false
35
+ ignore_public_acls = false
36
+ restrict_public_buckets = false
37
+ }
38
+
39
+
Original file line number Diff line number Diff line change
1
+ variable "route53_zone_id" {
2
+ description = " Route53 Zone id to create the DNS record for the Gatsby app"
3
+ }
4
+
5
+ variable "domain_name" {
6
+ description = " The domain to run the Gatsby app on"
7
+ }
8
+
9
+ variable "https_certificate_arn" {
10
+ description = " A full ARN path to the ACM SSL certificate in us-east-1"
11
+ }
Original file line number Diff line number Diff line change
1
+ terraform {
2
+ required_version = " ~> 0.12.20"
3
+ }
You can’t perform that action at this time.
0 commit comments