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

unable to use dynamic block with lifecycle rule when using the s3 module

shettypriy opened this issue · comments

Description

Unable to use the dynamic block for lifecycle rule .

  • ✋ I have searched the open/closed issues and my issue is not listed.

⚠️ Note

Before you submit an issue, please perform the following first:

  1. Remove the local .terraform directory (! ONLY if state is stored remotely, which hopefully you are following that best practice!): rm -rf .terraform/
  2. Re-initialize the project root to pull down modules: terraform init
  3. Re-attempt your terraform plan or apply and check if the issue still persists

Versions

  • Module version [Required]:

  • Terraform version:

  • Provider version(s):

Reproduction Code [Required]

module "test_bucket_for_dynamic" {
  source  = "terraform-aws-modules/s3-bucket/aws"
  version = "3.6.0"
  bucket = "test_bucket_for_dynamic"

  dynamic "lifecycle_rule" {
    for_each = [var.lifecycle_rule_30_day]
    content {

      abort_incomplete_multipart_upload_days = lookup(lifecycle_rule.value, "abort_incomplete_multipart_upload_days", null)
      enabled                                = lifecycle_rule.value.enabled
      id                                     = lookup(lifecycle_rule.value, "id", null)
      prefix                                 = lookup(lifecycle_rule.value, "prefix", null)
      tags                                   = lookup(lifecycle_rule.value, "tags", null)

      dynamic "expiration" {
        for_each = lookup(lifecycle_rule.value, "expiration", [])
        content {
          date                         = lookup(expiration.value, "date", null)
          days                         = lookup(expiration.value, "days", null)
          expired_object_delete_marker = lookup(expiration.value, "expired_object_delete_marker", null)
        }
      }

      dynamic "noncurrent_version_expiration" {
        for_each = lookup(lifecycle_rule.value, "noncurrent_version_expiration", [])
        content {
          days = lookup(noncurrent_version_expiration.value, "days", null)
        }
      }

      dynamic "noncurrent_version_transition" {
        for_each = lookup(lifecycle_rule.value, "noncurrent_version_transition", [])
        content {
          days          = lookup(noncurrent_version_transition.value, "days", null)
          storage_class = noncurrent_version_transition.value.storage_class
        }
      }

      dynamic "transition" {
        for_each = lookup(lifecycle_rule.value, "transition", [])
        content {
          date          = lookup(transition.value, "date", null)
          days          = lookup(transition.value, "days", null)
          storage_class = transition.value.storage_class
        }
      }
    }
  }
}

variable "lifecycle_rule_30_day" {
  default = {
    id      = "lifecycle_rule_30_day"
    enabled = true
    expiration = [
      {
        days = 30
      },
    ]
  }
}

Steps to reproduce the behavior:

  1. terraform init2.
  2. terraform plan -out plan.out -target module.test_bucket_for_dynamic
    Following is the error got for the plan

Error: Unsupported block type

│ on s3_bucket.tf line 9, in module "test_bucket_for_dynamic":
│ 9: dynamic "lifecycle_rule" {

│ Blocks of type "dynamic" are not expected here.

Could you please let me know if dynamic block can be used for lifecycle rule.

Please check the official Terraform documentation. It is not possible to do what you are trying to do.

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.