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

Lifecycle rule for all objects does not work

chrisfleisch opened this issue · comments

Description

I'm trying to to create a bucket with a lifecycle rule to transition all objects after 0 days to Deep Archive. The rule does not work when I created it with terraform. When I create the rule in AWS console it has a different Filter output then the one created with terraform.

Versions

  • Terraform:

Terraform v1.0.4
on darwin_amd64

  • Provider(s):

Terraform v1.0.4
on darwin_amd64

  • provider registry.terraform.io/hashicorp/aws v3.55.0
  • Module:
    AWS S3 bucket Terraform module

Reproduction

Steps to reproduce the behavior:
Terraform used to create bucket:

resource "aws_s3_bucket" "my-test-bucketname-for-infra-versions-2" {
  bucket = "my-test-bucketname-for-infra-versions-2"
  lifecycle_rule {
    id      = "Move to deep glacier after upload"
    enabled = true

    transition {
      days          = 0
      storage_class = "DEEP_ARCHIVE"
    }
  }
}

Run apply:
./terraform -chdir=projects/test_bucket apply

View s3 rule:
aws s3api get-bucket-lifecycle-configuration --bucket my-test-bucketname-for-infra-versions-2

Output from that command:

{
    "Rules": [
        {
            "ID": "Move to deep glacier after upload",
            "Filter": {
                "Prefix": ""
            },
            "Status": "Enabled",
            "Transitions": [
                {
                    "Days": 0,
                    "StorageClass": "DEEP_ARCHIVE"
                }
            ]
        }
    ]
}

This rule does not work. Objects in the bucket are not transitioned to Deep Archive storage class. I've had the rule in place for over 48 hours.

I've talked with AWS support and they said that when they create a rule for all objects the Filter field is empty and that the rule then works.

If I create a rule to apply to all objects via the AWS console and then run this command:
aws s3api get-bucket-lifecycle-configuration --bucket my-test-bucketname-for-infra-versions-2

I get different output:

{
    "Rules": [
        {
            "ID": "Move to deep glacier after upload",
            "Filter": {},
            "Status": "Enabled",
            "Transitions": [
                {
                    "Days": 0,
                    "StorageClass": "DEEP_ARCHIVE"
                }
            ]
        }
    ]
}

Even though I have not specified the optional prefix parameter in the terraform it still creates the Prefix field in the Filter field which should be empty like the one created with the console.

Is there a way I should be specifying a lifecycle rule to apply to all objects?

Hi @chrisfleisch !

This issue is probably related to Terraform AWS provider issues like:

  1. hashicorp/terraform-provider-aws#10235
  2. hashicorp/terraform-provider-aws#283

Finally, hashicorp/terraform-provider-aws#20433 - the upgrade is coming in version 4 of AWS provider.

I am not sure what can we do in the module if this is a bug in the provider (could you check the link above?).

Thanks for the links. You're probably correct that this is an issue for the provider. I can open the bug report over there.

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.