Terraform For each loop on object and pass to child module

I have a AWS s3 lifecycle rule of complex type (object) in my variables.tf file and have assigned it to a variable. Afterwards, I am using for_each loop to iterate over the object and passing this variable from a parent module to a child module where s3 resource is being created where I am stuck and I am not sure if my approach is correct or not. I know that for_each loop only accepts maps and sets but I could not find any resource to convert object to map and I am confused if I should convert object into map in my case.

Parent module: (variables.tf)

variable "lifecycle_rule_60_days" {
 type = object({
  life_id        = string
  prefix_val     = string
  bucket_enabled = bool
  expiration_list = object({
  expiration_days = number
})
})
 default = {
  life_id        = "abc"
  prefix_val     = "test"
  bucket_enabled = true
  expiration_list = {
  expiration_days = 20
    }
  }
}

Parent module: (main.tf)

module "xyz-parent-module" {
 source = "./aws-module/s3-bucket-module"
  for_each        = var.lifecycle_rule_60_days
   lifecycle_id   = each.value["life_id"]
   prefix_value   = each.value["prefix_val"]
   enabled_value  = each.value["bucket_enabled"]
   days_value     = each.value["expiration_days"]
}

Child module - s3-bucket-module: (variables.tf)

 variable "rule_xyz" {
   type = object({
     lifecycle_id      = string
     prefix_value      = string
     enabled_value     = bool
     expiration_days   = object({
       days_value      = number
     })
   })
 
   default = {
     lifecycle_id      = "testing-bucket"
     prefix_value      = "dev"
     enabled_value     = true
     expiration_days   = {
       days_value      = 60
     }
   }
 }

Child module - s3-bucket-module: (main.tf)

resource "aws_s3_bucket" "bucket_a" {
  bucket = "bucket_a"

    for_each  = var.rule_xyz
      id      = each.value["lifecycle_id"]
      prefix  = each.value["prefix_value"]
      enabled = each.value["enabled_value"]
      days    = each.value["days_value"]

}

After terraform plan I get the following errors:

Error: Unsupported argument in module "xyz-parent-module" 
An argument named "lifecycle_id" is not expected here. 
Error: Unsupported argument in module "xyz-parent-module" 
An argument named "prefix_value" is not expected here. 
Error: Unsupported argument in module "xyz-parent-module" 
An argument named "enabled_value" is not expected here 
Error: Unsupported argument in module "xyz-parent-module" 
An argument named "days_value" is not expected here

I am using Terraform v1.0.5 and the errors below are not of any help which I also tried to search but of no luck. I am trying to implement it for the last two days . I would appreciate if someone could please guide me what I am doing wrong.

for_each is used for when you want to create a variable number of resources (similar to count).

From the code you have presented there doesn’t look to be any variability, just a single object which always is populated (due to the default). As a result for_each isn’t something you should use here.

Instead you just need to reference the variable directly.

If I understood correctly, then I should be using like this:

module "xyz-parent-module" {
 source = "./aws-module/s3-bucket-module"
lifecycle_rule =  var.lifecycle_rule_60_days
}

But if I do this then I get the same error e.g.

Error: Unsupported argument in module "xyz-parent-module" 
lifecycle_rule =  var.lifecycle_rule_60_days
An argument named "lifecycle_rule" is not expected here.