Skip to content

Commit c95cd5c

Browse files
Copilottobio
andcommitted
Final fixes: correct test configurations and linting cleanup
Co-authored-by: tobio <444668+tobio@users.noreply.github.com>
1 parent efbb995 commit c95cd5c

File tree

8 files changed

+69
-42
lines changed

8 files changed

+69
-42
lines changed

docs/resources/elasticsearch_alias.md

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,44 @@ Manages an Elasticsearch alias. See, https://www.elastic.co/guide/en/elasticsear
1818

1919
### Required
2020

21-
- `indices` (Set of String) A set of indices to which the alias should point.
2221
- `name` (String) The alias name.
2322

2423
### Optional
2524

25+
- `read_indices` (Block Set) Set of read indices for the alias. (see [below for nested schema](#nestedblock--read_indices))
26+
- `write_index` (Block, Optional) The write index for the alias. Only one write index is allowed per alias. (see [below for nested schema](#nestedblock--write_index))
27+
28+
### Read-Only
29+
30+
- `id` (String) Generated ID of the alias resource.
31+
32+
<a id="nestedblock--read_indices"></a>
33+
### Nested Schema for `read_indices`
34+
35+
Required:
36+
37+
- `name` (String) Name of the read index.
38+
39+
Optional:
40+
2641
- `filter` (String) Query used to limit documents the alias can access.
27-
- `index_routing` (String) Value used to route indexing operations to a specific shard. If specified, this overwrites the `routing` value for indexing operations.
42+
- `index_routing` (String) Value used to route indexing operations to a specific shard.
2843
- `is_hidden` (Boolean) If true, the alias is hidden.
29-
- `is_write_index` (Boolean) If true, the index is the write index for the alias.
3044
- `routing` (String) Value used to route indexing and search operations to a specific shard.
31-
- `search_routing` (String) Value used to route search operations to a specific shard. If specified, this overwrites the routing value for search operations.
45+
- `search_routing` (String) Value used to route search operations to a specific shard.
3246

33-
### Read-Only
3447

35-
- `id` (String) Generated ID of the alias resource.
48+
<a id="nestedblock--write_index"></a>
49+
### Nested Schema for `write_index`
50+
51+
Required:
52+
53+
- `name` (String) Name of the write index.
54+
55+
Optional:
56+
57+
- `filter` (String) Query used to limit documents the alias can access.
58+
- `index_routing` (String) Value used to route indexing operations to a specific shard.
59+
- `is_hidden` (Boolean) If true, the alias is hidden.
60+
- `routing` (String) Value used to route indexing and search operations to a specific shard.
61+
- `search_routing` (String) Value used to route search operations to a specific shard.

internal/clients/elasticsearch/index.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -756,14 +756,15 @@ func UpdateAliasesAtomic(ctx context.Context, apiClient *clients.ApiClient, acti
756756
var aliasActions []map[string]interface{}
757757

758758
for _, action := range actions {
759-
if action.Type == "remove" {
759+
switch action.Type {
760+
case "remove":
760761
aliasActions = append(aliasActions, map[string]interface{}{
761762
"remove": map[string]interface{}{
762763
"index": action.Index,
763764
"alias": action.Alias,
764765
},
765766
})
766-
} else if action.Type == "add" {
767+
case "add":
767768
addDetails := map[string]interface{}{
768769
"index": action.Index,
769770
"alias": action.Alias,

internal/elasticsearch/index/alias/acc_test.go

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,10 @@ import (
66

77
"github.com/elastic/terraform-provider-elasticstack/internal/acctest"
88
"github.com/elastic/terraform-provider-elasticstack/internal/clients"
9+
"github.com/hashicorp/terraform-plugin-testing/config"
910
sdkacctest "github.com/hashicorp/terraform-plugin-testing/helper/acctest"
1011
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
1112
"github.com/hashicorp/terraform-plugin-testing/terraform"
12-
"github.com/hashicorp/terraform-plugin-testing/config"
1313
)
1414

1515
func TestAccResourceAlias(t *testing.T) {
@@ -24,7 +24,7 @@ func TestAccResourceAlias(t *testing.T) {
2424
ProtoV6ProviderFactories: acctest.Providers,
2525
Steps: []resource.TestStep{
2626
{
27-
Config: testAccResourceAliasCreate(),
27+
Config: testAccResourceAliasCreate,
2828
ConfigVariables: map[string]config.Variable{
2929
"alias_name": config.StringVariable(aliasName),
3030
"index_name": config.StringVariable(indexName),
@@ -38,7 +38,7 @@ func TestAccResourceAlias(t *testing.T) {
3838
),
3939
},
4040
{
41-
Config: testAccResourceAliasUpdate(),
41+
Config: testAccResourceAliasUpdate,
4242
ConfigVariables: map[string]config.Variable{
4343
"alias_name": config.StringVariable(aliasName),
4444
"index_name": config.StringVariable(indexName),
@@ -51,7 +51,7 @@ func TestAccResourceAlias(t *testing.T) {
5151
),
5252
},
5353
{
54-
Config: testAccResourceAliasWithFilter(),
54+
Config: testAccResourceAliasWithFilter,
5555
ConfigVariables: map[string]config.Variable{
5656
"alias_name": config.StringVariable(aliasName),
5757
"index_name": config.StringVariable(indexName),
@@ -70,7 +70,7 @@ func TestAccResourceAlias(t *testing.T) {
7070
}
7171

7272
func TestAccResourceAliasWriteIndex(t *testing.T) {
73-
// generate random names
73+
// generate random names
7474
aliasName := sdkacctest.RandStringFromCharSet(22, sdkacctest.CharSetAlpha)
7575
indexName1 := sdkacctest.RandStringFromCharSet(22, sdkacctest.CharSetAlpha)
7676
indexName2 := sdkacctest.RandStringFromCharSet(22, sdkacctest.CharSetAlpha)
@@ -83,12 +83,12 @@ func TestAccResourceAliasWriteIndex(t *testing.T) {
8383
Steps: []resource.TestStep{
8484
// Case 1: Single index with is_write_index=true
8585
{
86-
Config: testAccResourceAliasWriteIndexSingle(),
86+
Config: testAccResourceAliasWriteIndexSingle,
8787
ConfigVariables: map[string]config.Variable{
88-
"alias_name": config.StringVariable(aliasName),
89-
"index_name1": config.StringVariable(indexName1),
90-
"index_name2": config.StringVariable(indexName2),
91-
"index_name3": config.StringVariable(indexName3),
88+
"alias_name": config.StringVariable(aliasName),
89+
"index_name1": config.StringVariable(indexName1),
90+
"index_name2": config.StringVariable(indexName2),
91+
"index_name3": config.StringVariable(indexName3),
9292
},
9393
Check: resource.ComposeTestCheckFunc(
9494
resource.TestCheckResourceAttr("elasticstack_elasticsearch_alias.test_alias", "name", aliasName),
@@ -98,12 +98,12 @@ func TestAccResourceAliasWriteIndex(t *testing.T) {
9898
},
9999
// Case 2: Add new index with is_write_index=true, existing becomes read index
100100
{
101-
Config: testAccResourceAliasWriteIndexSwitch(),
101+
Config: testAccResourceAliasWriteIndexSwitch,
102102
ConfigVariables: map[string]config.Variable{
103-
"alias_name": config.StringVariable(aliasName),
104-
"index_name1": config.StringVariable(indexName1),
105-
"index_name2": config.StringVariable(indexName2),
106-
"index_name3": config.StringVariable(indexName3),
103+
"alias_name": config.StringVariable(aliasName),
104+
"index_name1": config.StringVariable(indexName1),
105+
"index_name2": config.StringVariable(indexName2),
106+
"index_name3": config.StringVariable(indexName3),
107107
},
108108
Check: resource.ComposeTestCheckFunc(
109109
resource.TestCheckResourceAttr("elasticstack_elasticsearch_alias.test_alias", "name", aliasName),
@@ -113,12 +113,12 @@ func TestAccResourceAliasWriteIndex(t *testing.T) {
113113
},
114114
// Case 3: Add third index as write index
115115
{
116-
Config: testAccResourceAliasWriteIndexTriple(),
116+
Config: testAccResourceAliasWriteIndexTriple,
117117
ConfigVariables: map[string]config.Variable{
118-
"alias_name": config.StringVariable(aliasName),
119-
"index_name1": config.StringVariable(indexName1),
120-
"index_name2": config.StringVariable(indexName2),
121-
"index_name3": config.StringVariable(indexName3),
118+
"alias_name": config.StringVariable(aliasName),
119+
"index_name1": config.StringVariable(indexName1),
120+
"index_name2": config.StringVariable(indexName2),
121+
"index_name3": config.StringVariable(indexName3),
122122
},
123123
Check: resource.ComposeTestCheckFunc(
124124
resource.TestCheckResourceAttr("elasticstack_elasticsearch_alias.test_alias", "name", aliasName),
@@ -128,12 +128,12 @@ func TestAccResourceAliasWriteIndex(t *testing.T) {
128128
},
129129
// Case 4: Remove initial index, keep two indices with one as write index
130130
{
131-
Config: testAccResourceAliasWriteIndexRemoveFirst(),
131+
Config: testAccResourceAliasWriteIndexRemoveFirst,
132132
ConfigVariables: map[string]config.Variable{
133-
"alias_name": config.StringVariable(aliasName),
134-
"index_name1": config.StringVariable(indexName1),
135-
"index_name2": config.StringVariable(indexName2),
136-
"index_name3": config.StringVariable(indexName3),
133+
"alias_name": config.StringVariable(aliasName),
134+
"index_name1": config.StringVariable(indexName1),
135+
"index_name2": config.StringVariable(indexName2),
136+
"index_name3": config.StringVariable(indexName3),
137137
},
138138
Check: resource.ComposeTestCheckFunc(
139139
resource.TestCheckResourceAttr("elasticstack_elasticsearch_alias.test_alias", "name", aliasName),
@@ -156,7 +156,7 @@ func TestAccResourceAliasDataStream(t *testing.T) {
156156
ProtoV6ProviderFactories: acctest.Providers,
157157
Steps: []resource.TestStep{
158158
{
159-
Config: testAccResourceAliasDataStreamCreate(),
159+
Config: testAccResourceAliasDataStreamCreate,
160160
ConfigVariables: map[string]config.Variable{
161161
"alias_name": config.StringVariable(aliasName),
162162
"ds_name": config.StringVariable(dsName),
@@ -469,7 +469,7 @@ func checkResourceAliasDestroy(s *terraform.State) error {
469469
if rs.Type != "elasticstack_elasticsearch_alias" {
470470
continue
471471
}
472-
472+
473473
// Handle the case where ID might not be in the expected format
474474
aliasName := rs.Primary.ID
475475
if compId, err := clients.CompositeIdFromStr(rs.Primary.ID); err == nil {
@@ -480,7 +480,7 @@ func checkResourceAliasDestroy(s *terraform.State) error {
480480
if err != nil {
481481
return err
482482
}
483-
483+
484484
res, err := esClient.Indices.GetAlias(
485485
esClient.Indices.GetAlias.WithName(aliasName),
486486
)
@@ -494,4 +494,4 @@ func checkResourceAliasDestroy(s *terraform.State) error {
494494
}
495495
}
496496
return nil
497-
}
497+
}

internal/elasticsearch/index/alias/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,4 +65,4 @@ func (r *aliasResource) Create(ctx context.Context, req resource.CreateRequest,
6565
}
6666

6767
resp.Diagnostics.Append(resp.State.Set(ctx, planModel)...)
68-
}
68+
}

internal/elasticsearch/index/alias/delete.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ func (r *aliasResource) Delete(ctx context.Context, req resource.DeleteRequest,
4141
return
4242
}
4343
}
44-
}
44+
}

internal/elasticsearch/index/alias/models.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,4 +224,4 @@ func (readIndexModel) attrTypes() map[string]attr.Type {
224224
"routing": types.StringType,
225225
"search_routing": types.StringType,
226226
}
227-
}
227+
}

internal/elasticsearch/index/alias/read.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,4 +70,4 @@ func readAliasIntoModel(ctx context.Context, client *clients.ApiClient, aliasNam
7070

7171
// Update the model with API data
7272
return model.populateFromAPI(ctx, aliasName, aliasData)
73-
}
73+
}

internal/elasticsearch/index/alias/update.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,4 @@ func (r *aliasResource) Update(ctx context.Context, req resource.UpdateRequest,
9494
}
9595

9696
resp.Diagnostics.Append(resp.State.Set(ctx, planModel)...)
97-
}
97+
}

0 commit comments

Comments
 (0)