Skip to content

Commit

Permalink
Breaking change: Update MinIO ILM policy with improved validation, no…
Browse files Browse the repository at this point in the history
…ncurrent version support, and better schema structure (#588)

Co-authored-by: Victor Nogueira <felladrin@gmail.com>
  • Loading branch information
SoulKyu and felladrin authored Nov 9, 2024
1 parent 851697a commit ffef36d
Show file tree
Hide file tree
Showing 4 changed files with 434 additions and 106 deletions.
102 changes: 81 additions & 21 deletions docs/resources/ilm_policy.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ resource "minio_s3_bucket" "bucket" {
bucket = "bucket"
}
# Simple expiration rule
resource "minio_ilm_policy" "bucket-lifecycle-rules" {
bucket = minio_s3_bucket.bucket.bucket
Expand All @@ -25,48 +26,107 @@ resource "minio_ilm_policy" "bucket-lifecycle-rules" {
expiration = "7d"
}
}
# Complex lifecycle policy with multiple rules
resource "minio_ilm_policy" "comprehensive-rules" {
bucket = minio_s3_bucket.bucket.bucket
# Rule with transition and expiration
rule {
id = "documents"
transition {
days = "30d"
storage_class = "STANDARD_IA"
}
expiration = "90d"
filter = "documents/"
tags = {
"department" = "finance"
}
}
# Rule with noncurrent version management
rule {
id = "versioning"
noncurrent_expiration {
days = "60d"
newer_versions = 5
}
noncurrent_transition {
days = "30d"
storage_class = "GLACIER"
newer_versions = 3
}
}
}
```

<!-- schema generated by tfplugindocs -->
## Schema

### Required

- `bucket` (String)
- `rule` (Block List, Min: 1) (see [below for nested schema](#nestedblock--rule))
- `bucket` (String) The name of the bucket to which this lifecycle policy applies. Must be between 0 and 63 characters.
- `rule` (Block List, Min: 1) A list of lifecycle rules (see below for nested schema).

### Read-Only

- `id` (String) The ID of this resource.

<a id="nestedblock--rule"></a>
### Nested Schema for `rule`

Required:
#### Required

- `id` (String)
- `id` (String) Unique identifier for the rule.

Optional:
#### Optional

- `expiration` (String) Value may be duration (5d), date (1970-01-01), or "DeleteMarker" to expire delete markers if `noncurrent_version_expiration_days` is used
- `filter` (String)
- `noncurrent_version_expiration_days` (Number)
- `noncurrent_version_transition_days` (Number)
- `tags` (Map of String)
- `transition` (Block List, Max: 1) (see [below for nested schema](#nestedblock--rule--transition))
- `expiration` (String) When objects should expire. Value must be a duration (e.g., "7d"), date (e.g., "2024-12-31"), or "DeleteMarker".
- `filter` (String) Prefix path filter for the rule.
- `tags` (Map of String) Key-value pairs of tags to filter objects.
- `transition` (Block List, Max: 1) Configuration block for transitioning objects to a different storage class (see below).
- `noncurrent_transition` (Block List, Max: 1) Configuration for transitioning noncurrent object versions (see below).
- `noncurrent_expiration` (Block List, Max: 1) Configuration for expiring noncurrent object versions (see below).

Read-Only:
#### Read-Only

- `status` (String)
- `status` (String) Current status of the rule.

<a id="nestedblock--rule--transition"></a>
### Nested Schema for `rule.transition`

Required:
#### Required

- `storage_class` (String) The storage class to transition objects to.

#### Optional

- `days` (String) Number of days after which objects should transition, in format "Nd" (e.g., "30d").
- `date` (String) Specific date for the transition in "YYYY-MM-DD" format.

### Nested Schema for `rule.noncurrent_transition`

#### Required

- `days` (String) Number of days after which noncurrent versions should transition, in format "Nd".
- `storage_class` (String) The storage class to transition noncurrent versions to.

#### Optional

- `newer_versions` (Number) Number of newer versions to retain before transition. Must be non-negative.

### Nested Schema for `rule.noncurrent_expiration`

#### Required

- `days` (String) Number of days after which noncurrent versions should be deleted, in format "Nd".

#### Optional

- `newer_versions` (Number) Number of newer versions to retain before expiration. Must be non-negative.

- `storage_class` (String)
## Import

Optional:
MinIO lifecycle policies can be imported using the bucket name:

- `date` (String)
- `days` (String)
```shell
terraform import minio_ilm_policy.example bucket-name
```
70 changes: 66 additions & 4 deletions examples/resources/minio_ilm_policy/resource.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,73 @@ resource "minio_s3_bucket" "bucket" {
bucket = "bucket"
}

resource "minio_ilm_policy" "bucket-lifecycle-rules" {
resource "minio_ilm_policy" "test_policy" {
bucket = minio_s3_bucket.bucket.bucket

rule {
id = "expire-7d"
expiration = "7d"
id = "rule1"
# Delete objects after 90 days
expiration = "90d"
filter = "documents/"
tags = {
"environment" = "test"
"type" = "document"
}
}
}

rule {
id = "rule2"
# Move objects to GLACIER after 30 days
transition {
days = "30d"
storage_class = "GLACIER"
}
filter = "backups/"
}

rule {
id = "rule3"
# Specific date for transition
transition {
date = "2024-12-31"
storage_class = "STANDARD_IA"
}
filter = "archives/"
}

rule {
id = "rule4"
# Handle noncurrent versions
noncurrent_transition {
days = "45d"
storage_class = "GLACIER"
newer_versions = 3
}
filter = "versioned-data/"
}

rule {
id = "rule5"
# Delete old versions
noncurrent_expiration {
days = "365d"
newer_versions = 5
}
filter = "old-versions/"
}

rule {
id = "rule6"
# Combined policy: transition then expire
transition {
days = "60d"
storage_class = "STANDARD_IA"
}
expiration = "180d"
filter = "logs/"
tags = {
"retention" = "short-term"
"type" = "logs"
}
}
}
Loading

0 comments on commit ffef36d

Please sign in to comment.