-
-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Closed
Description
Description
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:
for_each = try(flatten([rule.value.expiration]), [])
Since there is no compact
, the flatten
call will return [null]
which is a valid list with one value.
In my case the null
values are coming from a variable with optional
fields, so it would be best if the module could handle null values correctly.
- β I have searched the open/closed issues and my issue is not listed.
Versions
-
Module version [Required]: 4.5.0
-
Terraform version: 1.7.5
- Provider version(s): 5.84.0
Reproduction Code [Required]
module "s3_bucket" {
source = "terraform-aws-modules/s3-bucket/aws"
bucket = "tftest-foobar-bucket"
lifecycle_rule = [
{
id = "foobar"
enabled = true
expiration = null
transition = null
noncurrent_version_expiration = null
noncurrent_version_transition = null
filter = {
tags = null
}
}
]
}
Steps to reproduce the behavior:
- run
terraform plan
Expected behavior
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.
fabianopimentel, CaioAugustoo, ebarros29, vitornp, FleischerT and 12 moreleoalves100, wqueiroz7, CaioAugustoo and Mario-Valenteleoalves100, wqueiroz7, CaioAugustoo and Mario-Valenteleoalves100, bentorafael51, wqueiroz7, CaioAugustoo and Mario-Valente
Metadata
Metadata
Assignees
Labels
No labels