diff --git a/main.tf b/main.tf index 8e15a1b..de23f56 100644 --- a/main.tf +++ b/main.tf @@ -92,7 +92,7 @@ resource "aws_lb_listener" "this" { certificate_arn = try(each.value.certificate_arn, null) dynamic "default_action" { - for_each = try([each.value.authenticate_cognito], []) + for_each = can(coalesce(each.value.authenticate_cognito)) ? [each.value.authenticate_cognito] : [] content { authenticate_cognito { @@ -112,7 +112,7 @@ resource "aws_lb_listener" "this" { } dynamic "default_action" { - for_each = try([each.value.authenticate_oidc], []) + for_each = can(coalesce(each.value.authentication_oidc)) ? [each.value.authenticate_oidc] : [] content { authenticate_oidc { @@ -135,7 +135,7 @@ resource "aws_lb_listener" "this" { } dynamic "default_action" { - for_each = try([each.value.fixed_response], []) + for_each = can(coalesce(each.value.fixed_response)) ? [each.value.fixed_response] : [] content { fixed_response { @@ -150,7 +150,7 @@ resource "aws_lb_listener" "this" { } dynamic "default_action" { - for_each = try([each.value.forward], []) + for_each = can(coalesce(each.value.forward)) ? [each.value.forward] : [] content { order = try(default_action.value.order, null) @@ -160,7 +160,7 @@ resource "aws_lb_listener" "this" { } dynamic "default_action" { - for_each = try([each.value.weighted_forward], []) + for_each = can(coalesce(each.value.weighted_forward)) ? [each.value.weighted_forward] : [] content { forward { @@ -189,7 +189,7 @@ resource "aws_lb_listener" "this" { } dynamic "default_action" { - for_each = try([each.value.redirect], []) + for_each = can(coalesce(each.value.redirect)) ? [each.value.redirect] : [] content { order = try(default_action.value.order, null) @@ -208,7 +208,7 @@ resource "aws_lb_listener" "this" { } dynamic "mutual_authentication" { - for_each = try([each.value.mutual_authentication], []) + for_each = can(coalesce(each.value.mutual_authentication)) ? [each.value.mutual_authentication] : [] content { mode = mutual_authentication.value.mode trust_store_arn = try(mutual_authentication.value.trust_store_arn, null) @@ -493,7 +493,7 @@ resource "aws_lb_target_group" "this" { deregistration_delay = try(each.value.deregistration_delay, null) dynamic "health_check" { - for_each = try([each.value.health_check], []) + for_each = can(coalesce(each.value.health_check)) ? [each.value.health_check] : [] content { enabled = try(health_check.value.enabled, null) @@ -523,7 +523,7 @@ resource "aws_lb_target_group" "this" { slow_start = try(each.value.slow_start, null) dynamic "stickiness" { - for_each = try([each.value.stickiness], []) + for_each = can(coalesce(each.value.stickiness)) ? [each.value.stickiness] : [] content { cookie_duration = try(stickiness.value.cookie_duration, null) @@ -534,7 +534,7 @@ resource "aws_lb_target_group" "this" { } dynamic "target_failover" { - for_each = try(each.value.target_failover, []) + for_each = can(coalesce(each.value.target_failover)) ? each.value.target_failover : [] content { on_deregistration = target_failover.value.on_deregistration @@ -543,12 +543,11 @@ resource "aws_lb_target_group" "this" { } dynamic "target_group_health" { - for_each = try([each.value.target_group_health], []) + for_each = can(coalesce(each.value.target_group_health)) ? [each.value.target_group_health] : [] content { - dynamic "dns_failover" { - for_each = try([target_group_health.value.dns_failover], []) + for_each = can(coalesce(target_group_health.value.dns_failover)) ? [target_group_health.value.dns_failover] : [] content { minimum_healthy_targets_count = try(dns_failover.value.minimum_healthy_targets_count, null) @@ -557,7 +556,7 @@ resource "aws_lb_target_group" "this" { } dynamic "unhealthy_state_routing" { - for_each = try([target_group_health.value.unhealthy_state_routing], []) + for_each = can(coalesce(target_group_health.value.unhealthy_state_routing)) ? [target_group_health.value.unhealthy_state_routing] : [] content { minimum_healthy_targets_count = try(unhealthy_state_routing.value.minimum_healthy_targets_count, null) @@ -568,7 +567,7 @@ resource "aws_lb_target_group" "this" { } dynamic "target_health_state" { - for_each = try([each.value.target_health_state], []) + for_each = can(coalesce(each.value.target_health_state)) ? [each.value.target_health_state] : [] content { enable_unhealthy_connection_termination = try(target_health_state.value.enable_unhealthy_connection_termination, true) unhealthy_draining_interval = try(target_health_state.value.unhealthy_draining_interval, null)