From 441f26af6867ba33f6eeca0d66c53b53c0f41f14 Mon Sep 17 00:00:00 2001 From: John Noss Date: Wed, 24 Mar 2021 09:37:59 -0400 Subject: [PATCH 1/3] feat: update to 0.13: add required_providers --- versions.tf | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 versions.tf diff --git a/versions.tf b/versions.tf new file mode 100644 index 0000000..6a9fbaa --- /dev/null +++ b/versions.tf @@ -0,0 +1,9 @@ +terraform { + required_providers { + aws = { + source = "hashicorp/aws" + version = "~> 3.26" + } + } + required_version = "~> 0.13.6" +} From 2d491c345dfe8b45fa55e8b5102eb0e94aa53208 Mon Sep 17 00:00:00 2001 From: John Noss Date: Wed, 24 Mar 2021 09:48:05 -0400 Subject: [PATCH 2/3] fix: allow previous behavior to continue if not using lambda or custom header --- main.tf | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/main.tf b/main.tf index d1c501c..8d88844 100644 --- a/main.tf +++ b/main.tf @@ -8,13 +8,12 @@ resource "aws_cloudfront_distribution" "cf_distribution" { ## Origin's # S3 block dynamic "origin" { - for_each = [for o in var.s3_origin_configs : { + for_each = [for o in var.s3_origin_configs : merge({ domain_name = o.domain_name origin_id = o.origin_id origin_path = o.origin_path - custom_headers = o.custom_headers origin_access_identity = o.origin_access_identity - }] + }, try({custom_headers = o.custom_headers}, {}))] content { domain_name = origin.value.domain_name origin_id = origin.value.origin_id @@ -102,7 +101,7 @@ resource "aws_cloudfront_distribution" "cf_distribution" { event_type = i.event_type lambda_arn = i.lambda_arn include_body = i.include_body - }] + } if lookup(var.default_cache_behavior, "lambda_association", "") != ""] content { event_type = lambda_function_association.value.event_type From ab67661b7720f929ade2643e2405a6f67a656faa Mon Sep 17 00:00:00 2001 From: John Noss Date: Wed, 24 Mar 2021 09:53:12 -0400 Subject: [PATCH 3/3] fix: more places to preserve old behavior --- main.tf | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/main.tf b/main.tf index 8d88844..23868a5 100644 --- a/main.tf +++ b/main.tf @@ -20,10 +20,10 @@ resource "aws_cloudfront_distribution" "cf_distribution" { origin_path = origin.value.origin_path dynamic "custom_header" { - for_each = [for h in origin.value.custom_headers : { + for_each = try([for h in origin.value.custom_headers : { name = h.name value = h.value - }] + }], []) content { name = custom_header.value.name @@ -97,11 +97,11 @@ resource "aws_cloudfront_distribution" "cf_distribution" { target_origin_id = var.default_cache_behavior["target_origin_id"] dynamic "lambda_function_association" { - for_each = [for i in var.default_cache_behavior["lambda_association"] : { + for_each = try([for i in var.default_cache_behavior["lambda_association"] : { event_type = i.event_type lambda_arn = i.lambda_arn include_body = i.include_body - } if lookup(var.default_cache_behavior, "lambda_association", "") != ""] + }], []) content { event_type = lambda_function_association.value.event_type