Skip to content

Commit 8e61366

Browse files
committed
fix: Fix error when ordered cache behavior is not set, make default_cache_behavior nullable to be able to create other resources without creating a distribution
1 parent 501d39e commit 8e61366

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ No modules.
194194
| <a name="input_create"></a> [create](#input\_create) | Controls if resources should be created (affects nearly all resources) | `bool` | `true` | no |
195195
| <a name="input_create_monitoring_subscription"></a> [create\_monitoring\_subscription](#input\_create\_monitoring\_subscription) | If enabled, the resource for monitoring subscription will created | `bool` | `false` | no |
196196
| <a name="input_custom_error_response"></a> [custom\_error\_response](#input\_custom\_error\_response) | One or more custom error response elements | <pre>list(object({<br/> error_caching_min_ttl = optional(number)<br/> error_code = number<br/> response_code = optional(number)<br/> response_page_path = optional(string)<br/> }))</pre> | `null` | no |
197-
| <a name="input_default_cache_behavior"></a> [default\_cache\_behavior](#input\_default\_cache\_behavior) | The default cache behavior for this distribution | <pre>object({<br/> allowed_methods = optional(list(string), ["GET", "HEAD", "OPTIONS"])<br/> cache_policy_id = optional(string)<br/> cache_policy_name = optional(string)<br/> cached_methods = optional(list(string), ["GET", "HEAD"])<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/> 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 = optional(string, "https-only")<br/> })</pre> | n/a | yes |
197+
| <a name="input_default_cache_behavior"></a> [default\_cache\_behavior](#input\_default\_cache\_behavior) | The default cache behavior for this distribution | <pre>object({<br/> allowed_methods = optional(list(string), ["GET", "HEAD", "OPTIONS"])<br/> cache_policy_id = optional(string)<br/> cache_policy_name = optional(string)<br/> cached_methods = optional(list(string), ["GET", "HEAD"])<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/> 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 = optional(string, "https-only")<br/> })</pre> | `null` | no |
198198
| <a name="input_default_root_object"></a> [default\_root\_object](#input\_default\_root\_object) | The object that you want CloudFront to return (for example, index.html) when an end user requests the root URL | `string` | `null` | no |
199199
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Whether the distribution is enabled to accept end user requests for content | `bool` | `true` | no |
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 |

main.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,10 @@ resource "aws_cloudfront_monitoring_subscription" "this" {
535535
################################################################################
536536

537537
locals {
538-
cache_behaviors = concat([var.default_cache_behavior], var.ordered_cache_behavior)
538+
cache_behaviors = concat(
539+
var.default_cache_behavior != null ? [var.default_cache_behavior] : [],
540+
var.ordered_cache_behavior != null ? var.ordered_cache_behavior : []
541+
)
539542
}
540543

541544
data "aws_cloudfront_cache_policy" "this" {

variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ variable "default_cache_behavior" {
101101
trusted_signers = optional(list(string))
102102
viewer_protocol_policy = optional(string, "https-only")
103103
})
104-
nullable = false
104+
default = null
105105
}
106106

107107
variable "default_root_object" {

wrappers/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ module "wrapper" {
1111
create = try(each.value.create, var.defaults.create, true)
1212
create_monitoring_subscription = try(each.value.create_monitoring_subscription, var.defaults.create_monitoring_subscription, false)
1313
custom_error_response = try(each.value.custom_error_response, var.defaults.custom_error_response, null)
14-
default_cache_behavior = try(each.value.default_cache_behavior, var.defaults.default_cache_behavior)
14+
default_cache_behavior = try(each.value.default_cache_behavior, var.defaults.default_cache_behavior, null)
1515
default_root_object = try(each.value.default_root_object, var.defaults.default_root_object, null)
1616
enabled = try(each.value.enabled, var.defaults.enabled, true)
1717
http_version = try(each.value.http_version, var.defaults.http_version, "http2")

0 commit comments

Comments
 (0)