diff --git a/.changelog/3882.txt b/.changelog/3882.txt new file mode 100644 index 00000000000..de20a905be4 --- /dev/null +++ b/.changelog/3882.txt @@ -0,0 +1,3 @@ +```release-note:bug +sql: fixed an issue where `google_sql_database_instance` would throw an error when removing `private_network`. Removing `private_network` now recreates the resource. +``` diff --git a/google/resource_sql_database_instance.go b/google/resource_sql_database_instance.go index d1b631ec575..0056b6e057d 100644 --- a/google/resource_sql_database_instance.go +++ b/google/resource_sql_database_instance.go @@ -96,7 +96,8 @@ func resourceSqlDatabaseInstance() *schema.Resource { }, CustomizeDiff: customdiff.All( - customdiff.ForceNewIfChange("settings.0.disk_size", isDiskShrinkage)), + customdiff.ForceNewIfChange("settings.0.disk_size", isDiskShrinkage), + privateNetworkCustomizeDiff), Schema: map[string]*schema.Schema{ "region": { @@ -602,6 +603,18 @@ func isFirstGen(d *schema.ResourceData) bool { return !regexp.MustCompile("db*").Match([]byte(tier)) } +// Makes private_network ForceNew if it is changing from set to nil. The API returns an error +// if this change is attempted in-place. +func privateNetworkCustomizeDiff(d *schema.ResourceDiff, meta interface{}) error { + old, new := d.GetChange("settings.0.ip_configuration.0.private_network") + + if old != "" && new == "" { + d.ForceNew("settings.0.ip_configuration.0.private_network") + } + + return nil +} + func resourceSqlDatabaseInstanceCreate(d *schema.ResourceData, meta interface{}) error { config := meta.(*Config)