Skip to content

Commit aa12287

Browse files
StephenTan-TWnitrocodecloudpossebotkorenyoni
authored
Fix: fix incorrect conditional logic for dynamic blocks iterating on var.ec2_tag_set and var.ec2_tag_filter (#13)
- Swap second and third arguments in ternary operator for `var.ec2_tag_set` and `var.ec2_tag_filter`, which are incorrectly supplying an empty list if their lengths are > 0. - Use `lookup` function in dynamic blocks in order to introduce more robustness. Co-authored-by: nitrocode <[email protected]> Co-authored-by: cloudpossebot <[email protected]> Co-authored-by: Yonatan Koren <[email protected]>
1 parent 8eaf834 commit aa12287

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

main.tf

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -178,26 +178,27 @@ resource "aws_codedeploy_deployment_group" "default" {
178178
# Note that you cannot have both ec_tag_filter and ec2_tag_set vars set!
179179
# See https://docs.aws.amazon.com/cli/latest/reference/deploy/create-deployment-group.html for details
180180
dynamic "ec2_tag_filter" {
181-
for_each = length(var.ec2_tag_filter) > 0 ? [] : var.ec2_tag_filter
181+
for_each = length(var.ec2_tag_filter) > 0 ? var.ec2_tag_filter : []
182+
182183
content {
183-
key = ec2_tag_filter.value["key"]
184-
type = ec2_tag_filter.value["type"]
185-
value = ec2_tag_filter.value["value"]
184+
key = lookup(ec2_tag_filter.value, "key", null)
185+
type = lookup(ec2_tag_filter.value, "type", null)
186+
value = lookup(ec2_tag_filter.value, "value", null)
186187
}
187188
}
188189

189190
# Note that you cannot have both ec_tag_filter and ec2_tag_set vars set!
190191
# See https://docs.aws.amazon.com/cli/latest/reference/deploy/create-deployment-group.html for details
191192
dynamic "ec2_tag_set" {
192-
for_each = length(var.ec2_tag_set) > 0 ? [] : var.ec2_tag_set
193+
for_each = length(var.ec2_tag_set) > 0 ? var.ec2_tag_set : []
193194

194195
content {
195196
dynamic "ec2_tag_filter" {
196197
for_each = ec2_tag_set.value.ec2_tag_filter
197198
content {
198-
key = ec2_tag_filter.value["key"]
199-
type = ec2_tag_filter.value["type"]
200-
value = ec2_tag_filter.value["value"]
199+
key = lookup(ec2_tag_filter.value, "key", null)
200+
type = lookup(ec2_tag_filter.value, "type", null)
201+
value = lookup(ec2_tag_filter.value, "value", null)
201202
}
202203
}
203204
}

0 commit comments

Comments
 (0)