Skip to content

Commit d597a70

Browse files
committed
fix: Switch default type to avoid type checking acrobatics
1 parent a733ea9 commit d597a70

File tree

7 files changed

+20
-15
lines changed

7 files changed

+20
-15
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ No modules.
200200
| <a name="input_http_version"></a> [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 |
201201
| <a name="input_is_ipv6_enabled"></a> [is\_ipv6\_enabled](#input\_is\_ipv6\_enabled) | Whether the IPv6 is enabled for the distribution | `bool` | `true` | no |
202202
| <a name="input_logging_config"></a> [logging\_config](#input\_logging\_config) | The logging configuration that controls how logs are written to your distribution (maximum one) | <pre>object({<br/> bucket = optional(string)<br/> include_cookies = optional(bool)<br/> prefix = optional(string)<br/> })</pre> | `null` | no |
203-
| <a name="input_ordered_cache_behavior"></a> [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 | <pre>list(object({<br/> allowed_methods = optional(list(string), ["GET", "HEAD", "OPTIONS"])<br/> cached_methods = optional(list(string), ["GET", "HEAD"])<br/> cache_policy_id = optional(string)<br/> cache_policy_name = optional(string)<br/> compress = optional(bool, true)<br/> default_ttl = optional(number)<br/> field_level_encryption_id = optional(string)<br/> forwarded_values = optional(object({<br/> cookies = object({<br/> forward = optional(string, "none")<br/> whitelisted_names = optional(list(string))<br/> })<br/> headers = optional(list(string))<br/> query_string = optional(bool, false)<br/> query_string_cache_keys = optional(list(string))<br/> }),<br/> {<br/> cookies = {<br/> forward = "none"<br/> }<br/> query_string = false<br/> }<br/> )<br/> function_association = optional(map(object({<br/> event_type = optional(string)<br/> function_arn = optional(string)<br/> function_key = optional(string)<br/> })))<br/> grpc_config = optional(object({<br/> enabled = optional(bool)<br/> }))<br/> lambda_function_association = optional(map(object({<br/> event_type = optional(string)<br/> include_body = optional(bool)<br/> lambda_arn = string<br/> })))<br/> max_ttl = optional(number)<br/> min_ttl = optional(number)<br/> origin_request_policy_id = optional(string)<br/> origin_request_policy_name = optional(string)<br/> path_pattern = string<br/> realtime_log_config_arn = optional(string)<br/> response_headers_policy_id = optional(string)<br/> response_headers_policy_name = optional(string)<br/> smooth_streaming = optional(bool)<br/> target_origin_id = string<br/> trusted_key_groups = optional(list(string))<br/> trusted_signers = optional(list(string))<br/> viewer_protocol_policy = string<br/> }))</pre> | `null` | no |
203+
| <a name="input_ordered_cache_behavior"></a> [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 | <pre>list(object({<br/> allowed_methods = optional(list(string), ["GET", "HEAD", "OPTIONS"])<br/> cached_methods = optional(list(string), ["GET", "HEAD"])<br/> cache_policy_id = optional(string)<br/> cache_policy_name = optional(string)<br/> compress = optional(bool, true)<br/> default_ttl = optional(number)<br/> field_level_encryption_id = optional(string)<br/> forwarded_values = optional(object({<br/> cookies = object({<br/> forward = optional(string, "none")<br/> whitelisted_names = optional(list(string))<br/> })<br/> headers = optional(list(string))<br/> query_string = optional(bool, false)<br/> query_string_cache_keys = optional(list(string))<br/> }),<br/> {<br/> cookies = {<br/> forward = "none"<br/> }<br/> query_string = false<br/> }<br/> )<br/> function_association = optional(map(object({<br/> event_type = optional(string)<br/> function_arn = optional(string)<br/> function_key = optional(string)<br/> })))<br/> grpc_config = optional(object({<br/> enabled = optional(bool)<br/> }))<br/> lambda_function_association = optional(map(object({<br/> event_type = optional(string)<br/> include_body = optional(bool)<br/> lambda_arn = string<br/> })))<br/> max_ttl = optional(number)<br/> min_ttl = optional(number)<br/> origin_request_policy_id = optional(string)<br/> origin_request_policy_name = optional(string)<br/> path_pattern = string<br/> realtime_log_config_arn = optional(string)<br/> response_headers_policy_id = optional(string)<br/> response_headers_policy_name = optional(string)<br/> smooth_streaming = optional(bool)<br/> target_origin_id = string<br/> trusted_key_groups = optional(list(string))<br/> trusted_signers = optional(list(string))<br/> viewer_protocol_policy = string<br/> }))</pre> | `[]` | no |
204204
| <a name="input_origin"></a> [origin](#input\_origin) | One or more origins for this distribution (multiples allowed) | <pre>map(object({<br/> connection_attempts = optional(number)<br/> connection_timeout = optional(number)<br/> custom_header = optional(map(string))<br/> custom_origin_config = optional(object({<br/> http_port = number<br/> https_port = number<br/> ip_address_type = optional(string)<br/> origin_keepalive_timeout = optional(number)<br/> origin_read_timeout = optional(number)<br/> origin_protocol_policy = string<br/> origin_ssl_protocols = optional(list(string), ["TLSv1.2"])<br/> }))<br/> domain_name = string<br/> origin_access_control_key = optional(string)<br/> origin_access_control_id = optional(string)<br/> origin_id = optional(string)<br/> origin_path = optional(string)<br/> origin_shield = optional(object({<br/> enabled = bool<br/> origin_shield_region = optional(string)<br/> }))<br/> response_completion_timeout = optional(number)<br/> vpc_origin_config = optional(object({<br/> origin_keepalive_timeout = optional(number)<br/> origin_read_timeout = optional(number)<br/> vpc_origin_id = optional(string)<br/> vpc_origin_key = optional(string)<br/> }))<br/> }))</pre> | `{}` | no |
205205
| <a name="input_origin_access_control"></a> [origin\_access\_control](#input\_origin\_access\_control) | Map of CloudFront origin access control | <pre>map(object({<br/> description = optional(string)<br/> name = optional(string)<br/> origin_type = string<br/> signing_behavior = string<br/> signing_protocol = string<br/> }))</pre> | <pre>{<br/> "s3": {<br/> "origin_type": "s3",<br/> "signing_behavior": "always",<br/> "signing_protocol": "sigv4"<br/> }<br/>}</pre> | no |
206206
| <a name="input_origin_group"></a> [origin\_group](#input\_origin\_group) | One or more origin\_group for this distribution (multiples allowed) | <pre>map(object({<br/> failover_criteria = object({<br/> status_codes = list(number)<br/> })<br/> member = list(object({<br/> origin_id = string<br/> }))<br/> origin_id = optional(string)<br/> }))</pre> | `null` | no |

examples/complete/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,9 @@ Note that this example may create resources which cost money. Run `terraform des
5757

5858
## Inputs
5959

60-
No inputs.
60+
| Name | Description | Type | Default | Required |
61+
|------|-------------|------|---------|:--------:|
62+
| <a name="input_domain"></a> [domain](#input\_domain) | The domain name to use when deploying the CloudFront distribution | `string` | `"terraform-aws-modules.modules.tf"` | no |
6163

6264
## Outputs
6365

examples/complete/main.tf

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ data "aws_availability_zones" "available" {
1111
}
1212

1313
locals {
14-
# domain_name = "terraform-aws-modules.modules.tf"
15-
domain_name = "sharedservices.clowd.haus"
16-
subdomain = "cdn"
14+
subdomain = "cdn"
1715

1816
name = "ex-${basename(path.cwd)}"
1917

@@ -34,7 +32,7 @@ locals {
3432
module "cloudfront" {
3533
source = "../../"
3634

37-
aliases = ["${local.subdomain}.${local.domain_name}"]
35+
aliases = ["${local.subdomain}.${var.domain}"]
3836

3937
comment = "My awesome CloudFront"
4038
enabled = true
@@ -79,7 +77,7 @@ module "cloudfront" {
7977

8078
origin = {
8179
appsync = {
82-
domain_name = "appsync.${local.domain_name}"
80+
domain_name = "appsync.${var.domain}"
8381
custom_origin_config = {
8482
http_port = 80
8583
https_port = 443
@@ -389,16 +387,16 @@ resource "aws_cloudfront_function" "example" {
389387
}
390388

391389
data "aws_route53_zone" "this" {
392-
name = local.domain_name
390+
name = var.domain
393391
}
394392

395393
module "acm" {
396394
source = "terraform-aws-modules/acm/aws"
397395
version = "~> 4.0"
398396

399-
domain_name = local.domain_name
397+
domain_name = var.domain
400398
zone_id = data.aws_route53_zone.this.id
401-
subject_alternative_names = ["${local.subdomain}.${local.domain_name}"]
399+
subject_alternative_names = ["${local.subdomain}.${var.domain}"]
402400

403401
tags = local.tags
404402
}

examples/complete/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
variable "domain" {
2+
description = "The domain name to use when deploying the CloudFront distribution"
3+
type = string
4+
default = "terraform-aws-modules.modules.tf"
5+
}

main.tf

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ resource "aws_cloudfront_distribution" "this" {
108108
}
109109

110110
dynamic "ordered_cache_behavior" {
111-
for_each = var.ordered_cache_behavior != null ? var.ordered_cache_behavior : []
111+
for_each = length(var.ordered_cache_behavior) > 0 ? var.ordered_cache_behavior : []
112112

113113
content {
114114
allowed_methods = ordered_cache_behavior.value.allowed_methods
@@ -535,8 +535,7 @@ resource "aws_cloudfront_monitoring_subscription" "this" {
535535
################################################################################
536536

537537
locals {
538-
ordered_cache_behavior_normalized = var.ordered_cache_behavior == null ? [] : var.ordered_cache_behavior
539-
cache_behaviors = concat([var.default_cache_behavior], local.ordered_cache_behavior_normalized)
538+
cache_behaviors = concat([var.default_cache_behavior], var.ordered_cache_behavior)
540539
}
541540

542541
data "aws_cloudfront_cache_policy" "this" {

variables.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,8 @@ variable "ordered_cache_behavior" {
191191
trusted_signers = optional(list(string))
192192
viewer_protocol_policy = string
193193
}))
194-
default = null
194+
default = []
195+
nullable = false
195196
}
196197

197198
variable "origin_group" {

wrappers/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module "wrapper" {
1717
http_version = try(each.value.http_version, var.defaults.http_version, "http2")
1818
is_ipv6_enabled = try(each.value.is_ipv6_enabled, var.defaults.is_ipv6_enabled, true)
1919
logging_config = try(each.value.logging_config, var.defaults.logging_config, null)
20-
ordered_cache_behavior = try(each.value.ordered_cache_behavior, var.defaults.ordered_cache_behavior, null)
20+
ordered_cache_behavior = try(each.value.ordered_cache_behavior, var.defaults.ordered_cache_behavior, [])
2121
origin = try(each.value.origin, var.defaults.origin, {})
2222
origin_access_control = try(each.value.origin_access_control, var.defaults.origin_access_control, {
2323
s3 = {

0 commit comments

Comments
 (0)