-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcommon.tf
More file actions
155 lines (120 loc) · 3.13 KB
/
common.tf
File metadata and controls
155 lines (120 loc) · 3.13 KB
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
155
data "aws_caller_identity" "current" {}
data "aws_cloudfront_cache_policy" "caching_optimized" {
name = "Managed-CachingOptimized"
}
data "aws_cloudfront_origin_request_policy" "s3_origin" {
name = "Managed-CORS-S3Origin"
}
resource "aws_cloudfront_origin_access_control" "images" {
name = aws_s3_bucket.images.bucket_regional_domain_name
description = "Managed by Terraform"
origin_access_control_origin_type = "s3"
signing_behavior = "always"
signing_protocol = "sigv4"
}
resource "aws_route53_zone" "phlask" {
name = "phlask.me"
}
resource "aws_s3_bucket" "images" {
bucket = "phlask-tap-images"
}
resource "aws_s3_bucket_acl" "images" {
bucket = aws_s3_bucket.images.id
acl = "private"
}
resource "aws_s3_bucket_policy" "images" {
bucket = aws_s3_bucket.images.id
policy = data.aws_iam_policy_document.images.json
}
data "aws_iam_policy_document" "images" {
policy_id = "PolicyForCloudFrontPrivateContent"
statement {
sid = "AllowCloudFrontServicePrincipal"
effect = "Allow"
principals {
type = "Service"
identifiers = ["cloudfront.amazonaws.com"]
}
actions = [
"s3:GetObject",
]
resources = [
"${aws_s3_bucket.images.arn}/*",
]
condition {
test = "StringEquals"
variable = "AWS:SourceArn"
values = [
module.prod_site.cf_distribution_arn,
module.beta_site.cf_distribution_arn
]
}
}
}
resource "aws_s3_bucket_cors_configuration" "images" {
bucket = aws_s3_bucket.images.id
cors_rule {
allowed_headers = ["*"]
allowed_methods = ["HEAD", "GET", "PUT", "POST", "DELETE"]
allowed_origins = ["*"]
expose_headers = []
}
}
resource "aws_s3_bucket_lifecycle_configuration" "images" {
bucket = aws_s3_bucket.images.id
rule {
id = "clean-test-photos"
filter {
prefix = "test/"
}
status = "Enabled"
expiration {
days = 7
}
noncurrent_version_expiration {
noncurrent_days = 7
}
abort_incomplete_multipart_upload {
days_after_initiation = 7
}
}
rule {
id = "clean-beta-photos"
filter {
prefix = "beta/"
}
status = "Disabled"
expiration {
days = 30
}
noncurrent_version_expiration {
noncurrent_days = 30
}
abort_incomplete_multipart_upload {
days_after_initiation = 30
}
}
}
resource "aws_s3_bucket" "logs" {
bucket = "phlask-logs"
}
resource "aws_s3_bucket_ownership_controls" "logs" {
bucket = aws_s3_bucket.logs.id
rule {
object_ownership = "BucketOwnerPreferred"
}
}
resource "aws_cloudfront_function" "image-path-cleanup" {
name = "image-path-cleanup"
runtime = "cloudfront-js-2.0"
comment = "Managed by Terraform"
publish = true
code = file("${path.module}/src_code/image-path-cleanup/function.js")
}
resource "aws_cloudfront_function" "react-url-rewrite" {
name = "react-url-rewrite"
comment = "Managed by Terraform"
runtime = "cloudfront-js-2.0"
publish = true
code = file("${path.module}/src_code/react-url-rewrite/function.js")
}