mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 18:01:01 -06:00
provider/google-cloud: Add second generation disk specification options (#11571)
* Add second generation disk specification options. * Adjust test check to match resource read behaviour.
This commit is contained in:
parent
babc52202c
commit
23e01de515
@ -89,6 +89,18 @@ func resourceSqlDatabaseInstance() *schema.Resource {
|
||||
},
|
||||
},
|
||||
},
|
||||
"disk_autoresize": &schema.Schema{
|
||||
Type: schema.TypeBool,
|
||||
Optional: true,
|
||||
},
|
||||
"disk_size": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
"disk_type": &schema.Schema{
|
||||
Type: schema.TypeString,
|
||||
Optional: true,
|
||||
},
|
||||
"ip_configuration": &schema.Schema{
|
||||
Type: schema.TypeList,
|
||||
Optional: true,
|
||||
@ -325,6 +337,18 @@ func resourceSqlDatabaseInstanceCreate(d *schema.ResourceData, meta interface{})
|
||||
settings.CrashSafeReplicationEnabled = v.(bool)
|
||||
}
|
||||
|
||||
if v, ok := _settings["disk_autoresize"]; ok && v.(bool) {
|
||||
settings.StorageAutoResize = v.(bool)
|
||||
}
|
||||
|
||||
if v, ok := _settings["disk_size"]; ok && v.(int) > 0 {
|
||||
settings.DataDiskSizeGb = int64(v.(int))
|
||||
}
|
||||
|
||||
if v, ok := _settings["disk_type"]; ok && len(v.(string)) > 0 {
|
||||
settings.DataDiskType = v.(string)
|
||||
}
|
||||
|
||||
if v, ok := _settings["database_flags"]; ok {
|
||||
settings.DatabaseFlags = make([]*sqladmin.DatabaseFlags, 0)
|
||||
_databaseFlagsList := v.([]interface{})
|
||||
@ -579,6 +603,24 @@ func resourceSqlDatabaseInstanceRead(d *schema.ResourceData, meta interface{}) e
|
||||
_settings["crash_safe_replication"] = settings.CrashSafeReplicationEnabled
|
||||
}
|
||||
|
||||
if v, ok := _settings["disk_autoresize"]; ok && v != nil {
|
||||
if v.(bool) {
|
||||
_settings["disk_autoresize"] = settings.StorageAutoResize
|
||||
}
|
||||
}
|
||||
|
||||
if v, ok := _settings["disk_size"]; ok && v != nil {
|
||||
if v.(int) > 0 && settings.DataDiskSizeGb < int64(v.(int)) {
|
||||
_settings["disk_size"] = settings.DataDiskSizeGb
|
||||
}
|
||||
}
|
||||
|
||||
if v, ok := _settings["disk_type"]; ok && v != nil {
|
||||
if len(v.(string)) > 0 {
|
||||
_settings["disk_type"] = settings.DataDiskType
|
||||
}
|
||||
}
|
||||
|
||||
if v, ok := _settings["database_flags"]; ok && len(v.([]interface{})) > 0 {
|
||||
_flag_map := make(map[string]string)
|
||||
// First keep track of localy defined flag pairs
|
||||
@ -842,6 +884,20 @@ func resourceSqlDatabaseInstanceUpdate(d *schema.ResourceData, meta interface{})
|
||||
settings.CrashSafeReplicationEnabled = v.(bool)
|
||||
}
|
||||
|
||||
if v, ok := _settings["disk_autoresize"]; ok && v.(bool) {
|
||||
settings.StorageAutoResize = v.(bool)
|
||||
}
|
||||
|
||||
if v, ok := _settings["disk_size"]; ok {
|
||||
if v.(int) > 0 && int64(v.(int)) > instance.Settings.DataDiskSizeGb {
|
||||
settings.DataDiskSizeGb = int64(v.(int))
|
||||
}
|
||||
}
|
||||
|
||||
if v, ok := _settings["disk_type"]; ok && len(v.(string)) > 0 {
|
||||
settings.DataDiskType = v.(string)
|
||||
}
|
||||
|
||||
_oldDatabaseFlags := make([]interface{}, 0)
|
||||
if ov, ook := _o["database_flags"]; ook {
|
||||
_oldDatabaseFlags = ov.([]interface{})
|
||||
|
@ -115,6 +115,29 @@ func TestAccGoogleSqlDatabaseInstance_slave(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccGoogleSqlDatabaseInstance_diskspecs(t *testing.T) {
|
||||
var instance sqladmin.DatabaseInstance
|
||||
masterID := acctest.RandInt()
|
||||
|
||||
resource.Test(t, resource.TestCase{
|
||||
PreCheck: func() { testAccPreCheck(t) },
|
||||
Providers: testAccProviders,
|
||||
CheckDestroy: testAccGoogleSqlDatabaseInstanceDestroy,
|
||||
Steps: []resource.TestStep{
|
||||
resource.TestStep{
|
||||
Config: fmt.Sprintf(
|
||||
testGoogleSqlDatabaseInstance_diskspecs, masterID),
|
||||
Check: resource.ComposeTestCheckFunc(
|
||||
testAccCheckGoogleSqlDatabaseInstanceExists(
|
||||
"google_sql_database_instance.instance", &instance),
|
||||
testAccCheckGoogleSqlDatabaseInstanceEquals(
|
||||
"google_sql_database_instance.instance", &instance),
|
||||
),
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
func TestAccGoogleSqlDatabaseInstance_settings_upgrade(t *testing.T) {
|
||||
var instance sqladmin.DatabaseInstance
|
||||
databaseID := acctest.RandInt()
|
||||
@ -266,6 +289,24 @@ func testAccCheckGoogleSqlDatabaseInstanceEquals(n string,
|
||||
return fmt.Errorf("Error settings.crash_safe_replication mismatch, (%s, %s)", server, local)
|
||||
}
|
||||
|
||||
server = strconv.FormatBool(instance.Settings.StorageAutoResize)
|
||||
local = attributes["settings.0.disk_autoresize"]
|
||||
if server != local && len(server) > 0 && len(local) > 0 {
|
||||
return fmt.Errorf("Error settings.disk_autoresize mismatch, (%s, %s)", server, local)
|
||||
}
|
||||
|
||||
server = strconv.FormatInt(instance.Settings.DataDiskSizeGb, 10)
|
||||
local = attributes["settings.0.disk_size"]
|
||||
if server != local && len(server) > 0 && len(local) > 0 && local != "0" {
|
||||
return fmt.Errorf("Error settings.disk_size mismatch, (%s, %s)", server, local)
|
||||
}
|
||||
|
||||
server = instance.Settings.DataDiskType
|
||||
local = attributes["settings.0.disk_type"]
|
||||
if server != local && len(server) > 0 && len(local) > 0 {
|
||||
return fmt.Errorf("Error settings.disk_type mismatch, (%s, %s)", server, local)
|
||||
}
|
||||
|
||||
if instance.Settings.IpConfiguration != nil {
|
||||
server = strconv.FormatBool(instance.Settings.IpConfiguration.Ipv4Enabled)
|
||||
local = attributes["settings.0.ip_configuration.0.ipv4_enabled"]
|
||||
@ -530,6 +571,20 @@ resource "google_sql_database_instance" "instance_slave" {
|
||||
}
|
||||
`
|
||||
|
||||
var testGoogleSqlDatabaseInstance_diskspecs = `
|
||||
resource "google_sql_database_instance" "instance" {
|
||||
name = "tf-lw-%d"
|
||||
region = "us-central1"
|
||||
|
||||
settings {
|
||||
tier = "db-f1-micro"
|
||||
disk_autoresize = true
|
||||
disk_size = 15
|
||||
disk_type = "PD_HDD"
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
var testGoogleSqlDatabaseInstance_authNets_step1 = `
|
||||
resource "google_sql_database_instance" "instance" {
|
||||
name = "tf-lw-%d"
|
||||
|
@ -73,6 +73,12 @@ The required `settings` block supports:
|
||||
* `crash_safe_replication` - (Optional) Specific to read instances, indicates
|
||||
when crash-safe replication flags are enabled.
|
||||
|
||||
* `disk_autoresize` - (Optional, Second Generation, Default: `false`) Configuration to increase storage size automatically.
|
||||
|
||||
* `disk_size` - (Optional, Second Generation, Default: `10`) The size of data disk, in GB. Size of a running instance cannot be reduced but can be increased.
|
||||
|
||||
* `disk_type` - (Optional, Second Generation, Default: `PD_SSD`) The type of data disk: PD_SSD or PD_HDD.
|
||||
|
||||
* `pricing_plan` - (Optional) Pricing plan for this instance, can be one of
|
||||
`PER_USE` or `PACKAGE`.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user