Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot add lifecycle rule to expire delete markers #167

Closed
snemetz opened this issue Feb 7, 2023 · 3 comments · Fixed by #202
Closed

Cannot add lifecycle rule to expire delete markers #167

snemetz opened this issue Feb 7, 2023 · 3 comments · Fixed by #202
Labels
enhancement New feature or request

Comments

@snemetz
Copy link

snemetz commented Feb 7, 2023

Found a bug? Maybe our Slack Community can help.

Slack Community

Describe the Bug

Attempting to add a second rule to expire delete markers. But get The given value is not suitable for module.s3_bucket.var.lifecycle_configuration_rules declared at .terraform/modules/s3_bucket/variables.tf:159,1-41: cannot find a │ common base type for all elements.

Lifecycle rules:

locals {
  lifecycle_configuration_rules = [
    {
      enabled = true
      id      = "cleanup"
      abort_incomplete_multipart_upload_days = 1
      filter_and = {
        prefix = "prefix/"
      }
      expiration = {
        days = var.s3_expiration
      }
      noncurrent_version_expiration = {
        newer_noncurrent_versions = var.s3_expiration_noncurrent_versions
        noncurrent_days           = var.s3_expiration_noncurrent_days
      }
      transition                    = null
      noncurrent_version_transition = null
    }
    ,
    {
      enabled = true
      id      = "cleanup-delete-markers"
      expiration = {
        expired_object_delete_marker = true
      }
      abort_incomplete_multipart_upload_days = 1
      filter_and                             = null
      transition                             = null
      noncurrent_version_expiration          = null
      noncurrent_version_transition          = null
    }
  ]
}

The first rule works fine by itself. Error happens when second rule is added

The second rule is one I use all the time. Just first time using this module to create it

Expected Behavior

Both lifecycle rules defined

Steps to Reproduce

  1. Add the lifecycle rules to a S3 bucket definition
  2. Run terraform plan
  3. Receive error
    ╷ │ Error: Invalid value for input variable │ │ on main.tf line 128, in module "s3_bucket": │ 128: lifecycle_configuration_rules = local.lifecycle_configuration_rules │ │ The given value is not suitable for module.s3_bucket.var.lifecycle_configuration_rules declared at .terraform/modules/s3_bucket/variables.tf:159,1-41: cannot find a │ common base type for all elements.

Environment (please complete the following information):

  • Terraform v1.3.7
  • AWS provider v4.53.0
  • Cloudposse s3_bucket module 3.0.0
  • macOS 13.2
@snemetz snemetz added the bug 🐛 An issue with the system label Feb 7, 2023
@Nuru
Copy link
Contributor

Nuru commented May 5, 2023

This is not a bug, this is how Terraform works. All elements of the list must be of the same type. When they are objects, that means they must have all the same fields.

You need to add missing fields. This should work with Terraform 1.0.0 or later:

locals {
  lifecycle_configuration_rules = [
    {
      enabled = true
      id      = "cleanup"
      abort_incomplete_multipart_upload_days = 1
      filter_and = {
        prefix = "prefix/"
      }
      expiration = {
        days = var.s3_expiration
        expired_object_delete_marker = null
      }
      noncurrent_version_expiration = {
        newer_noncurrent_versions = var.s3_expiration_noncurrent_versions
        noncurrent_days           = var.s3_expiration_noncurrent_days
      }
      transition                    = null
      noncurrent_version_transition = null
    }
    ,
    {
      enabled = true
      id      = "cleanup-delete-markers"
      expiration = {
        days = null
        expired_object_delete_marker = true
      }
      abort_incomplete_multipart_upload_days = 1
      filter_and                             = null
      transition                             = null
      noncurrent_version_expiration          = null
      noncurrent_version_transition          = null
    }
  ]
}

@Nuru Nuru added invalid This doesn't seem right and removed bug 🐛 An issue with the system labels May 5, 2023
@snemetz
Copy link
Author

snemetz commented May 6, 2023

That isn't true. Terraform has allowed optional fields for the last couple versions.
While they still need to be of same type, they do not have to have the same fields.
I've been using optional fields heavily lately.

But this is more of an improvement (feature request) than a bug, just due to it was probably written before terraform 1.3

@Nuru
Copy link
Contributor

Nuru commented May 6, 2023

The lifecycle_configuration_rules is not declared to have any optional fields. Therefore, the input is incorrect, as the error message stated, and the solution is to fix the input. That means it is not a bug.

I will leave this open as a feature request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
2 participants