Skip to content

Commit 75844f0

Browse files
arenardtobio
andauthored
Add max_primary_shard_docs condition to ILM rollover (elastic#845)
* Add `max_primary_shard_docs` condition to ILM rollover (elastic#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 * Add explicit case for max_primary_shard_docs * Fix acctests --------- Co-authored-by: Toby Brain <[email protected]>
1 parent 08b9042 commit 75844f0

File tree

5 files changed

+61
-14
lines changed

5 files changed

+61
-14
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
## [Unreleased]
22

3+
- Add `max_primary_shard_docs` condition to ILM rollover ([#845](https://github.com/elastic/terraform-provider-elasticstack/pull/845))
4+
35
## [0.11.13] - 2025-01-09
46

57
- Support 8.15.5 in acc tests ([#963](https://github.com/elastic/terraform-provider-elasticstack/pull/963)).
@@ -11,7 +13,7 @@
1113

1214
### Breaking changes
1315

14-
- Support multiple group by fields in SLOs ([#870](https://github.com/elastic/terraform-provider-elasticstack/pull/878)). This changes to type of the `group_by` attribute of the `elasticstack_kibana_slo` resource from a String to a list of Strings. Any existing SLO defintions will need to update `group_by = "field"` to `group_by = ["field"]`.
16+
- Support multiple group by fields in SLOs ([#870](https://github.com/elastic/terraform-provider-elasticstack/pull/878)). This changes to type of the `group_by` attribute of the `elasticstack_kibana_slo` resource from a String to a list of Strings. Any existing SLO defintions will need to update `group_by = "field"` to `group_by = ["field"]`.
1517

1618
### Changes
1719
- Handle NPE in integration policy secrets ([#946](https://github.com/elastic/terraform-provider-elasticstack/pull/946))

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.2**
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/data_stream_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
func TestAccResourceDataStream(t *testing.T) {
15-
// generate renadom name
15+
// generate random name
1616
dsName := sdkacctest.RandStringFromCharSet(22, sdkacctest.CharSetAlpha)
1717

1818
resource.Test(t, resource.TestCase{

internal/elasticsearch/index/ilm.go

Lines changed: 20 additions & 10 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":
@@ -562,21 +567,26 @@ func expandPhase(p map[string]interface{}, serverVersion *version.Version) (*mod
562567
return &phase, diags
563568
}
564569

565-
var RolloverMinConditionsMinSupportedVersion = version.Must(version.NewVersion("8.4.0"))
570+
var (
571+
RolloverMinConditionsMinSupportedVersion = version.Must(version.NewVersion("8.4.0"))
572+
MaxPrimaryShardDocsMinSupportedVersion = version.Must(version.NewVersion("8.2.0"))
573+
)
574+
566575
var ilmActionSettingOptions = map[string]struct {
567576
skipEmptyCheck bool
568577
def interface{}
569578
minVersion *version.Version
570579
}{
580+
"allow_write_after_shrink": {def: false, minVersion: version.Must(version.NewVersion("8.14.0"))},
571581
"number_of_replicas": {skipEmptyCheck: true},
572-
"total_shards_per_node": {skipEmptyCheck: true, def: -1, minVersion: version.Must(version.NewVersion("7.16.0"))},
573582
"priority": {skipEmptyCheck: true},
583+
"max_primary_shard_docs": {def: 0, minVersion: MaxPrimaryShardDocsMinSupportedVersion},
574584
"min_age": {def: "", minVersion: RolloverMinConditionsMinSupportedVersion},
575585
"min_docs": {def: 0, minVersion: RolloverMinConditionsMinSupportedVersion},
576586
"min_size": {def: "", minVersion: RolloverMinConditionsMinSupportedVersion},
577-
"min_primary_shard_size": {def: "", minVersion: RolloverMinConditionsMinSupportedVersion},
578587
"min_primary_shard_docs": {def: 0, minVersion: RolloverMinConditionsMinSupportedVersion},
579-
"allow_write_after_shrink": {def: false, minVersion: version.Must(version.NewVersion("8.14.0"))},
588+
"min_primary_shard_size": {def: "", minVersion: RolloverMinConditionsMinSupportedVersion},
589+
"total_shards_per_node": {skipEmptyCheck: true, def: -1, minVersion: version.Must(version.NewVersion("7.16.0"))},
580590
}
581591

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

internal/elasticsearch/index/ilm_test.go

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,14 @@ func TestAccResourceILMRolloverConditions(t *testing.T) {
127127
CheckDestroy: checkResourceILMDestroy,
128128
ProtoV6ProviderFactories: acctest.Providers,
129129
Steps: []resource.TestStep{
130+
{
131+
SkipFunc: versionutils.CheckIfVersionIsUnsupported(index.MaxPrimaryShardDocsMinSupportedVersion),
132+
Config: testAccResourceILMCreateWithMaxPrimaryShardDocs(policyName),
133+
Check: resource.ComposeTestCheckFunc(
134+
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "name", policyName),
135+
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.max_primary_shard_docs", "5000"),
136+
),
137+
},
130138
{
131139
SkipFunc: versionutils.CheckIfVersionIsUnsupported(index.RolloverMinConditionsMinSupportedVersion),
132140
Config: testAccResourceILMCreateWithRolloverConditions(policyName),
@@ -135,12 +143,13 @@ func TestAccResourceILMRolloverConditions(t *testing.T) {
135143
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.max_age", "7d"),
136144
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.max_docs", "10000"),
137145
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.max_size", "100gb"),
146+
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.max_primary_shard_docs", "5000"),
138147
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.max_primary_shard_size", "50gb"),
139148
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.min_age", "3d"),
140149
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.min_docs", "1000"),
141150
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"),
143151
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.min_primary_shard_docs", "500"),
152+
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.min_primary_shard_size", "25gb"),
144153
),
145154
},
146155
},
@@ -273,12 +282,37 @@ resource "elasticstack_elasticsearch_index_lifecycle" "test_rollover" {
273282
max_age = "7d"
274283
max_docs = 10000
275284
max_size = "100gb"
285+
max_primary_shard_docs = 5000
276286
max_primary_shard_size = "50gb"
277287
min_age = "3d"
278288
min_docs = 1000
279289
min_size = "50gb"
280-
min_primary_shard_size = "25gb"
281290
min_primary_shard_docs = 500
291+
min_primary_shard_size = "25gb"
292+
}
293+
294+
readonly {}
295+
}
296+
297+
delete {
298+
delete {}
299+
}
300+
}
301+
`, name)
302+
}
303+
304+
func testAccResourceILMCreateWithMaxPrimaryShardDocs(name string) string {
305+
return fmt.Sprintf(`
306+
provider "elasticstack" {
307+
elasticsearch {}
308+
}
309+
310+
resource "elasticstack_elasticsearch_index_lifecycle" "test_rollover" {
311+
name = "%s"
312+
313+
hot {
314+
rollover {
315+
max_primary_shard_docs = 5000
282316
}
283317
284318
readonly {}

0 commit comments

Comments
 (0)