Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 deletions internal/elasticsearch/cluster/slm.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions internal/elasticsearch/cluster/slm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
),
},
{
Expand Down Expand Up @@ -68,7 +69,7 @@ resource "elasticstack_elasticsearch_snapshot_lifecycle" "test_slm" {
snapshot_name = "<daily-snap-{now/d}>"
repository = elasticstack_elasticsearch_snapshot_repository.repo.name

indices = ["data-*", "important"]
indices = ["data-*", "abc"]
Copy link
Contributor Author

@k-yomo k-yomo May 15, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String set will be converted to list in alphabetical order, so replace it to make sure the result is not alphabetically re-ordered.
https://developer.hashicorp.com/terraform/language/expressions/type-constraints#conversion-of-complex-types

ignore_unavailable = false
include_global_state = false

Expand Down