From f1f9bf53d282f7992963e9cb50b18991cc009f28 Mon Sep 17 00:00:00 2001 From: Andrew Starr-Bochicchio Date: Fri, 15 Nov 2024 18:38:10 -0500 Subject: [PATCH 1/2] opensearch_config: only send PATCH on create if values set. --- .../database/resource_database_opensearch_config.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/digitalocean/database/resource_database_opensearch_config.go b/digitalocean/database/resource_database_opensearch_config.go index 1cd952f2c..9a6ef9d83 100644 --- a/digitalocean/database/resource_database_opensearch_config.go +++ b/digitalocean/database/resource_database_opensearch_config.go @@ -254,8 +254,10 @@ func resourceDigitalOceanDatabaseOpensearchConfigCreate(ctx context.Context, d * client := meta.(*config.CombinedConfig).GodoClient() clusterID := d.Get("cluster_id").(string) - if err := updateOpensearchConfig(ctx, d, client); err != nil { - return diag.Errorf("Error updating Opensearch configuration: %s", err) + if d.HasChangeExcept("cluster_id") { + if err := updateOpensearchConfig(ctx, d, client); err != nil { + return diag.Errorf("Error updating Opensearch configuration: %s", err) + } } d.SetId(makeDatabaseOpensearchConfigID(clusterID)) From ed361fcac5b314c2a694b607de562184eabfbd1f Mon Sep 17 00:00:00 2001 From: Andrew Starr-Bochicchio Date: Fri, 15 Nov 2024 18:58:26 -0500 Subject: [PATCH 2/2] opensearch_config: use GetOkExists for bools --- .../resource_database_opensearch_config.go | 14 +++++++------- .../resource_database_opensearch_config_test.go | 14 ++++++++++---- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/digitalocean/database/resource_database_opensearch_config.go b/digitalocean/database/resource_database_opensearch_config.go index 9a6ef9d83..bd7bd02a5 100644 --- a/digitalocean/database/resource_database_opensearch_config.go +++ b/digitalocean/database/resource_database_opensearch_config.go @@ -280,11 +280,11 @@ func updateOpensearchConfig(ctx context.Context, d *schema.ResourceData, client opts := &godo.OpensearchConfig{} - if v, ok := d.GetOk("ism_enabled"); ok { + if v, ok := d.GetOkExists("ism_enabled"); ok { opts.IsmEnabled = godo.PtrTo(v.(bool)) } - if v, ok := d.GetOk("ism_history_enabled"); ok { + if v, ok := d.GetOkExists("ism_history_enabled"); ok { opts.IsmHistoryEnabled = godo.PtrTo(v.(bool)) } @@ -352,15 +352,15 @@ func updateOpensearchConfig(ctx context.Context, d *schema.ResourceData, client opts.IndicesRecoveryMaxConcurrentFileChunks = godo.PtrTo(v.(int)) } - if v, ok := d.GetOk("action_auto_create_index_enabled"); ok { + if v, ok := d.GetOkExists("action_auto_create_index_enabled"); ok { opts.ActionAutoCreateIndexEnabled = godo.PtrTo(v.(bool)) } - if v, ok := d.GetOk("action_destructive_requires_name"); ok { + if v, ok := d.GetOkExists("action_destructive_requires_name"); ok { opts.ActionDestructiveRequiresName = godo.PtrTo(v.(bool)) } - if v, ok := d.GetOk("enable_security_audit"); ok { + if v, ok := d.GetOkExists("enable_security_audit"); ok { opts.EnableSecurityAudit = godo.PtrTo(v.(bool)) } @@ -408,7 +408,7 @@ func updateOpensearchConfig(ctx context.Context, d *schema.ResourceData, client opts.ThreadPoolForceMergeSize = godo.PtrTo(v.(int)) } - if v, ok := d.GetOk("override_main_response_version"); ok { + if v, ok := d.GetOkExists("override_main_response_version"); ok { opts.OverrideMainResponseVersion = godo.PtrTo(v.(bool)) } @@ -424,7 +424,7 @@ func updateOpensearchConfig(ctx context.Context, d *schema.ResourceData, client opts.ClusterRoutingAllocationNodeConcurrentRecoveries = godo.PtrTo(v.(int)) } - if v, ok := d.GetOk("plugins_alerting_filter_by_backend_roles_enabled"); ok { + if v, ok := d.GetOkExists("plugins_alerting_filter_by_backend_roles_enabled"); ok { opts.PluginsAlertingFilterByBackendRolesEnabled = godo.PtrTo(v.(bool)) } diff --git a/digitalocean/database/resource_database_opensearch_config_test.go b/digitalocean/database/resource_database_opensearch_config_test.go index b92dbe029..15cdb9097 100644 --- a/digitalocean/database/resource_database_opensearch_config_test.go +++ b/digitalocean/database/resource_database_opensearch_config_test.go @@ -20,17 +20,21 @@ func TestAccDigitalOceanDatabaseOpensearchConfig_Basic(t *testing.T) { { Config: fmt.Sprintf(testAccCheckDigitalOceanDatabaseOpensearchConfigConfigBasic, dbConfig, true, 10, "1"), Check: resource.ComposeTestCheckFunc( + resource.TestCheckResourceAttr("digitalocean_database_opensearch_config.foobar", "enable_security_audit", "true"), resource.TestCheckResourceAttr("digitalocean_database_opensearch_config.foobar", "ism_enabled", "true"), + resource.TestCheckResourceAttr("digitalocean_database_opensearch_config.foobar", "ism_history_enabled", "true"), resource.TestCheckResourceAttr("digitalocean_database_opensearch_config.foobar", "ism_history_max_age_hours", "10"), resource.TestCheckResourceAttr("digitalocean_database_opensearch_config.foobar", "ism_history_max_docs", "1"), ), }, { - Config: fmt.Sprintf(testAccCheckDigitalOceanDatabaseOpensearchConfigConfigBasic, dbConfig, false, 1, "9223372036854775807"), + Config: fmt.Sprintf(testAccCheckDigitalOceanDatabaseOpensearchConfigConfigBasic, dbConfig, false, 1, "1000000000000000000"), Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("digitalocean_database_opensearch_config.foobar", "ism_enabled", "false"), + resource.TestCheckResourceAttr("digitalocean_database_opensearch_config.foobar", "enable_security_audit", "false"), + resource.TestCheckResourceAttr("digitalocean_database_opensearch_config.foobar", "ism_enabled", "true"), + resource.TestCheckResourceAttr("digitalocean_database_opensearch_config.foobar", "ism_history_enabled", "true"), resource.TestCheckResourceAttr("digitalocean_database_opensearch_config.foobar", "ism_history_max_age_hours", "1"), - resource.TestCheckResourceAttr("digitalocean_database_opensearch_config.foobar", "ism_history_max_docs", "9223372036854775807"), + resource.TestCheckResourceAttr("digitalocean_database_opensearch_config.foobar", "ism_history_max_docs", "1000000000000000000"), ), }, }, @@ -42,7 +46,9 @@ const testAccCheckDigitalOceanDatabaseOpensearchConfigConfigBasic = ` resource "digitalocean_database_opensearch_config" "foobar" { cluster_id = digitalocean_database_cluster.foobar.id - ism_enabled = %t + enable_security_audit = %t + ism_enabled = true + ism_history_enabled = true ism_history_max_age_hours = %d ism_history_max_docs = %s }`