From 4f18fb1c0e8c462dfcbd5c0c993f1f5645a7aa8f Mon Sep 17 00:00:00 2001 From: E Bobo Date: Thu, 27 Jan 2022 21:43:34 +0300 Subject: [PATCH] [main.tf] Updated conditions with included cache_policy_id variable (#210) * [main.tf] Updated conditions with included cache_policy_id variable Co-authored-by: cloudpossebot <11232728+cloudpossebot@users.noreply.github.com> Co-authored-by: Yonatan Koren --- main.tf | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/main.tf b/main.tf index e260aaa5..f5ace3bd 100644 --- a/main.tf +++ b/main.tf @@ -482,7 +482,7 @@ resource "aws_cloudfront_distribution" "default" { dynamic "forwarded_values" { # If a cache policy or origin request policy is specified, # we cannot include a `forwarded_values` block at all in the API request. - for_each = (var.cache_policy_id == null && var.origin_request_policy_id == null) ? [true] : [] + for_each = (var.cache_policy_id != null || var.origin_request_policy_id != null) ? [] : [true] content { query_string = var.forward_query_string query_string_cache_keys = var.query_string_cache_keys @@ -495,9 +495,9 @@ resource "aws_cloudfront_distribution" "default" { } viewer_protocol_policy = var.viewer_protocol_policy - default_ttl = var.default_ttl - min_ttl = var.min_ttl - max_ttl = var.max_ttl + default_ttl = (var.cache_policy_id != null || var.origin_request_policy_id != null) ? 0 : var.default_ttl + min_ttl = (var.cache_policy_id != null || var.origin_request_policy_id != null) ? 0 : var.min_ttl + max_ttl = (var.cache_policy_id != null || var.origin_request_policy_id != null) ? 0 : var.max_ttl realtime_log_config_arn = var.realtime_log_config_arn @@ -537,7 +537,7 @@ resource "aws_cloudfront_distribution" "default" { dynamic "forwarded_values" { # If a cache policy or origin request policy is specified, we cannot include a `forwarded_values` block at all in the API request - for_each = ordered_cache_behavior.value.cache_policy_id == null || ordered_cache_behavior.value.origin_request_policy_id == null ? [true] : [] + for_each = (ordered_cache_behavior.value.cache_policy_id != null || ordered_cache_behavior.value.origin_request_policy_id != null) ? [] : [true] content { query_string = ordered_cache_behavior.value.forward_query_string headers = ordered_cache_behavior.value.forward_header_values @@ -550,13 +550,13 @@ resource "aws_cloudfront_distribution" "default" { } viewer_protocol_policy = ordered_cache_behavior.value.viewer_protocol_policy - default_ttl = ordered_cache_behavior.value.default_ttl - min_ttl = ordered_cache_behavior.value.min_ttl - max_ttl = ordered_cache_behavior.value.max_ttl + default_ttl = (ordered_cache_behavior.value.cache_policy_id != null || ordered_cache_behavior.value.origin_request_policy_id != null) ? 0 : ordered_cache_behavior.value.default_ttl + min_ttl = (ordered_cache_behavior.value.cache_policy_id != null || ordered_cache_behavior.value.origin_request_policy_id != null) ? 0 : ordered_cache_behavior.value.min_ttl + max_ttl = (ordered_cache_behavior.value.cache_policy_id != null || ordered_cache_behavior.value.origin_request_policy_id != null) ? 0 : ordered_cache_behavior.value.max_ttl response_headers_policy_id = ordered_cache_behavior.value.response_headers_policy_id dynamic "lambda_function_association" { - for_each = ordered_cache_behavior.value.lambda_function_association + for_each = try(ordered_cache_behavior.value.lambda_function_association, []) content { event_type = lambda_function_association.value.event_type include_body = lookup(lambda_function_association.value, "include_body", null) @@ -565,7 +565,7 @@ resource "aws_cloudfront_distribution" "default" { } dynamic "function_association" { - for_each = lookup(ordered_cache_behavior.value, "function_association", []) + for_each = try(ordered_cache_behavior.value.function_association, []) content { event_type = function_association.value.event_type function_arn = function_association.value.function_arn