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

Ressource aws_s3_bucket_lifecycle_configuration > object_size_greater_than doesn’t work when used at Filter level #23575

Closed
flibustier opened this issue Mar 8, 2022 · 3 comments · Fixed by #23441
Labels
bug Addresses a defect in current functionality. service/s3 Issues and PRs that pertain to the s3 service.

Comments

@flibustier
Copy link

flibustier commented Mar 8, 2022

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform CLI and Terraform AWS Provider Version

Terraform 0.14 but reproduced with 0.15 and 1.0
AWS provider 4.4.0 and 4.3.0

Affected Resource(s)

Terraform Configuration Files

This code doesn’t update the real infrastructure, it keeps planning the same change over and over

resource "aws_s3_bucket_lifecycle_configuration" "my_bucket_lifecycles" {
  bucket = aws_s3_bucket.my_bucket.id

  rule {
    status = "Enabled"
    id     = "to-intelligent-tiering"

    filter {
      object_size_greater_than = 5242880
    }

    transition {
      days          = 1
      storage_class = "INTELLIGENT_TIERING"
    }
  }

Debug Output

The output produced

  ~ resource "aws_s3_bucket_lifecycle_configuration" "my_bucket_lifecycles" {
        id     = "my-bucket"
        # (1 unchanged attribute hidden)

      ~ rule {
            id     = "to-intelligent-tiering"
            # (1 unchanged attribute hidden)

          ~ filter {
              + object_size_greater_than = "5242880"
            }

            # (1 unchanged block hidden)
        }
        # (3 unchanged blocks hidden)
    }

The output stay the same when applying multiple times (as it doesn’t change the real infrastructure)

Panic Output

If I manually modify the corresponding field in the AWS console (I put 2MB of object size minimal), I got the following panic when terraform is planning the changes :

Error: error setting rule: rule.0.filter.0.object_size_greater_than: '' expected type 'string', got unconvertible type 'int', value: '2097152'

Quick fix

It’s possible to avoid this using the and clause :

filter {
      and {
        object_size_greater_than = 5242880
      }
}

It produced a working output (we can observe that the int type is here, instead of string in the faulty case)

  ~ resource "aws_s3_bucket_lifecycle_configuration" "my_bucket_lifecycles" {
        id     = "my-bucket"
        # (1 unchanged attribute hidden)

      ~ rule {
            id     = "to-intelligent-tiering"
            # (1 unchanged attribute hidden)

          ~ filter {
              + and {
                  + object_size_greater_than = 5242880
                }
            }

            # (1 unchanged block hidden)
        }
        # (3 unchanged blocks hidden)
    }

And the real infrastructure is changed 🎉

References

I guess this code seems incriminated :

@github-actions github-actions bot added needs-triage Waiting for first response or review from a maintainer. service/s3 Issues and PRs that pertain to the s3 service. labels Mar 8, 2022
@anGie44 anGie44 added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Mar 8, 2022
@anGie44
Copy link
Contributor

anGie44 commented Mar 8, 2022

Hi @flibustier , thank you for raising this issue. Just wanted to quickly note that I think this PR (#23441) should fix this as it addresses the panic your are seeing. We weren't handling the data conversion (int -> string) in both rule.filter.object_size_greater_than and rule.filter.object_size_less_than

@flibustier
Copy link
Author

Awesome ! I will track the progress of the PR then :) Thanks !!

@github-actions
Copy link

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 10, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/s3 Issues and PRs that pertain to the s3 service.
Projects
None yet
2 participants