You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When trying to use a lifecycle rule while passing null values for transition, noncurrent_version_transition and filter inputs, Terraform throws a "null value has no attributes" error. I believe this is due to how the for_each blocks are implemented:
The plan to create a bucket with an empty lifecycle rule.
Actual behavior
Error:
│ Error: Attempt to get attribute from null value
│
│ on .terraform/modules/s3_bucket/main.tf line 281, in resource "aws_s3_bucket_lifecycle_configuration" "this":
│ 281: storage_class = transition.value.storage_class
│ ├────────────────
│ │ transition.value is null
│
│ This value is null, so it does not have any attributes.
╵
╷
│ Error: Attempt to get attribute from null value
│
│ on .terraform/modules/s3_bucket/main.tf line 302, in resource "aws_s3_bucket_lifecycle_configuration" "this":
│ 302: storage_class = noncurrent_version_transition.value.storage_class
│ ├────────────────
│ │ noncurrent_version_transition.value is null
│
│ This value is null, so it does not have any attributes.
╵
╷
│ Error: Invalid function argument
│
│ on .terraform/modules/s3_bucket/main.tf line 317, in resource "aws_s3_bucket_lifecycle_configuration" "this":
│ 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]
│
│ Invalid value for "inputMap" parameter: argument must not be null.
╵
╷
│ Error: Invalid function argument
│
│ on .terraform/modules/s3_bucket/main.tf line 337, in resource "aws_s3_bucket_lifecycle_configuration" "this":
│ 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]
│
│ Invalid value for "inputMap" parameter: argument must not be null.
The text was updated successfully, but these errors were encountered:
Description
When trying to use a lifecycle rule while passing null values for
transition
,noncurrent_version_transition
andfilter
inputs, Terraform throws a "null value has no attributes" error. I believe this is due to how thefor_each
blocks are implemented:Since there is no
compact
, theflatten
call will return[null]
which is a valid list with one value.In my case the
null
values are coming from a variable withoptional
fields, so it would be best if the module could handle null values correctly.Versions
Module version [Required]: 4.5.0
Terraform version: 1.7.5
Reproduction Code [Required]
Steps to reproduce the behavior:
terraform plan
Expected behavior
The plan to create a bucket with an empty lifecycle rule.
Actual behavior
Error:
The text was updated successfully, but these errors were encountered: