Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ No modules.
| <a name="input_create"></a> [create](#input\_create) | Controls if resources should be created (affects nearly all resources) | `bool` | `true` | no |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
| <a name="input_enabled"></a> [enabled](#input\_enabled) | Whether the distribution is enabled to accept end user requests for content | `bool` | `true` | no |
| <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 |
Expand Down
27 changes: 22 additions & 5 deletions examples/complete/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,10 @@ module "cloudfront" {
viewer-request = {
function_arn = aws_cloudfront_function.example.arn
}
# Or ARN reference to standalone function created with the module
viewer-response = {
function_arn = module.standalone_cloudfront_functions.cloudfront_functions.example.arn
}

# Option 2: Dynamic reference to module-managed function by key/name
# Uncomment to use module-managed functions instead:
Expand All @@ -179,11 +183,6 @@ module "cloudfront" {
# viewer-response = {
# function_key = "viewer-response-headers"
# }

# For this example, using standalone function for both
viewer-response = {
function_arn = aws_cloudfront_function.example.arn
}
}
},
{
Expand Down Expand Up @@ -337,6 +336,24 @@ module "cloudfront" {
tags = local.tags
}

# Create CloudFront function using the module
module "standalone_cloudfront_functions" {
source = "../../"

# Don't create main resources, only functions
create = false

cloudfront_functions = {
example = {
name = "shared-${local.name}"
runtime = "cloudfront-js-1.0"
code = file("./functions/example-function.js")
}
}

origin_access_control = {}
}

module "records" {
source = "terraform-aws-modules/route53/aws//modules/records"
version = "~> 5.0"
Expand Down
5 changes: 4 additions & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,10 @@ resource "aws_cloudfront_monitoring_subscription" "this" {
################################################################################

locals {
cache_behaviors = concat([var.default_cache_behavior], var.ordered_cache_behavior)
cache_behaviors = concat(
var.default_cache_behavior != null ? [var.default_cache_behavior] : [],
var.ordered_cache_behavior != null ? var.ordered_cache_behavior : []
)
}

data "aws_cloudfront_cache_policy" "this" {
Expand Down
2 changes: 1 addition & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ variable "default_cache_behavior" {
trusted_signers = optional(list(string))
viewer_protocol_policy = optional(string, "https-only")
})
nullable = false
default = null
}

variable "default_root_object" {
Expand Down
2 changes: 1 addition & 1 deletion wrappers/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module "wrapper" {
create = try(each.value.create, var.defaults.create, true)
create_monitoring_subscription = try(each.value.create_monitoring_subscription, var.defaults.create_monitoring_subscription, false)
custom_error_response = try(each.value.custom_error_response, var.defaults.custom_error_response, null)
default_cache_behavior = try(each.value.default_cache_behavior, var.defaults.default_cache_behavior)
default_cache_behavior = try(each.value.default_cache_behavior, var.defaults.default_cache_behavior, null)
default_root_object = try(each.value.default_root_object, var.defaults.default_root_object, null)
enabled = try(each.value.enabled, var.defaults.enabled, true)
http_version = try(each.value.http_version, var.defaults.http_version, "http2")
Expand Down
Loading