From 5615bfa09c44894e202b98c70c360972b0a6851a Mon Sep 17 00:00:00 2001 From: k-yomo Date: Mon, 15 May 2023 16:53:50 +0900 Subject: [PATCH 1/3] Guarantee indices order in SLM --- internal/elasticsearch/cluster/slm.go | 8 ++++---- internal/elasticsearch/cluster/slm_test.go | 5 +++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/internal/elasticsearch/cluster/slm.go b/internal/elasticsearch/cluster/slm.go index d062aa81e..cf77b99b8 100644 --- a/internal/elasticsearch/cluster/slm.go +++ b/internal/elasticsearch/cluster/slm.go @@ -73,7 +73,7 @@ func ResourceSlm() *schema.Resource { }, "indices": { Description: "Comma-separated list of data streams and indices to include in the snapshot.", - Type: schema.TypeSet, + Type: schema.TypeList, Optional: true, Computed: true, Elem: &schema.Schema{ @@ -201,9 +201,9 @@ func resourceSlmPut(ctx context.Context, d *schema.ResourceData, meta interface{ } indices := make([]string, 0) if v, ok := d.GetOk("indices"); ok { - p := v.(*schema.Set) - for _, e := range p.List() { - indices = append(indices, e.(string)) + list := v.([]interface{}) + for _, idx := range list { + indices = append(indices, idx.(string)) } } slmConfig.Indices = indices diff --git a/internal/elasticsearch/cluster/slm_test.go b/internal/elasticsearch/cluster/slm_test.go index 87c5e20f0..fa07fea0b 100644 --- a/internal/elasticsearch/cluster/slm_test.go +++ b/internal/elasticsearch/cluster/slm_test.go @@ -31,7 +31,8 @@ func TestAccResourceSLM(t *testing.T) { resource.TestCheckResourceAttr("elasticstack_elasticsearch_snapshot_lifecycle.test_slm", "max_count", "50"), resource.TestCheckResourceAttr("elasticstack_elasticsearch_snapshot_lifecycle.test_slm", "ignore_unavailable", "false"), resource.TestCheckResourceAttr("elasticstack_elasticsearch_snapshot_lifecycle.test_slm", "include_global_state", "false"), - resource.TestCheckTypeSetElemAttr("elasticstack_elasticsearch_snapshot_lifecycle.test_slm", "indices.*", "data-*"), + resource.TestCheckResourceAttr("elasticstack_elasticsearch_snapshot_lifecycle.test_slm", "indices.0", "data-*"), + resource.TestCheckResourceAttr("elasticstack_elasticsearch_snapshot_lifecycle.test_slm", "indices.1", "abc"), ), }, { @@ -68,7 +69,7 @@ resource "elasticstack_elasticsearch_snapshot_lifecycle" "test_slm" { snapshot_name = "" repository = elasticstack_elasticsearch_snapshot_repository.repo.name - indices = ["data-*", "important"] + indices = ["data-*", "abc"] ignore_unavailable = false include_global_state = false From 38da509ee149d33e8cba18dcf04dbae9c97237bc Mon Sep 17 00:00:00 2001 From: k-yomo Date: Mon, 15 May 2023 18:14:48 +0900 Subject: [PATCH 2/3] Regenerate docs --- docs/resources/elasticsearch_snapshot_lifecycle.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/resources/elasticsearch_snapshot_lifecycle.md b/docs/resources/elasticsearch_snapshot_lifecycle.md index f44c109d8..88dfe6826 100644 --- a/docs/resources/elasticsearch_snapshot_lifecycle.md +++ b/docs/resources/elasticsearch_snapshot_lifecycle.md @@ -63,7 +63,7 @@ resource "elasticstack_elasticsearch_snapshot_lifecycle" "slm_policy" { - `feature_states` (Set of String) Feature states to include in the snapshot. - `ignore_unavailable` (Boolean) If `false`, the snapshot fails if any data stream or index in indices is missing or closed. If `true`, the snapshot ignores missing or closed data streams and indices. - `include_global_state` (Boolean) If `true`, include the cluster state in the snapshot. -- `indices` (Set of String) Comma-separated list of data streams and indices to include in the snapshot. +- `indices` (List of String) Comma-separated list of data streams and indices to include in the snapshot. - `max_count` (Number) Maximum number of snapshots to retain, even if the snapshots have not yet expired. - `metadata` (String) Attaches arbitrary metadata to the snapshot. - `min_count` (Number) Minimum number of snapshots to retain, even if the snapshots have expired. From 78b46720984e64d4287e0a47761683a8d8d1b91a Mon Sep 17 00:00:00 2001 From: k-yomo Date: Mon, 15 May 2023 18:15:58 +0900 Subject: [PATCH 3/3] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a76a13747..0bb685733 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -50,6 +50,7 @@ }) } ``` +- Fix order of `indices` field in SLM ([#326](https://github.com/elastic/terraform-provider-elasticstack/pull/326)) ## [0.5.0] - 2022-12-07