digitalocean / terraform-provider-digitalocean

Terraform DigitalOcean provider
https://registry.terraform.io/providers/digitalocean/digitalocean/latest/docs
Mozilla Public License 2.0
507 stars 277 forks source link

spaces lifecycle policy not working as expected #752

Open volleynator opened 2 years ago

volleynator commented 2 years ago

Bug Report

Describe the bug

I try to set up lifecycle policy which should expire and delete files after one day. The rule is applied according to s3cmd, however, files are not deleted, they remain inside the space.

Affected Resource(s)

Expected Behavior

Files should be deleted after one day

Actual Behavior

Files remain inside the bucked

Steps to Reproduce

  1. terraform apply -->

Terraform Configuration Files

resource "digitalocean_spaces_bucket" "postgres-backup-s3-bucket" {
  name   = "backup-space"
  region = "fra1"

  lifecycle_rule {
    id      = "lifecycle-rule"
    enabled = true
    expiration {
      days = 1
    }
  }
}

Expected behavior

Terraform v1.0.10
on linux_amd64
+ provider registry.terraform.io/digitalocean/digitalocean v2.14.0
+ provider registry.terraform.io/gavinbunney/kubectl v1.10.0
+ provider registry.terraform.io/hashicorp/helm v1.3.2
+ provider registry.terraform.io/hashicorp/kubernetes v1.13.4
+ provider registry.terraform.io/hashicorp/template v2.2.0
+ provider registry.terraform.io/kreuzwerker/docker v2.11.0
+ provider registry.terraform.io/loafoe/htpasswd v0.9.1

Your version of Terraform is out of date! The latest version
is 1.0.11. You can update by downloading from https://www.terraform.io/downloads.html

Additional context

s3cmd output of s3cmd getlifecycle

<?xml version="1.0" ?>
<LifecycleConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
    <Rule>
        <ID>lifecycle-rule</ID>
        <Prefix/>
        <Status>Enabled</Status>
        <Expiration>
            <Days>1</Days>
        </Expiration>
    </Rule>
</LifecycleConfiguration>
baznikin commented 2 years ago

I confirm this issue! same behavior

andrewsomething commented 2 years ago

Can you open a DigitalOcean support ticket so the team can take a closer look? If s3cmd getlifecycle is returning the lifecycle rule as defined in Terraform, that suggests that Terraform is working as expected and the issue is on the backend.

baznikin commented 2 years ago

Can you open a DigitalOcean support ticket so the team can take a closer look? If s3cmd getlifecycle is returning the lifecycle rule as defined in Terraform, that suggests that Terraform is working as expected and the issue is on the backend.

I suppose you are right, I'll reach them after some additional tests. s3cmd return lifecycle policy same as for OP.

ChiefMateStarbuck commented 1 year ago

Hello @baznikin, have we been able to resolve this issue for you?

baznikin commented 1 year ago

Hello @ChiefMateStarbuck! Yes, after some trials and tests lifecycle_rule works for me. My issue was wrong prefix value. My final code looks almost same as OP policy. I dunno why, maybe something was fixed from API side...

lifecycle_rule {
  id                                     = "expire-backups"
  enabled                                = true
  abort_incomplete_multipart_upload_days = 2
  expiration {
    days = 15
  }
}
zanoni23 commented 1 year ago

So lifecycle policy doesn't support versioning on the bucket being set to Suspended. If you have versioning enabled then you supposedly have to add something for noncurrent_version_expiration.

If I create a new Space bucket via the Digital Ocean portal 'aws s3api get-bucket-versioning' returns nothing.

If I create a new Space bucket with Terraform using the latest Digital Ocean provider and set versioning to disabled, it creates a bucket that when queried returns versioning status as Suspended.

If I create a new Space bucket with Terraform using the latest Digital Ocean provider and don't have anything specifying 'versioning' at all, then get-bucket-versioning returns nothing.

I would have thought that setting versioning to disabled would have not configured any versioning at all. I guess I have to modify my Terraform module to workaround this. And also test to confirm that lifecycle option works with zero versioning config set (which I assume it does given it works for other people).