Skip to content

Commit

Permalink
Fix error thrown when index configuration has no number_of_replicas s…
Browse files Browse the repository at this point in the history
…pecified (#123)

* Fix error thrown when index configuration has no number_of_replicas specified

Signed-off-by: Rupa Lahiri <[email protected]>

* Add tests to check index resource with default shards and replicas on re-apply/update

Signed-off-by: Rupa Lahiri <[email protected]>

---------

Signed-off-by: Rupa Lahiri <[email protected]>
  • Loading branch information
rblcoder authored Nov 9, 2023
1 parent 2245e1d commit 7128bed
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
7 changes: 5 additions & 2 deletions provider/resource_opensearch_index.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ var (
Type: schema.TypeString,
Description: "Number of shard replicas. A stringified number.",
Optional: true,
Computed: true,
},
"auto_expand_replicas": {
Type: schema.TypeString,
Expand Down Expand Up @@ -634,8 +635,10 @@ func resourceOpensearchIndexUpdate(d *schema.ResourceData, meta interface{}) err
settings := make(map[string]interface{})
for _, key := range settingsKeys {
schemaName := strings.Replace(key, ".", "_", -1)
if d.HasChange(schemaName) {
settings[key] = d.Get(schemaName)
if _, ok := d.GetOk(schemaName); ok {
if d.HasChange(schemaName) {
settings[key] = d.Get(schemaName)
}
}
}

Expand Down
27 changes: 27 additions & 0 deletions provider/resource_opensearch_index_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ resource "opensearch_index" "test" {
indexing_slowlog_threshold_index_warn = "5s"
indexing_slowlog_level = "warn"
}
`
testAccOpensearchIndexDefaultShardsReplicas = `
resource "opensearch_index" "testdefaultshardsreplicas" {
name = "terraform-testdefaultshardsreplicas"
}
`
testAccOpensearchIndexAnalysis = `
resource "opensearch_index" "test" {
Expand Down Expand Up @@ -250,6 +255,28 @@ func TestAccOpensearchIndex(t *testing.T) {
})
}

func TestAccOpensearchIndexDefaultShardsReplicas(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: checkOpensearchIndexDestroy,
Steps: []resource.TestStep{
{
Config: testAccOpensearchIndexDefaultShardsReplicas,
Check: resource.ComposeTestCheckFunc(
checkOpensearchIndexExists("opensearch_index.testdefaultshardsreplicas"),
),
},
{
Config: testAccOpensearchIndexDefaultShardsReplicas,
Check: resource.ComposeTestCheckFunc(
checkOpensearchIndexExists("opensearch_index.testdefaultshardsreplicas"),
),
},
},
})
}

func TestAccOpensearchIndex_rolloverAliasOpendistro(t *testing.T) {
provider := Provider()
diags := provider.Configure(context.Background(), &terraform.ResourceConfig{})
Expand Down

0 comments on commit 7128bed

Please sign in to comment.