Skip to content

Commit b97f1c7

Browse files
author
AR3E3B9N
committed
Add max_primary_shard_docs condition to ILM rollover (#845)
* Add `max_primary_shard_docs` condition to rollover * Update test for rollover `max_primary_shard_docs` condition * Specify min version in the description * Update CHANGELOG.md
1 parent 1fa3e9b commit b97f1c7

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
### Changes
44

5+
- Add `max_primary_shard_docs` condition to ILM rollover ([#845](https://github.com/elastic/terraform-provider-elasticstack/pull/845))
56
- Fix boolean setting parsing for `elasticstack_elasticsearch_indices` data source. ([#842](https://github.com/elastic/terraform-provider-elasticstack/pull/842))
67

78
## [0.11.9] - 2024-10-14

docs/resources/elasticsearch_index_lifecycle.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ Optional:
288288

289289
- `max_age` (String) Triggers rollover after the maximum elapsed time from index creation is reached.
290290
- `max_docs` (Number) Triggers rollover after the specified maximum number of documents is reached.
291+
- `max_primary_shard_docs` (Number) Triggers rollover when the largest primary shard in the index reaches a certain number of documents. Supported from Elasticsearch version **8.4**
291292
- `max_primary_shard_size` (String) Triggers rollover when the largest primary shard in the index reaches a certain size.
292293
- `max_size` (String) Triggers rollover when the index reaches a certain size.
293294
- `min_age` (String) Prevents rollover until after the minimum elapsed time from index creation is reached. Supported from Elasticsearch version **8.4**

internal/elasticsearch/index/ilm.go

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,11 @@ var supportedActions = map[string]*schema.Schema{
268268
Type: schema.TypeString,
269269
Optional: true,
270270
},
271+
"max_primary_shard_docs": {
272+
Description: "Triggers rollover when the largest primary shard in the index reaches a certain number of documents. Supported from Elasticsearch version **8.2**",
273+
Type: schema.TypeInt,
274+
Optional: true,
275+
},
271276
"max_primary_shard_size": {
272277
Description: "Triggers rollover when the largest primary shard in the index reaches a certain size.",
273278
Type: schema.TypeString,
@@ -288,16 +293,16 @@ var supportedActions = map[string]*schema.Schema{
288293
Type: schema.TypeString,
289294
Optional: true,
290295
},
291-
"min_primary_shard_size": {
292-
Description: "Prevents rollover until the largest primary shard in the index reaches a certain size. Supported from Elasticsearch version **8.4**",
293-
Type: schema.TypeString,
294-
Optional: true,
295-
},
296296
"min_primary_shard_docs": {
297297
Description: "Prevents rollover until the largest primary shard in the index reaches a certain number of documents. Supported from Elasticsearch version **8.4**",
298298
Type: schema.TypeInt,
299299
Optional: true,
300300
},
301+
"min_primary_shard_size": {
302+
Description: "Prevents rollover until the largest primary shard in the index reaches a certain size. Supported from Elasticsearch version **8.4**",
303+
Type: schema.TypeString,
304+
Optional: true,
305+
},
301306
},
302307
},
303308
},
@@ -529,7 +534,7 @@ func expandPhase(p map[string]interface{}, serverVersion *version.Version) (*mod
529534
}
530535
}
531536
case "rollover":
532-
actions[actionName], diags = expandAction(a, serverVersion, "max_age", "max_docs", "max_size", "max_primary_shard_size", "min_age", "min_docs", "min_size", "min_primary_shard_size", "min_primary_shard_docs")
537+
actions[actionName], diags = expandAction(a, serverVersion, "max_age", "max_docs", "max_size", "max_primary_shard_docs", "max_primary_shard_size", "min_age", "min_docs", "min_size", "min_primary_shard_docs", "min_primary_shard_size")
533538
case "searchable_snapshot":
534539
actions[actionName], diags = expandAction(a, serverVersion, "snapshot_repository", "force_merge_index")
535540
case "set_priority":
@@ -568,15 +573,16 @@ var ilmActionSettingOptions = map[string]struct {
568573
def interface{}
569574
minVersion *version.Version
570575
}{
576+
"allow_write_after_shrink": {def: false, minVersion: version.Must(version.NewVersion("8.14.0"))},
571577
"number_of_replicas": {skipEmptyCheck: true},
572-
"total_shards_per_node": {skipEmptyCheck: true, def: -1, minVersion: version.Must(version.NewVersion("7.16.0"))},
573578
"priority": {skipEmptyCheck: true},
579+
"max_primary_shard_docs": {minVersion: version.Must(version.NewVersion("8.2.0"))},
574580
"min_age": {def: "", minVersion: RolloverMinConditionsMinSupportedVersion},
575581
"min_docs": {def: 0, minVersion: RolloverMinConditionsMinSupportedVersion},
576582
"min_size": {def: "", minVersion: RolloverMinConditionsMinSupportedVersion},
577-
"min_primary_shard_size": {def: "", minVersion: RolloverMinConditionsMinSupportedVersion},
578583
"min_primary_shard_docs": {def: 0, minVersion: RolloverMinConditionsMinSupportedVersion},
579-
"allow_write_after_shrink": {def: false, minVersion: version.Must(version.NewVersion("8.14.0"))},
584+
"min_primary_shard_size": {def: "", minVersion: RolloverMinConditionsMinSupportedVersion},
585+
"total_shards_per_node": {skipEmptyCheck: true, def: -1, minVersion: version.Must(version.NewVersion("7.16.0"))},
580586
}
581587

582588
func expandAction(a []interface{}, serverVersion *version.Version, settings ...string) (map[string]interface{}, diag.Diagnostics) {

internal/elasticsearch/index/ilm_test.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,13 @@ func TestAccResourceILMRolloverConditions(t *testing.T) {
135135
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.max_age", "7d"),
136136
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.max_docs", "10000"),
137137
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.max_size", "100gb"),
138+
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.min_primary_shard_docs", "5000"),
138139
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.max_primary_shard_size", "50gb"),
139140
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.min_age", "3d"),
140141
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.min_docs", "1000"),
141142
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.min_size", "50gb"),
142-
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.min_primary_shard_size", "25gb"),
143143
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.min_primary_shard_docs", "500"),
144+
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.min_primary_shard_size", "25gb"),
144145
),
145146
},
146147
},
@@ -273,12 +274,13 @@ resource "elasticstack_elasticsearch_index_lifecycle" "test_rollover" {
273274
max_age = "7d"
274275
max_docs = 10000
275276
max_size = "100gb"
277+
max_primary_shard_docs = 5000
276278
max_primary_shard_size = "50gb"
277279
min_age = "3d"
278280
min_docs = 1000
279281
min_size = "50gb"
280-
min_primary_shard_size = "25gb"
281282
min_primary_shard_docs = 500
283+
min_primary_shard_size = "25gb"
282284
}
283285
284286
readonly {}

0 commit comments

Comments
 (0)