Skip to content

Support allow_write_after_shrink in ILM policies #662

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

Merged
merged 5 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ jobs:
- '8.11.4'
- '8.12.2'
- '8.13.4'
- '8.14.0'
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Populate policy_id when importing fleet policies and integrations ([#646](https://github.com/elastic/terraform-provider-elasticstack/pull/646))
- Fix alerting rule update crash when backend responds with HTTP 4xx. ([#649](https://github.com/elastic/terraform-provider-elasticstack/pull/649))
- Support allow_write_after_shrink when managing ILM policies ([#662](https://github.com/elastic/terraform-provider-elasticstack/pull/662))

## [0.11.3] - 2024-05-16

Expand Down
2 changes: 2 additions & 0 deletions docs/resources/elasticsearch_index_lifecycle.md
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,7 @@ Required:

Optional:

- `allow_write_after_shrink` (Boolean) If true, the shrunken index is made writable by removing the write block.
- `max_primary_shard_size` (String) The max primary shard size for the target index.
- `number_of_shards` (Number) Number of shards to shrink to.

Expand Down Expand Up @@ -415,6 +416,7 @@ Required:

Optional:

- `allow_write_after_shrink` (Boolean) If true, the shrunken index is made writable by removing the write block.
- `max_primary_shard_size` (String) The max primary shard size for the target index.
- `number_of_shards` (Number) Number of shards to shrink to.

Expand Down
24 changes: 15 additions & 9 deletions internal/elasticsearch/index/ilm.go
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,11 @@ var supportedActions = map[string]*schema.Schema{
Type: schema.TypeString,
Optional: true,
},
"allow_write_after_shrink": {
Description: "If true, the shrunken index is made writable by removing the write block.",
Type: schema.TypeBool,
Optional: true,
},
},
},
},
Expand Down Expand Up @@ -530,7 +535,7 @@ func expandPhase(p map[string]interface{}, serverVersion *version.Version) (*mod
case "set_priority":
actions[actionName], diags = expandAction(a, serverVersion, "priority")
case "shrink":
actions[actionName], diags = expandAction(a, serverVersion, "number_of_shards", "max_primary_shard_size")
actions[actionName], diags = expandAction(a, serverVersion, "number_of_shards", "max_primary_shard_size", "allow_write_after_shrink")
case "unfollow":
if a[0] != nil {
ac := a[0].(map[string]interface{})
Expand Down Expand Up @@ -563,14 +568,15 @@ var ilmActionSettingOptions = map[string]struct {
def interface{}
minVersion *version.Version
}{
"number_of_replicas": {skipEmptyCheck: true},
"total_shards_per_node": {skipEmptyCheck: true, def: -1, minVersion: version.Must(version.NewVersion("7.16.0"))},
"priority": {skipEmptyCheck: true},
"min_age": {def: "", minVersion: RolloverMinConditionsMinSupportedVersion},
"min_docs": {def: 0, minVersion: RolloverMinConditionsMinSupportedVersion},
"min_size": {def: "", minVersion: RolloverMinConditionsMinSupportedVersion},
"min_primary_shard_size": {def: "", minVersion: RolloverMinConditionsMinSupportedVersion},
"min_primary_shard_docs": {def: 0, minVersion: RolloverMinConditionsMinSupportedVersion},
"number_of_replicas": {skipEmptyCheck: true},
"total_shards_per_node": {skipEmptyCheck: true, def: -1, minVersion: version.Must(version.NewVersion("7.16.0"))},
"priority": {skipEmptyCheck: true},
"min_age": {def: "", minVersion: RolloverMinConditionsMinSupportedVersion},
"min_docs": {def: 0, minVersion: RolloverMinConditionsMinSupportedVersion},
"min_size": {def: "", minVersion: RolloverMinConditionsMinSupportedVersion},
"min_primary_shard_size": {def: "", minVersion: RolloverMinConditionsMinSupportedVersion},
"min_primary_shard_docs": {def: 0, minVersion: RolloverMinConditionsMinSupportedVersion},
"allow_write_after_shrink": {def: false, minVersion: version.Must(version.NewVersion("8.14.0"))},
}

func expandAction(a []interface{}, serverVersion *version.Version, settings ...string) (map[string]interface{}, diag.Diagnostics) {
Expand Down
3 changes: 3 additions & 0 deletions internal/elasticsearch/index/ilm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,9 @@ resource "elasticstack_elasticsearch_index_lifecycle" "test" {
})
number_of_replicas = 1
}
shrink {
max_primary_shard_size = "50gb"
}
}

}
Expand Down
Loading