Skip to content

Commit

Permalink
Make sql db instance recreate when going private -> public (#3882) (#…
Browse files Browse the repository at this point in the history
…7054)

Signed-off-by: Modular Magician <[email protected]>
  • Loading branch information
modular-magician authored Aug 18, 2020
1 parent 5ce1050 commit e6400e4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .changelog/3882.txt
Original file line number Diff line number Diff line change
@@ -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.
```
15 changes: 14 additions & 1 deletion google/resource_sql_database_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit e6400e4

Please sign in to comment.