diff --git a/README.md b/README.md index 4a12232..627545f 100644 --- a/README.md +++ b/README.md @@ -200,7 +200,7 @@ No modules. | [http\_version](#input\_http\_version) | The maximum HTTP version to support on the distribution. Allowed values are http1.1, http2, http2and3, and http3. The default is http2 | `string` | `"http2"` | no | | [is\_ipv6\_enabled](#input\_is\_ipv6\_enabled) | Whether the IPv6 is enabled for the distribution | `bool` | `true` | no | | [logging\_config](#input\_logging\_config) | The logging configuration that controls how logs are written to your distribution (maximum one) |
object({
bucket = optional(string)
include_cookies = optional(bool)
prefix = optional(string)
})
| `null` | no | -| [ordered\_cache\_behavior](#input\_ordered\_cache\_behavior) | 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 |
list(object({
allowed_methods = optional(list(string), ["GET", "HEAD", "OPTIONS"])
cached_methods = optional(list(string), ["GET", "HEAD"])
cache_policy_id = optional(string)
cache_policy_name = optional(string)
compress = optional(bool, true)
default_ttl = optional(number)
field_level_encryption_id = optional(string)
forwarded_values = optional(object({
cookies = object({
forward = optional(string, "none")
whitelisted_names = optional(list(string))
})
headers = optional(list(string))
query_string = optional(bool, false)
query_string_cache_keys = optional(list(string))
}),
{
cookies = {
forward = "none"
}
query_string = false
}
)
function_association = optional(map(object({
event_type = optional(string)
function_arn = optional(string)
function_key = optional(string)
})))
grpc_config = optional(object({
enabled = optional(bool)
}))
lambda_function_association = optional(map(object({
event_type = optional(string)
include_body = optional(bool)
lambda_arn = string
})))
max_ttl = optional(number)
min_ttl = optional(number)
origin_request_policy_id = optional(string)
origin_request_policy_name = optional(string)
path_pattern = string
realtime_log_config_arn = optional(string)
response_headers_policy_id = optional(string)
response_headers_policy_name = optional(string)
smooth_streaming = optional(bool)
target_origin_id = string
trusted_key_groups = optional(list(string))
trusted_signers = optional(list(string))
viewer_protocol_policy = string
}))
| `null` | no | +| [ordered\_cache\_behavior](#input\_ordered\_cache\_behavior) | 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 |
list(object({
allowed_methods = optional(list(string), ["GET", "HEAD", "OPTIONS"])
cached_methods = optional(list(string), ["GET", "HEAD"])
cache_policy_id = optional(string)
cache_policy_name = optional(string)
compress = optional(bool, true)
default_ttl = optional(number)
field_level_encryption_id = optional(string)
forwarded_values = optional(object({
cookies = object({
forward = optional(string, "none")
whitelisted_names = optional(list(string))
})
headers = optional(list(string))
query_string = optional(bool, false)
query_string_cache_keys = optional(list(string))
}),
{
cookies = {
forward = "none"
}
query_string = false
}
)
function_association = optional(map(object({
event_type = optional(string)
function_arn = optional(string)
function_key = optional(string)
})))
grpc_config = optional(object({
enabled = optional(bool)
}))
lambda_function_association = optional(map(object({
event_type = optional(string)
include_body = optional(bool)
lambda_arn = string
})))
max_ttl = optional(number)
min_ttl = optional(number)
origin_request_policy_id = optional(string)
origin_request_policy_name = optional(string)
path_pattern = string
realtime_log_config_arn = optional(string)
response_headers_policy_id = optional(string)
response_headers_policy_name = optional(string)
smooth_streaming = optional(bool)
target_origin_id = string
trusted_key_groups = optional(list(string))
trusted_signers = optional(list(string))
viewer_protocol_policy = string
}))
| `[]` | no | | [origin](#input\_origin) | One or more origins for this distribution (multiples allowed) |
map(object({
connection_attempts = optional(number)
connection_timeout = optional(number)
custom_header = optional(map(string))
custom_origin_config = optional(object({
http_port = number
https_port = number
ip_address_type = optional(string)
origin_keepalive_timeout = optional(number)
origin_read_timeout = optional(number)
origin_protocol_policy = string
origin_ssl_protocols = optional(list(string), ["TLSv1.2"])
}))
domain_name = string
origin_access_control_key = optional(string)
origin_access_control_id = optional(string)
origin_id = optional(string)
origin_path = optional(string)
origin_shield = optional(object({
enabled = bool
origin_shield_region = optional(string)
}))
response_completion_timeout = optional(number)
vpc_origin_config = optional(object({
origin_keepalive_timeout = optional(number)
origin_read_timeout = optional(number)
vpc_origin_id = optional(string)
vpc_origin_key = optional(string)
}))
}))
| `{}` | no | | [origin\_access\_control](#input\_origin\_access\_control) | Map of CloudFront origin access control |
map(object({
description = optional(string)
name = optional(string)
origin_type = string
signing_behavior = string
signing_protocol = string
}))
|
{
"s3": {
"origin_type": "s3",
"signing_behavior": "always",
"signing_protocol": "sigv4"
}
}
| no | | [origin\_group](#input\_origin\_group) | One or more origin\_group for this distribution (multiples allowed) |
map(object({
failover_criteria = object({
status_codes = list(number)
})
member = list(object({
origin_id = string
}))
origin_id = optional(string)
}))
| `null` | no | diff --git a/examples/complete/README.md b/examples/complete/README.md index afe8c16..89805d9 100644 --- a/examples/complete/README.md +++ b/examples/complete/README.md @@ -57,7 +57,9 @@ Note that this example may create resources which cost money. Run `terraform des ## Inputs -No inputs. +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [domain](#input\_domain) | The domain name to use when deploying the CloudFront distribution | `string` | `"terraform-aws-modules.modules.tf"` | no | ## Outputs diff --git a/examples/complete/main.tf b/examples/complete/main.tf index fb108f4..171c004 100644 --- a/examples/complete/main.tf +++ b/examples/complete/main.tf @@ -11,9 +11,7 @@ data "aws_availability_zones" "available" { } locals { - # domain_name = "terraform-aws-modules.modules.tf" - domain_name = "sharedservices.clowd.haus" - subdomain = "cdn" + subdomain = "cdn" name = "ex-${basename(path.cwd)}" @@ -34,7 +32,7 @@ locals { module "cloudfront" { source = "../../" - aliases = ["${local.subdomain}.${local.domain_name}"] + aliases = ["${local.subdomain}.${var.domain}"] comment = "My awesome CloudFront" enabled = true @@ -79,7 +77,7 @@ module "cloudfront" { origin = { appsync = { - domain_name = "appsync.${local.domain_name}" + domain_name = "appsync.${var.domain}" custom_origin_config = { http_port = 80 https_port = 443 @@ -389,16 +387,16 @@ resource "aws_cloudfront_function" "example" { } data "aws_route53_zone" "this" { - name = local.domain_name + name = var.domain } module "acm" { source = "terraform-aws-modules/acm/aws" version = "~> 4.0" - domain_name = local.domain_name + domain_name = var.domain zone_id = data.aws_route53_zone.this.id - subject_alternative_names = ["${local.subdomain}.${local.domain_name}"] + subject_alternative_names = ["${local.subdomain}.${var.domain}"] tags = local.tags } diff --git a/examples/complete/variables.tf b/examples/complete/variables.tf index e69de29..573bce1 100644 --- a/examples/complete/variables.tf +++ b/examples/complete/variables.tf @@ -0,0 +1,5 @@ +variable "domain" { + description = "The domain name to use when deploying the CloudFront distribution" + type = string + default = "terraform-aws-modules.modules.tf" +} diff --git a/main.tf b/main.tf index bd9b08a..2e44c66 100644 --- a/main.tf +++ b/main.tf @@ -108,7 +108,7 @@ resource "aws_cloudfront_distribution" "this" { } dynamic "ordered_cache_behavior" { - for_each = var.ordered_cache_behavior != null ? var.ordered_cache_behavior : [] + for_each = length(var.ordered_cache_behavior) > 0 ? var.ordered_cache_behavior : [] content { allowed_methods = ordered_cache_behavior.value.allowed_methods @@ -535,7 +535,7 @@ resource "aws_cloudfront_monitoring_subscription" "this" { ################################################################################ locals { - cache_behaviors = var.ordered_cache_behavior != null ? concat([var.default_cache_behavior], var.ordered_cache_behavior) : [var.default_cache_behavior] + cache_behaviors = concat([var.default_cache_behavior], var.ordered_cache_behavior) } data "aws_cloudfront_cache_policy" "this" { diff --git a/variables.tf b/variables.tf index d7ac1e3..e116580 100644 --- a/variables.tf +++ b/variables.tf @@ -191,7 +191,8 @@ variable "ordered_cache_behavior" { trusted_signers = optional(list(string)) viewer_protocol_policy = string })) - default = null + default = [] + nullable = false } variable "origin_group" { diff --git a/wrappers/main.tf b/wrappers/main.tf index 0379e31..8a0f7c0 100644 --- a/wrappers/main.tf +++ b/wrappers/main.tf @@ -17,7 +17,7 @@ module "wrapper" { http_version = try(each.value.http_version, var.defaults.http_version, "http2") is_ipv6_enabled = try(each.value.is_ipv6_enabled, var.defaults.is_ipv6_enabled, true) logging_config = try(each.value.logging_config, var.defaults.logging_config, null) - ordered_cache_behavior = try(each.value.ordered_cache_behavior, var.defaults.ordered_cache_behavior, null) + ordered_cache_behavior = try(each.value.ordered_cache_behavior, var.defaults.ordered_cache_behavior, []) origin = try(each.value.origin, var.defaults.origin, {}) origin_access_control = try(each.value.origin_access_control, var.defaults.origin_access_control, { s3 = {