Skip to content

Commit b608fbf

Browse files
committed
Add explicit case for max_primary_shard_docs
1 parent 3136fbc commit b608fbf

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed

internal/elasticsearch/index/ilm.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,11 @@ func expandPhase(p map[string]interface{}, serverVersion *version.Version) (*mod
567567
return &phase, diags
568568
}
569569

570-
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+
571575
var ilmActionSettingOptions = map[string]struct {
572576
skipEmptyCheck bool
573577
def interface{}
@@ -576,7 +580,7 @@ var ilmActionSettingOptions = map[string]struct {
576580
"allow_write_after_shrink": {def: false, minVersion: version.Must(version.NewVersion("8.14.0"))},
577581
"number_of_replicas": {skipEmptyCheck: true},
578582
"priority": {skipEmptyCheck: true},
579-
"max_primary_shard_docs": {minVersion: version.Must(version.NewVersion("8.2.0"))},
583+
"max_primary_shard_docs": {minVersion: MaxPrimaryShardDocsMinSupportedVersion},
580584
"min_age": {def: "", minVersion: RolloverMinConditionsMinSupportedVersion},
581585
"min_docs": {def: 0, minVersion: RolloverMinConditionsMinSupportedVersion},
582586
"min_size": {def: "", minVersion: RolloverMinConditionsMinSupportedVersion},

internal/elasticsearch/index/ilm_test.go

Lines changed: 33 additions & 1 deletion
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,7 +143,7 @@ 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"),
138-
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.min_primary_shard_docs", "5000"),
146+
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.max_primary_shard_docs", "5000"),
139147
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.max_primary_shard_size", "50gb"),
140148
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.min_age", "3d"),
141149
resource.TestCheckResourceAttr("elasticstack_elasticsearch_index_lifecycle.test_rollover", "hot.0.rollover.0.min_docs", "1000"),
@@ -293,6 +301,30 @@ resource "elasticstack_elasticsearch_index_lifecycle" "test_rollover" {
293301
`, name)
294302
}
295303

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
316+
}
317+
318+
readonly {}
319+
}
320+
321+
delete {
322+
delete {}
323+
}
324+
}
325+
`, name)
326+
}
327+
296328
func testAccResourceILMDownsampleNoTimeout(name string) string {
297329
return fmt.Sprintf(`
298330
provider "elasticstack" {

0 commit comments

Comments
 (0)