From b61243e0163e12a6e4a4ba35c0680aee99da6a60 Mon Sep 17 00:00:00 2001 From: Ben Kero Date: Sun, 6 Dec 2020 12:05:25 -0800 Subject: [PATCH] add custom_header variable to send custom headers to origin (#47) --- README.md | 1 + docs/terraform.md | 1 + examples/complete/variables.tf | 10 ++++++++++ main.tf | 10 ++++++++++ variables.tf | 10 ++++++++++ 5 files changed, 32 insertions(+) diff --git a/README.md b/README.md index 10d72e8..8b7c54c 100644 --- a/README.md +++ b/README.md @@ -142,6 +142,7 @@ Available targets: | compress | Whether you want CloudFront to automatically compress content for web requests that include Accept-Encoding: gzip in the request header (default: false) | `bool` | `false` | no | | context | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. |
object({
enabled = bool
namespace = string
environment = string
stage = string
name = string
delimiter = string
attributes = list(string)
tags = map(string)
additional_tag_map = map(string)
regex_replace_chars = string
label_order = list(string)
id_length_limit = number
})
|
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_order": [],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {}
}
| no | | custom\_error\_response | List of one or more custom error response element maps |
list(object({
error_caching_min_ttl = string
error_code = string
response_code = string
response_page_path = string
}))
| `[]` | no | +| custom\_header | List of one or more custom headers passed to the origin |
list(object({
name = string
value = string
}))
| `[]` | no | | default\_root\_object | Object that CloudFront return when requests the root URL | `string` | `"index.html"` | no | | default\_ttl | Default amount of time (in seconds) that an object is in a CloudFront cache | `number` | `60` | no | | delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no | diff --git a/docs/terraform.md b/docs/terraform.md index 02b2a9a..b98271a 100644 --- a/docs/terraform.md +++ b/docs/terraform.md @@ -27,6 +27,7 @@ | compress | Whether you want CloudFront to automatically compress content for web requests that include Accept-Encoding: gzip in the request header (default: false) | `bool` | `false` | no | | context | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. |
object({
enabled = bool
namespace = string
environment = string
stage = string
name = string
delimiter = string
attributes = list(string)
tags = map(string)
additional_tag_map = map(string)
regex_replace_chars = string
label_order = list(string)
id_length_limit = number
})
|
{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_order": [],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {}
}
| no | | custom\_error\_response | List of one or more custom error response element maps |
list(object({
error_caching_min_ttl = string
error_code = string
response_code = string
response_page_path = string
}))
| `[]` | no | +| custom\_header | List of one or more custom headers passed to the origin |
list(object({
name = string
value = string
}))
| `[]` | no | | default\_root\_object | Object that CloudFront return when requests the root URL | `string` | `"index.html"` | no | | default\_ttl | Default amount of time (in seconds) that an object is in a CloudFront cache | `number` | `60` | no | | delimiter | Delimiter to be used between `namespace`, `environment`, `stage`, `name` and `attributes`.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no | diff --git a/examples/complete/variables.tf b/examples/complete/variables.tf index 6a094a0..7d4f5b4 100644 --- a/examples/complete/variables.tf +++ b/examples/complete/variables.tf @@ -33,6 +33,16 @@ variable "custom_error_response" { default = [] } +variable "custom_header" { + type = list(object({ + name = string + value = string + })) + + description = "List of one or more custom headers passed to the origin" + default = [] +} + variable "web_acl_id" { description = "(Optional) - Web ACL ID that can be attached to the Cloudfront distribution" default = "" diff --git a/main.tf b/main.tf index 9968bc7..0860238 100644 --- a/main.tf +++ b/main.tf @@ -68,6 +68,16 @@ resource "aws_cloudfront_distribution" "default" { origin_keepalive_timeout = var.origin_keepalive_timeout origin_read_timeout = var.origin_read_timeout } + + dynamic custom_header { + for_each = var.custom_header + content { + name = custom_header.value.name + value = custom_header.value.value + } + } + + } viewer_certificate { diff --git a/variables.tf b/variables.tf index bb161f3..bf565cb 100644 --- a/variables.tf +++ b/variables.tf @@ -36,6 +36,16 @@ variable "custom_error_response" { default = [] } +variable "custom_header" { + type = list(object({ + name = string + value = string + })) + + description = "List of one or more custom headers passed to the origin" + default = [] +} + variable "web_acl_id" { type = string description = "ID of the AWS WAF web ACL that is associated with the distribution"