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

Multiple ILM rules update each other #585

Open
ilyakitaev opened this issue Oct 17, 2024 · 4 comments
Open

Multiple ILM rules update each other #585

ilyakitaev opened this issue Oct 17, 2024 · 4 comments

Comments

@ilyakitaev
Copy link

ilyakitaev commented Oct 17, 2024

resource "minio_ilm_policy" "tenant-bucket-backup-ilm-daily" {
  bucket = "somebucket"

  rule {
    id         = "daily_cleanup"
    expiration = "14d"
    filter     = "daily/"
  }
}

resource "minio_ilm_policy" "tenant-bucket-backup-ilm-weekly" {

  bucket = "somebucket"

  rule {
    id         = "weekly_cleanup"
    expiration = "80d"
    filter     = "weekly/"
  }
}

Excpected creating two rules for bucket, but

# minio_ilm_policy.tenant-bucket-backup-ilm-daily[0] will be updated in-place
  ~ resource "minio_ilm_policy" "tenant-bucket-backup-ilm-daily" {
        id     = "somebucket"
        # (1 unchanged attribute hidden)

      ~ rule {
          ~ expiration                         = "80d" -> "14d"
          ~ filter                             = "weekly/" -> "daily/"
          ~ id                                 = "weekly_cleanup" -> "daily_cleanup"
            tags                               = {}
            # (3 unchanged attributes hidden)
        }
    }

cause they have same ID

@inakimalerba
Copy link

inakimalerba commented Oct 30, 2024

Hey @ilyakitaev

I hit the same issue and lost all my already created rules 😰 so it would be great to fix the library to reflect this .

Nevertheless, I managed to make it work. The code expects one object with multiple rule attributes instead of multiple minio_ilm_policy objects. Your code should be:

resource "minio_ilm_policy" "tenant-bucket-backup-ilm" {
  bucket = "somebucket"

  rule {
    id         = "daily_cleanup"
    expiration = "14d"
    filter     = "daily/"
  }

  rule {
    id         = "weekly_cleanup"
    expiration = "80d"
    filter     = "weekly/"
  }
}

@SoulKyu
Copy link
Contributor

SoulKyu commented Nov 12, 2024

@ilyakitaev
The problem is that each minio_ilm_policy resource creates a completely new lifecycle configuration for the bucket, overwriting any existing rules.

I think using a uniq policy as described by @inakimalerba is good for the moment.

We could merge policy with existing one but this would be a bad case with manual lifecycle policy that wont be destroyed by Terraform when you need Terraform to be your source of truth

I hit the same issue and lost all my already created rules 😰 so it would be great to fix the library to reflect this .

Maybe the improvement would be a better plan with deleted policy before applying

@inakimalerba
Copy link

Hey @SoulKyu , thanks for the reply.

Wanted to explain better my issue. My bucket had manually created policies, and when I tried to add a new one using terraform I was not expecting all the other policies to be replaced by the single one I was adding. It's mostly my fault but maybe that should be warned on the documentation.

Thanks :)

@SoulKyu
Copy link
Contributor

SoulKyu commented Nov 12, 2024

@inakimalerba
Thank you for the clarification! Yes, this is actually expected behavior with the current implementation - when using Terraform to manage ILM policies, it manages the entire lifecycle configuration of the bucket as a single unit. This means it will replace any existing manual configurations with what's defined in Terraform.
This is a common pattern in Terraform where resources are managed as complete units, but I agree it should be more clearly documented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants