Skip to content

[Bug]: aws_s3_bucket_lifecycle_configuration inserting undeclared values that are "known after apply" since 5.86.0 #41537

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

Closed
nwsparks opened this issue Feb 24, 2025 · 6 comments · Fixed by #42036
Assignees
Labels
bug Addresses a defect in current functionality. service/s3 Issues and PRs that pertain to the s3 service.
Milestone

Comments

@nwsparks
Copy link
Contributor

nwsparks commented Feb 24, 2025

Terraform Core Version

1.10.5

AWS Provider Version

5.88.0

Affected Resource(s)

  • aws_s3_bucket_lifecycle_configuration

Expected Behavior

It seems that since aws provider 5.86.0 the plans are inserting values of known after apply for undeclared properties (days, prefix, etc). this has caused all of our tests via terraform test to fail as it can no longer compute comparisons when searching within the lifecycle rules. example error:

│ Condition expression could not be evaluated at this time. This means you have executed a `run` block with `command = plan` and one of the values your condition
│ depended on is not known until after the plan has been applied. Either remove this value from your condition, or execute an `apply` command from this `run` block.
here is an example working output of a plan from provider version 5.85.0 - please expand
# aws_s3_bucket_lifecycle_configuration.lifecycle will be created
+ resource "aws_s3_bucket_lifecycle_configuration" "lifecycle" {
    + bucket                                 = (known after apply)
    + id                                     = (known after apply)
    + transition_default_minimum_object_size = (known after apply)

    + rule {
        + id     = "Root remove incomplete uploads after 5 days"
        + status = "Enabled"

        + abort_incomplete_multipart_upload {
            + days_after_initiation = 5
          }
      }
    + rule {
        + id     = "Root retain 3 old versions"
        + status = "Enabled"

        + noncurrent_version_expiration {
            + newer_noncurrent_versions = "3"
            + noncurrent_days           = 1
          }
      }
    + rule {
        + id     = "Root remove old versions after 60 days"
        + status = "Enabled"

        + noncurrent_version_expiration {
            + noncurrent_days = 60
          }
      }
    + rule {
        + id     = "Root remove expired delete markers immediately"
        + status = "Enabled"

        + expiration {
            + days                         = 0
            + expired_object_delete_marker = true
          }
      }
    + rule {
        + id     = "Prefix test/ remove noncurrent versions older than 10 days"
        + status = "Enabled"

        + filter {
            + prefix = "test/"
          }

        + noncurrent_version_expiration {
            + noncurrent_days = 10
          }
      }
    + rule {
        + id     = "Prefix test/ retain 10 old versions"
        + status = "Enabled"

        + filter {
            + prefix = "test/"
          }

        + noncurrent_version_expiration {
            + newer_noncurrent_versions = "10"
            + noncurrent_days           = 1
          }
      }
    + rule {
        + id     = "Prefix test/ remove current versions older than 10 days"
        + status = "Enabled"

        + expiration {
            + days                         = 10
            + expired_object_delete_marker = (known after apply)
          }

        + filter {
            + prefix = "test/"
          }
      }
  }

Actual Behavior

here is a broken plan from 5.86.0 and still present in 5.88.0, please expand
# aws_s3_bucket_lifecycle_configuration.lifecycle will be created
+ resource "aws_s3_bucket_lifecycle_configuration" "lifecycle" {
    + bucket                                 = (known after apply)
    + expected_bucket_owner                  = (known after apply)
    + id                                     = (known after apply)
    + transition_default_minimum_object_size = "all_storage_classes_128K"

    + rule {
        + id     = "Root remove incomplete uploads after 5 days"
        + prefix = (known after apply)
        + status = "Enabled"

        + abort_incomplete_multipart_upload {
            + days_after_initiation = 5
          }
      }
    + rule {
        + id     = "Root retain 3 old versions"
        + prefix = (known after apply)
        + status = "Enabled"

        + noncurrent_version_expiration {
            + newer_noncurrent_versions = 3
            + noncurrent_days           = 1
          }
      }
    + rule {
        + id     = "Root remove old versions after 60 days"
        + prefix = (known after apply)
        + status = "Enabled"

        + noncurrent_version_expiration {
            + newer_noncurrent_versions = (known after apply)
            + noncurrent_days           = 60
          }
      }
    + rule {
        + id     = "Root remove expired delete markers immediately"
        + prefix = (known after apply)
        + status = "Enabled"

        + expiration {
            + days                         = (known after apply)
            + expired_object_delete_marker = true
          }
      }
    + rule {
        + id     = "Prefix test/ remove noncurrent versions older than 10 days"
        + prefix = (known after apply)
        + status = "Enabled"

        + filter {
            + object_size_greater_than = (known after apply)
            + object_size_less_than    = (known after apply)
            + prefix                   = "test/"
          }

        + noncurrent_version_expiration {
            + newer_noncurrent_versions = (known after apply)
            + noncurrent_days           = 10
          }
      }
    + rule {
        + id     = "Prefix test/ retain 10 old versions"
        + prefix = (known after apply)
        + status = "Enabled"

        + filter {
            + object_size_greater_than = (known after apply)
            + object_size_less_than    = (known after apply)
            + prefix                   = "test/"
          }

        + noncurrent_version_expiration {
            + newer_noncurrent_versions = 10
            + noncurrent_days           = 1
          }
      }
    + rule {
        + id     = "Prefix test/ remove current versions older than 10 days"
        + prefix = (known after apply)
        + status = "Enabled"

        + expiration {
            + days                         = 10
            + expired_object_delete_marker = (known after apply)
          }

        + filter {
            + object_size_greater_than = (known after apply)
            + object_size_less_than    = (known after apply)
            + prefix                   = "test/"
          }
      }
  }

note in the failing plan how there are suddenly properties for prefix and days appear with known after apply. we are not declaring those and no code has changed in between those two plans. the only difference is the provider versions.

Terraform Configuration Files

Module file:

resource "aws_s3_bucket" "this" {
  bucket = "my-tf-test-bucket"

  force_destroy = true
}

resource "aws_s3_bucket_lifecycle_configuration" "this" {
  bucket = aws_s3_bucket.this.id


  rule {
    id = "rule1"

    expiration {
      # days = 0
      expired_object_delete_marker = true
    }

    status = "Enabled"
  }
}

Test file:

variables {
  bucket_name = "testing_nonexistent_testing_bucket"
}

run "validate_backups" {
  command = plan

  assert {
    condition = alltrue([ for k,v in
      aws_s3_bucket_lifecycle_configuration.this.rule :
      v.expiration[0].days == 0 && v.expiration[0].expired_object_delete_marker if v.id == "rule1"
    ])

    error_message = <<-EOF
      Days must be 5
    EOF
  }
}

Steps to Reproduce

run the code above on 5.86 or newer and then again on 5.85 and note the differences in the plan output. pre 5.86 days will be 0, after it is known after apply. This is causing the above test to fail as it cannot calculate for days. If i try to set days == 0 then it returns a warning

│ Warning: Invalid Attribute Combination
│
│   with aws_s3_bucket_lifecycle_configuration.this,
│   on s3.tf line 16, in resource "aws_s3_bucket_lifecycle_configuration" "this":
│   16:       expired_object_delete_marker = true
│
│ Attribute "rule[0].expiration[0].expired_object_delete_marker" should not be specified when "rule[0].expiration[0].days" is also specified

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

No response

Would you like to implement a fix?

No

@nwsparks nwsparks added the bug Addresses a defect in current functionality. label Feb 24, 2025
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • 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.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@github-actions github-actions bot added service/s3 Issues and PRs that pertain to the s3 service. needs-triage Waiting for first response or review from a maintainer. labels Feb 24, 2025
@justinretzolk
Copy link
Member

Relates #41126
Relates #41073

@justinretzolk justinretzolk added prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. and removed needs-triage Waiting for first response or review from a maintainer. labels Feb 25, 2025
@gdavison gdavison self-assigned this Mar 11, 2025
@johannes-gehrs
Copy link

We're also seeing this kind of drift. Just to understand what exactly is happening here, If one were to apply the plan, would this solve the issue going forward?

Copy link

Warning

This Issue has been closed, meaning that any additional comments are much easier for the maintainers to miss. Please assume that the maintainers will not see them.

Ongoing conversations amongst community members are welcome, however, the issue will be locked after 30 days. Moving conversations to another venue, such as the AWS Provider forum, is recommended. If you have additional concerns, please open a new issue, referencing this one where needed.

@github-actions github-actions bot added this to the v5.94.0 milestone Mar 28, 2025
@github-actions github-actions bot removed the prioritized Part of the maintainer teams immediate focus. To be addressed within the current quarter. label Apr 3, 2025
Copy link

github-actions bot commented Apr 3, 2025

This functionality has been released in v5.94.0 of the Terraform AWS Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

Copy link

github-actions bot commented May 4, 2025

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 4, 2025
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
4 participants