@@ -262,7 +262,7 @@ resource "aws_s3_bucket_lifecycle_configuration" "this" {
262
262
263
263
# Max 1 block - expiration
264
264
dynamic "expiration" {
265
- for_each = try (flatten ([rule . value . expiration ]), [])
265
+ for_each = try (compact ( flatten ([rule . value . expiration ]) ), [])
266
266
267
267
content {
268
268
date = try (expiration. value . date , null )
@@ -273,7 +273,7 @@ resource "aws_s3_bucket_lifecycle_configuration" "this" {
273
273
274
274
# Several blocks - transition
275
275
dynamic "transition" {
276
- for_each = try (flatten ([rule . value . transition ]), [])
276
+ for_each = try (compact ( flatten ([rule . value . transition ]) ), [])
277
277
278
278
content {
279
279
date = try (transition. value . date , null )
@@ -284,7 +284,7 @@ resource "aws_s3_bucket_lifecycle_configuration" "this" {
284
284
285
285
# Max 1 block - noncurrent_version_expiration
286
286
dynamic "noncurrent_version_expiration" {
287
- for_each = try (flatten ([rule . value . noncurrent_version_expiration ]), [])
287
+ for_each = try (compact ( flatten ([rule . value . noncurrent_version_expiration ]) ), [])
288
288
289
289
content {
290
290
newer_noncurrent_versions = try (noncurrent_version_expiration. value . newer_noncurrent_versions , null )
@@ -294,7 +294,7 @@ resource "aws_s3_bucket_lifecycle_configuration" "this" {
294
294
295
295
# Several blocks - noncurrent_version_transition
296
296
dynamic "noncurrent_version_transition" {
297
- for_each = try (flatten ([rule . value . noncurrent_version_transition ]), [])
297
+ for_each = try (compact ( flatten ([rule . value . noncurrent_version_transition ]) ), [])
298
298
299
299
content {
300
300
newer_noncurrent_versions = try (noncurrent_version_transition. value . newer_noncurrent_versions , null )
@@ -305,7 +305,7 @@ resource "aws_s3_bucket_lifecycle_configuration" "this" {
305
305
306
306
# Max 1 block - filter - without any key arguments or tags
307
307
dynamic "filter" {
308
- for_each = length (try (flatten ([rule . value . filter ]), [])) == 0 ? [true ] : []
308
+ for_each = one (try (flatten ([rule . value . filter ]), [])) == null ? [true ] : []
309
309
310
310
content {
311
311
# prefix = ""
@@ -314,15 +314,15 @@ resource "aws_s3_bucket_lifecycle_configuration" "this" {
314
314
315
315
# Max 1 block - filter - with one key argument or a single tag
316
316
dynamic "filter" {
317
- for_each = [for v in try (flatten ([rule . value . filter ]), []) : v if max (length (keys (v)), length ( try (rule. value . filter . tags , rule. value . filter . tag , []) )) == 1 ]
317
+ for_each = [for v in try (rule . value . filter == null ? [] : flatten ([rule . value . filter ]), []) : v if max (length (keys (v)), try (length ( rule. value . filter . tags ), length ( rule. value . filter . tag ), 0 )) == 1 ]
318
318
319
319
content {
320
320
object_size_greater_than = try (filter. value . object_size_greater_than , null )
321
321
object_size_less_than = try (filter. value . object_size_less_than , null )
322
322
prefix = try (filter. value . prefix , null )
323
323
324
324
dynamic "tag" {
325
- for_each = try (filter. value . tags , filter. value . tag , [])
325
+ for_each = try (coalesce ( filter. value . tags , {}), coalesce ( filter. value . tag , {}) , [])
326
326
327
327
content {
328
328
key = tag. key
@@ -334,7 +334,7 @@ resource "aws_s3_bucket_lifecycle_configuration" "this" {
334
334
335
335
# Max 1 block - filter - with more than one key arguments or multiple tags
336
336
dynamic "filter" {
337
- for_each = [for v in try (flatten ([rule . value . filter ]), []) : v if max (length (keys (v)), length ( try (rule. value . filter . tags , rule. value . filter . tag , []) )) > 1 ]
337
+ for_each = [for v in try (rule . value . filter == null ? [] : flatten ([rule . value . filter ]), []) : v if max (length (keys (v)), try (length ( rule. value . filter . tags ), length ( rule. value . filter . tag ), 0 )) > 1 ]
338
338
339
339
content {
340
340
and {
0 commit comments