Skip to content

Commit

Permalink
[main.tf] Updated conditions with included cache_policy_id variable (#…
Browse files Browse the repository at this point in the history
…210)

* [main.tf] Updated conditions with included cache_policy_id variable

Co-authored-by: cloudpossebot <[email protected]>
Co-authored-by: Yonatan Koren <[email protected]>
  • Loading branch information
3 people authored Jan 27, 2022
1 parent 076c5bf commit 4f18fb1
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down

0 comments on commit 4f18fb1

Please sign in to comment.