Skip to content

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

Closed
@nwsparks

Description

@nwsparks

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

Metadata

Metadata

Assignees

Labels

bugAddresses a defect in current functionality.service/s3Issues and PRs that pertain to the s3 service.

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions