Skip to content

Commit

Permalink
Adding DiffSuppress for pd-ssd and pd-hdd (#6537) (#12567)
Browse files Browse the repository at this point in the history
* first commit

* Adding DiffSuppress for pd-ssd and pd-hdd

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

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Sep 15, 2022
1 parent 06b8305 commit 0d68b7e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .changelog/6537.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
google_sql_database_instance: fixed a bug causing a perma-diff on disk_type due to API values being downcased
```
14 changes: 10 additions & 4 deletions google/resource_sql_database_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,11 @@ is set to true.`,
Description: `The size of data disk, in GB. Size of a running instance cannot be reduced but can be increased. If you want to set this field, set disk_autoresize to false.`,
},
"disk_type": {
Type: schema.TypeString,
Optional: true,
Default: "PD_SSD",
Description: `The type of data disk: PD_SSD or PD_HDD.`,
Type: schema.TypeString,
Optional: true,
Default: "PD_SSD",
DiffSuppressFunc: caseDiffDashSuppress,
Description: `The type of data disk: PD_SSD or PD_HDD.`,
},
"ip_configuration": {
Type: schema.TypeList,
Expand Down Expand Up @@ -1831,3 +1832,8 @@ func sqlDatabaseInstanceRestoreFromBackup(d *schema.ResourceData, config *Config

return nil
}

func caseDiffDashSuppress(_, old, new string, _ *schema.ResourceData) bool {
postReplaceNew := strings.Replace(new, "-", "_", -1)
return strings.ToUpper(postReplaceNew) == strings.ToUpper(old)
}
34 changes: 34 additions & 0 deletions google/resource_sql_database_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,40 @@ import (
sqladmin "google.golang.org/api/sqladmin/v1beta4"
)

func TestCaseDiffDashSuppress(t *testing.T) {
cases := map[string]struct {
Old, New string
ExpectDiffSuppress bool
}{
"PD_HDD": {
Old: "PD_HDD",
New: "pd-hdd",
ExpectDiffSuppress: true,
},
"PD_SSD": {
Old: "PD_SSD",
New: "pd-ssd",
ExpectDiffSuppress: true,
},
"pd-hdd": {
Old: "pd-hdd",
New: "PD_HDD",
ExpectDiffSuppress: false,
},
"pd-ssd": {
Old: "pd-ssd",
New: "PD_SSD",
ExpectDiffSuppress: false,
},
}

for tn, tc := range cases {
if caseDiffDashSuppress(tn, tc.Old, tc.New, nil) != tc.ExpectDiffSuppress {
t.Errorf("bad: %s, %q => %q expect DiffSuppress to return %t", tn, tc.Old, tc.New, tc.ExpectDiffSuppress)
}
}
}

func TestAccSqlDatabase_basic(t *testing.T) {
t.Parallel()

Expand Down

0 comments on commit 0d68b7e

Please sign in to comment.