diff --git a/provider/resource_opensearch_index.go b/provider/resource_opensearch_index.go index 96000aa..708c9ac 100644 --- a/provider/resource_opensearch_index.go +++ b/provider/resource_opensearch_index.go @@ -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, @@ -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) + } } } diff --git a/provider/resource_opensearch_index_test.go b/provider/resource_opensearch_index_test.go index d353165..9b86231 100644 --- a/provider/resource_opensearch_index_test.go +++ b/provider/resource_opensearch_index_test.go @@ -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" { @@ -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{})