Skip to content

Commit 1571102

Browse files
committed
fix(sub-modules): incorrect assumption for optional objects to not exist in for_each condition
1 parent 6346613 commit 1571102

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

modules/acm/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ resource "aws_acm_certificate" "amazon_issued" {
1111
key_algorithm = each.value.key_algorithm
1212

1313
dynamic "options" {
14-
for_each = (try(each.value.options, null) != null && length(try(each.value.options, {})) > 0) ? [1] : []
14+
for_each = length(each.value.options != null ? each.value.options : {}) > 0 ? [1] : []
1515

1616
content {
1717
certificate_transparency_logging_preference = each.value.options.certificate_transparency_logging_preference
1818
}
1919
}
2020

2121
dynamic "validation_option" {
22-
for_each = (try(each.value.validation_option, null) != null && length(try(each.value.validation_option, {})) > 0) ? [1] : []
22+
for_each = length(each.value.validation_option != null ? each.value.validation_option : {}) > 0 ? [1] : []
2323

2424
content {
2525
domain_name = each.value.validation_option.domain_name

modules/alb/main.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ resource "aws_lb_target_group" "this" {
3131
target_type = each.value.target_type
3232

3333
dynamic "health_check" {
34-
for_each = (try(each.value.health_check, null) != null && length(try(each.value.health_check, {})) > 0) ? [1] : []
34+
for_each = length(each.value.health_check != null ? each.value.health_check : {}) > 0 ? [1] : []
3535

3636
content {
3737
enabled = try(each.value.health_check.enabled, null)
@@ -65,7 +65,7 @@ resource "aws_lb_listener" "this" {
6565
ssl_policy = element(var.listeners, count.index).ssl_policy
6666

6767
dynamic "mutual_authentication" {
68-
for_each = (try(element(var.listeners, count.index).mutual_authentication, null) != null && length(try(element(var.listeners, count.index).mutual_authentication, {})) > 0) ? [1] : []
68+
for_each = length(element(var.listeners, count.index).mutual_authentication != null ? element(var.listeners, count.index).mutual_authentication : {}) > 0 ? [1] : []
6969

7070
content {
7171
mode = element(var.listeners, count.index).mutual_authentication.mode
@@ -84,7 +84,7 @@ resource "aws_lb_listener" "this" {
8484
order = default_action.value.order
8585

8686
dynamic "authenticate_cognito" {
87-
for_each = (try(default_action.value.authenticate_cognito, null) != null && length(try(default_action.value.authenticate_cognito, {})) > 0) ? [1] : []
87+
for_each = length(default_action.value.authenticate_cognito != null ? default_action.value.authenticate_cognito : {}) > 0 ? [1] : []
8888

8989
content {
9090
user_pool_arn = default_action.value.authenticate_cognito.user_pool_arn
@@ -99,7 +99,7 @@ resource "aws_lb_listener" "this" {
9999
}
100100

101101
dynamic "authenticate_oidc" {
102-
for_each = (try(default_action.value.authenticate_oidc, null) != null && length(try(default_action.value.authenticate_oidc, {})) > 0) ? [1] : []
102+
for_each = length(default_action.value.authenticate_oidc != null ? default_action.value.authenticate_oidc : {}) > 0 ? [1] : []
103103

104104
content {
105105
authorization_endpoint = default_action.value.authenticate_oidc.authorization_endpoint
@@ -117,7 +117,7 @@ resource "aws_lb_listener" "this" {
117117
}
118118

119119
dynamic "fixed_response" {
120-
for_each = (try(default_action.value.fixed_response, null) != null && length(try(default_action.value.fixed_response, {})) > 0) ? [1] : []
120+
for_each = length(default_action.value.fixed_response != null ? default_action.value.fixed_response : {}) > 0 ? [1] : []
121121

122122
content {
123123
content_type = default_action.value.fixed_response.content_type
@@ -127,7 +127,7 @@ resource "aws_lb_listener" "this" {
127127
}
128128

129129
dynamic "forward" {
130-
for_each = (try(default_action.value.forward, null) != null && length(try(default_action.value.forward, {})) > 0) ? [1] : []
130+
for_each = length(default_action.value.forward != null ? default_action.value.forward : {}) > 0 ? [1] : []
131131

132132
content {
133133
dynamic "target_group" {
@@ -141,7 +141,7 @@ resource "aws_lb_listener" "this" {
141141
}
142142

143143
dynamic "stickiness" {
144-
for_each = (try(default_action.value.forward.stickiness, null) != null && length(try(default_action.value.forward.stickiness, {})) > 0) ? [1] : []
144+
for_each = length(default_action.value.forward.stickiness != null ? default_action.value.forward.stickiness : {}) > 0 ? [1] : []
145145

146146
content {
147147
duration = default_action.value.forward.stickiness.duration
@@ -152,7 +152,7 @@ resource "aws_lb_listener" "this" {
152152
}
153153

154154
dynamic "redirect" {
155-
for_each = (try(default_action.value.redirect, null) != null && length(try(default_action.value.redirect, {})) > 0) ? [1] : []
155+
for_each = length(default_action.value.redirect != null ? default_action.value.redirect : {}) > 0 ? [1] : []
156156

157157
content {
158158
status_code = default_action.value.redirect.status_code

modules/capacity-provider/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ resource "aws_ecs_capacity_provider" "this" {
1111
auto_scaling_group_arn = coalesce(each.value.auto_scaling_group_arn, var.default_auto_scaling_group_arn)
1212

1313
dynamic "managed_scaling" {
14-
for_each = (try(each.value.managed_scaling, null) != null && length(try(each.value.managed_scaling, {})) > 0) ? [1] : []
14+
for_each = length(each.value.managed_scaling != null ? each.value.managed_scaling : {}) > 0 ? [1] : []
1515

1616
content {
1717
instance_warmup_period = each.value.managed_scaling.instance_warmup_period

0 commit comments

Comments
 (0)