Skip to content

Commit

Permalink
Change the default for google_sql_database.deletion_policy to DELETE (#…
Browse files Browse the repository at this point in the history
…6936) (#13226)

Fixes #13206

Signed-off-by: Modular Magician <magic-modules@google.com>

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician committed Dec 12, 2022
1 parent df663ab commit a989875
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 8 deletions.
6 changes: 6 additions & 0 deletions .changelog/6936.txt
@@ -0,0 +1,6 @@
```release-note:note
sql: fixed an issue where `google_sql_database` was abandoned by default as of version `4.45.0`. Users who have upgraded to `4.45.0` or `4.46.0` will see a diff when running their next `terraform apply` after upgrading this version, indicating the `deletion_policy` field's value has changed from `"ABANDON"` to `"DELETE"`. This will create a no-op call against the API, but can otherwise be safely applied.
```
```release-note:bug
sql: fixed an issue where `google_sql_database` was abandoned by default as of version `4.45.0`. Users who have upgraded to `4.45.0` or `4.46.0` will see a diff when running their next `terraform apply` after upgrading this version, indicating the `deletion_policy` field's value has changed from `"ABANDON"` to `"DELETE"`. This will create a no-op call against the API, but can otherwise be safely applied.
```
8 changes: 4 additions & 4 deletions google/resource_sql_database.go
Expand Up @@ -79,11 +79,11 @@ a value of 'en_US.UTF8' at creation time.`,
"deletion_policy": {
Type: schema.TypeString,
Optional: true,
Default: "ABANDON",
Default: "DELETE",
Description: `The deletion policy for the database. Setting ABANDON allows the resource
to be abandoned rather than deleted. This is useful for Postgres, where databases cannot be
deleted from the API if there are users other than cloudsqlsuperuser with access. Possible
values are: "ABANDON".`,
values are: "ABANDON", "DELETE". Defaults to "DELETE".`,
},
"project": {
Type: schema.TypeString,
Expand Down Expand Up @@ -218,7 +218,7 @@ func resourceSQLDatabaseRead(d *schema.ResourceData, meta interface{}) error {

// Explicitly set virtual fields to default values if unset
if _, ok := d.GetOkExists("deletion_policy"); !ok {
if err := d.Set("deletion_policy", "ABANDON"); err != nil {
if err := d.Set("deletion_policy", "DELETE"); err != nil {
return fmt.Errorf("Error setting deletion_policy: %s", err)
}
}
Expand Down Expand Up @@ -401,7 +401,7 @@ func resourceSQLDatabaseImport(d *schema.ResourceData, meta interface{}) ([]*sch
d.SetId(id)

// Explicitly set virtual fields to default values on import
if err := d.Set("deletion_policy", "ABANDON"); err != nil {
if err := d.Set("deletion_policy", "DELETE"); err != nil {
return nil, fmt.Errorf("Error setting deletion_policy: %s", err)
}

Expand Down
7 changes: 4 additions & 3 deletions google/resource_sql_database_generated_test.go
Expand Up @@ -86,9 +86,10 @@ func TestAccSQLDatabase_sqlDatabaseDeletionPolicyExample(t *testing.T) {
Config: testAccSQLDatabase_sqlDatabaseDeletionPolicyExample(context),
},
{
ResourceName: "google_sql_database.database_deletion_policy",
ImportState: true,
ImportStateVerify: true,
ResourceName: "google_sql_database.database_deletion_policy",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"deletion_policy"},
},
},
})
Expand Down
2 changes: 1 addition & 1 deletion website/docs/r/sql_database.html.markdown
Expand Up @@ -121,7 +121,7 @@ The following arguments are supported:
* `deletion_policy` - (Optional) The deletion policy for the database. Setting ABANDON allows the resource
to be abandoned rather than deleted. This is useful for Postgres, where databases cannot be
deleted from the API if there are users other than cloudsqlsuperuser with access. Possible
values are: "ABANDON".
values are: "ABANDON", "DELETE". Defaults to "DELETE".


## Attributes Reference
Expand Down

0 comments on commit a989875

Please sign in to comment.