-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvariables.tf
453 lines (428 loc) · 16.2 KB
/
variables.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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
# Cloudfront
variable "web_acl_id" {
description = "Optional WAF arn"
type = string
default = ""
}
variable "cloudflare_zone_id" {
description = "ID of the CloudFlare Route53 Zone where to create the records to validate the certificate. Providing it will auto-create the DNS record for the validation of the certificate"
type = string
default = null
}
variable "aliases" {
description = "Alternate domain names for the CloudFront Distribution. A Custom SSL certificate will be created in ACM with the same names"
type = list(string)
validation {
condition = length(var.aliases) > 0
error_message = "You must specify at least one alias for your CloudFront distribution."
}
}
variable "enable_cloudfront" {
description = "Enables the cloudfront distribution. If false: distribution isn't active."
type = bool
default = true
}
variable "enable_cloudfront_staging" {
description = "Enables the cloudfront staging distribution and continuous deployment. If false: staging distribution isn't active. At first deployment, the staging distribution should be set to false. Set this argument once the primary cloudfront exists."
type = bool
default = false
}
variable "cloudfront_staging_weight" {
description = "The weight of the staging distribution. Default: 0. Should be between 0 and 0.15"
type = number
default = 0
}
variable "cloudfront_price_class" {
description = "Price class of the cloudfront distribution."
type = string
default = "PriceClass_100"
}
variable "comment" {
description = "Comments for the cloudfront distribution."
type = string
default = ""
}
variable "default_root_object" {
description = "The object that we want Cloudfront to return"
type = string
default = null
}
variable "http_version" {
description = "Which HTTP version we use"
type = string
default = "http2and3"
}
variable "retain_on_delete" {
description = "Disables the distribution instead of deleting it when destroying the resource through Terraform. If this is set, the distribution needs to be deleted manually afterwards."
type = bool
default = false
}
variable "wait_for_deployment" {
description = "If enabled, the resource will wait for the distribution status to change from In Progress to Deployed. Setting this to false will skip the process. Default: true"
type = bool
default = false
}
variable "dynamic_s3_origin_config" {
description = "Configuration of the S3 bucket used as origin, if any"
type = list(object({
domain_name = string
origin_id = string
origin_path = string
origin_access_identity = optional(string)
}))
default = []
}
variable "dynamic_s3_origin_config_staging" {
description = "Configuration of the S3 bucket used as origin for staging, if any"
type = list(object({
domain_name = string
origin_id = string
origin_path = string
origin_access_identity = optional(string)
}))
default = []
}
variable "dynamic_custom_origin_config" {
description = "Configuration of the custom origin (e.g: HTTP server)"
type = list(object({
domain_name = string
origin_id = string
origin_path = string
http_port = optional(number, 80)
https_port = optional(number, 443)
origin_keepalive_timeout = optional(number, 60)
origin_read_timeout = optional(number, 60)
origin_protocol_policy = optional(string, "https-only")
origin_ssl_protocols = list(string)
custom_header = optional(list(object({
name = string
value = string
})), [])
}))
default = []
}
variable "dynamic_custom_origin_config_staging" {
description = "Configuration of the custom origin for staging (e.g: HTTP server)"
type = list(object({
domain_name = string
origin_id = string
origin_path = string
http_port = optional(number, 80)
https_port = optional(number, 443)
origin_keepalive_timeout = optional(number, 60)
origin_read_timeout = optional(number, 60)
origin_protocol_policy = optional(string, "https-only")
origin_ssl_protocols = list(string)
custom_header = optional(list(object({
name = string
value = string
})), [])
}))
default = []
}
variable "cloudfront_custom_error_response" {
description = "The list of custom errors and their TTLs."
type = list(object({
error_code = number
min_ttl = number
response_page_path = string
response_code = number
}))
default = []
}
variable "viewer_cert_minimum_protocol_version" {
description = "Minimum SSL/TLS protocol for https certificates used by the viewer"
type = string
default = "TLSv1.2_2021"
}
variable "dynamic_ordered_cache_behavior_staging" {
description = "An ordered list of cache behaviors resource for this distribution. List from top to bottom in order of precedence. The topmost cache behavior will have precedence 0."
type = list(object({
path_pattern = string
allowed_methods = list(string)
cached_methods = list(string)
target_origin_id = string
compress = optional(bool, true)
cache_policy = optional(object({
min_ttl = optional(number, 0)
default_ttl = optional(number, 0)
max_ttl = optional(number, 31536000) # 1 year
header_behavior = optional(string, "whitelist")
headers = optional(list(string), ["Host", "Origin"])
cookie_behavior = optional(string, "none")
cookies = optional(list(string), [])
query_string_behavior = optional(string, "all")
query_strings = optional(list(string), [])
enable_brotli = optional(bool, true)
enable_gzip = optional(bool, true)
}), {})
# use this if you want to include additional headers/cookies/query_strings to be forwarded to the origin
origin_request_policy = optional(object({
header_behavior = optional(string, "none")
headers = optional(list(string), [])
cookie_behavior = optional(string, "none")
cookies = optional(list(string), [])
query_string_behavior = optional(string, "none")
query_strings = optional(list(string), [])
}))
viewer_protocol_policy = optional(string, "redirect-to-https")
realtime_log_config_arn = optional(string)
function_association = optional(list(object({
event_type = string
function_arn = string
})), [])
lambda_at_edge = optional(list(object({
lambda_arn = string
event_type = string
include_body = bool
})), [])
}))
default = []
}
variable "dynamic_ordered_cache_behavior" {
description = "An ordered list of cache behaviors resource for this distribution. List from top to bottom in order of precedence. The topmost cache behavior will have precedence 0."
type = list(object({
path_pattern = string
allowed_methods = list(string)
cached_methods = list(string)
target_origin_id = string
compress = optional(bool, true)
cache_policy = optional(object({
min_ttl = optional(number, 0)
default_ttl = optional(number, 0)
max_ttl = optional(number, 31536000) # 1 year
header_behavior = optional(string, "whitelist")
headers = optional(list(string), ["Host", "Origin"])
cookie_behavior = optional(string, "none")
cookies = optional(list(string), [])
query_string_behavior = optional(string, "all")
query_strings = optional(list(string), [])
enable_brotli = optional(bool, true)
enable_gzip = optional(bool, true)
}), {})
# use this if you want to include additional headers/cookies/query_strings to be forwarded to the origin
origin_request_policy = optional(object({
header_behavior = optional(string, "none")
headers = optional(list(string), [])
cookie_behavior = optional(string, "none")
cookies = optional(list(string), [])
query_string_behavior = optional(string, "none")
query_strings = optional(list(string), [])
}))
viewer_protocol_policy = optional(string, "redirect-to-https")
realtime_log_config_arn = optional(string)
function_association = optional(list(object({
event_type = string
function_arn = string
})), [])
lambda_at_edge = optional(list(object({
lambda_arn = string
event_type = string
include_body = bool
})), [])
}))
default = []
}
variable "default_cache_behavior_staging" {
description = "Default cache behavior resource for this distribution."
type = object({
path_pattern = string
allowed_methods = list(string)
cached_methods = list(string)
target_origin_id = string
compress = optional(bool, true)
cache_policy = optional(object({
min_ttl = optional(number, 0)
default_ttl = optional(number, 0)
max_ttl = optional(number, 31536000) # 1 year
header_behavior = optional(string, "whitelist")
headers = optional(list(string), ["Host", "Origin"])
cookie_behavior = optional(string, "none")
cookies = optional(list(string), [])
query_string_behavior = optional(string, "all")
query_strings = optional(list(string), [])
enable_brotli = optional(bool, true)
enable_gzip = optional(bool, true)
}), {})
# use this if you want to include additional headers/cookies/query_strings to be forwarded to the origin
origin_request_policy = optional(object({
header_behavior = optional(string, "none")
headers = optional(list(string), [])
cookie_behavior = optional(string, "none")
cookies = optional(list(string), [])
query_string_behavior = optional(string, "none")
query_strings = optional(list(string), [])
}))
viewer_protocol_policy = optional(string, "redirect-to-https")
realtime_log_config_arn = optional(string)
function_association = optional(list(object({
event_type = string
function_arn = string
})), [])
lambda_at_edge = optional(list(object({
lambda_arn = string
event_type = string
include_body = bool
})), [])
})
default = null
}
variable "default_cache_behavior" {
description = "Default cache behavior resource for this distribution."
type = object({
path_pattern = string
allowed_methods = list(string)
cached_methods = list(string)
target_origin_id = string
compress = optional(bool, true)
cache_policy = optional(object({
min_ttl = optional(number, 0)
default_ttl = optional(number, 0)
max_ttl = optional(number, 31536000) # 1 year
header_behavior = optional(string, "whitelist")
headers = optional(list(string), ["Host", "Origin"])
cookie_behavior = optional(string, "none")
cookies = optional(list(string), [])
query_string_behavior = optional(string, "all")
query_strings = optional(list(string), [])
enable_brotli = optional(bool, true)
enable_gzip = optional(bool, true)
}), {})
# use this if you want to include additional headers/cookies/query_strings to be forwarded to the origin
origin_request_policy = optional(object({
header_behavior = optional(string, "none")
headers = optional(list(string), [])
cookie_behavior = optional(string, "none")
cookies = optional(list(string), [])
query_string_behavior = optional(string, "none")
query_strings = optional(list(string), [])
}))
viewer_protocol_policy = optional(string, "redirect-to-https")
realtime_log_config_arn = optional(string)
function_association = optional(list(object({
event_type = string
function_arn = string
})), [])
lambda_at_edge = optional(list(object({
lambda_arn = string
event_type = string
include_body = bool
})), [])
})
default = null
}
variable "dynamic_origin_group" {
description = "One or more origin_group for this distribution (multiples allowed)."
type = list(object({
id = string
status_codes = list(number)
member1 = string
member2 = string
}))
default = []
}
variable "dynamic_origin_group_staging" {
description = "One or more origin_group for staging distribution (multiples allowed)."
type = list(object({
id = string
status_codes = list(number)
member1 = string
member2 = string
}))
default = []
}
# LOGS
variable "logging" {
description = "Enable logging capabilities for CloudFront"
type = object({
activate = bool
deploy_resources = bool
bucket_prefix = optional(string, "aws-cloudfront-logs")
bucket_override = optional(string, null)
cloudfront_realtime_log_fields = optional(list(string), [ # See https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/real-time-logs.html#understand-real-time-log-config-fields
"asn",
"c-country",
"c-ip",
"c-ip-version",
"c-port",
"cache-behavior-path-pattern",
"cmcd-buffer-length",
"cmcd-buffer-starvation",
"cmcd-content-id",
"cmcd-deadline",
"cmcd-encoded-bitrate",
"cmcd-measured-throughput",
"cmcd-next-object-request",
"cmcd-next-range-request",
"cmcd-object-duration",
"cmcd-object-type",
"cmcd-playback-rate",
"cmcd-requested-maximum-throughput",
"cmcd-session-id",
"cmcd-startup",
"cmcd-stream-type",
"cmcd-streaming-format",
"cmcd-top-bitrate",
"cmcd-version",
"cs-accept",
"cs-accept-encoding",
"cs-bytes",
"cs-cookie",
"cs-header-names",
"cs-headers",
"cs-headers-count",
"cs-host",
"cs-method",
"cs-protocol",
"cs-protocol-version",
"cs-referer",
"cs-uri-query",
"cs-uri-stem",
"cs-user-agent",
"fle-encrypted-fields",
"fle-status",
"origin-fbl",
"origin-lbl",
"primary-distribution-dns-name",
"primary-distribution-id",
"sc-bytes",
"sc-content-len",
"sc-content-type",
"sc-range-end",
"sc-range-start",
"sc-status",
"ssl-cipher",
"ssl-protocol",
"time-taken",
"time-to-first-byte",
"timestamp",
"x-edge-detailed-result-type",
"x-edge-location",
"x-edge-request-id",
"x-edge-response-result-type",
"x-edge-result-type",
"x-forwarded-for",
"x-host-header"
])
cloudfront_realtime_log_sampling_rate = optional(number, 1)
logs_prefix = optional(string, "logs/")
retention_days = optional(number, 30)
datadog_api_key = optional(string, null)
})
default = {
activate = false
deploy_resources = false
}
validation {
condition = !(var.logging.activate && !var.logging.deploy_resources && var.logging.bucket_override == null)
error_message = "In order to activate logs you should deploy infrastructure resources, which can be done by setting the 'deploy_resources' variable to 'true', or override the s3 bucket name"
}
validation {
condition = !(var.logging.bucket_override != null && var.logging.deploy_resources)
error_message = "If you override the bucket name where logs will be stored you should not deploy the loggin infrastructure, this can be done by setting the 'deploy_resources' variable to 'false'"
}
validation {
condition = var.logging.cloudfront_realtime_log_sampling_rate >= 1 && var.logging.cloudfront_realtime_log_sampling_rate <= 100
error_message = "Should be between 1 and 100 inclusive"
}
}