terraform-aws-modules / terraform-aws-s3-bucket

Terraform module to create AWS S3 resources 🇺🇦

Home Page:https://registry.terraform.io/modules/terraform-aws-modules/s3-bucket/aws

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Inappropriate value for attribute "days": a number is required

bientavu opened this issue · comments

Description

Weirdly I have an error saying the type of attribute "days" should be a number. But it is a number in my code... or maybe I'm missing something...

Versions

  • Module version: v3.14.0

  • Terraform version: v1.5.7

  • Provider version(s): v5.17.0

Reproduction Code [Required]

Steps to reproduce the behavior:

main.tf

module "s3_bucket_alb_logs" {
  for_each = var.s3_log_bucket_settings_and_rules
  source   = "terraform-aws-modules/s3-bucket/aws"
  version  = "v3.14.0"

  bucket = format("%s-%s-access-logs", var.Project, each.key)
  acl    = "log-delivery-write"
  lifecycle_rule = [
    {
      enabled = each.value.lifecycle_rules.enable_lifecycle_configuration
      id      = format("%s-public-alb-access-logs-lifecycle-rule", var.Project)

      abort_incomplete_multipart_upload_days = 1
      filter_and                             = null
      expiration = {
        days = each.value.lifecycle_rules.expiration_days
      }
      transition = [
        {
          days          = each.value.lifecycle_rules.first_transition_days
          storage_class = each.value.lifecycle_rules.second_transition_days
        },
        {
          days          = each.value.lifecycle_rules.first_transition_class_type
          storage_class = each.value.lifecycle_rules.second_transition_class_type
        }
      ]
    }
  ]

  # Allow deletion of non-empty bucket
  force_destroy = each.value.force_destroy

  control_object_ownership = each.value.control_object_ownership
  object_ownership         = each.value.object_ownership

  attach_elb_log_delivery_policy = true # Required for ALB logs
  attach_lb_log_delivery_policy  = true # Required for ALB/NLB logs

  access_log_delivery_policy_source_accounts = each.value.access_log_delivery_policy_source_accounts
}

variables.tf

variable "s3_log_bucket_settings_and_rules" {
  description = "All settings and rules for S3 Log Bucket creation"
  type = map(object({
    lifecycle_rules = object({
      enable_lifecycle_configuration = bool
      expiration_days                = number
      first_transition_days          = number
      first_transition_class_type    = string
      second_transition_days         = number
      second_transition_class_type   = string
    })
    force_destroy                              = bool
    control_object_ownership                   = bool
    object_ownership                           = string
    access_log_delivery_policy_source_accounts = list(string)
  }))
}

terraform.tfvars

s3_log_bucket_settings_and_rules = {
   private-alb = {
    lifecycle_rules = {
      enable_lifecycle_configuration = true
      expiration_days                = 365
      first_transition_days          = 30
      second_transition_days         = 90
      first_transition_class_type    = "STANDARD_IA"
      second_transition_class_type   = "GLACIER"
    }
    force_destroy            = true
    control_object_ownership = true
    ....

As you can see my variable is correctly setup with "expiration_days" as a number and I put a number inside my .tfvars. Am I missing something ?

Expected behavior

tf plan goes smoothly and plan a lifecycle policy where my expiration days is correctly setup to 365

Actual behavior

tf plan erorr says "Inappropriate value for attribute "days": a number is required"

Terminal Output Screenshot(s)

Additional context

@bientavu you put wrong values on days and storage_class. Please change your code from this

        {
          days          = each.value.lifecycle_rules.first_transition_days
          storage_class = each.value.lifecycle_rules.second_transition_days
        },
        {
          days          = each.value.lifecycle_rules.first_transition_class_type
          storage_class = each.value.lifecycle_rules.second_transition_class_type
        }

to this

        {
          days          = each.value.lifecycle_rules.first_transition_days
          storage_class = each.value.lifecycle_rules.first_transition_class_type
        },
        {
          days          = each.value.lifecycle_rules.second_transition_days
          storage_class = each.value.lifecycle_rules.second_transition_class_type
        }

@abaidgulshan, oh my bad I should have seen that... thanks a lot!

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.