Skip to content

Commit 1848f5f

Browse files
Terraform Team Automationsahilg11
authored andcommitted
Bug Fix - [mysql] Terraform support DbSystem change shape without ForceNew
1 parent 5fef80f commit 1848f5f

File tree

7 files changed

+48
-25
lines changed

7 files changed

+48
-25
lines changed

internal/integrationtest/mysql_mysql_backup_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,7 @@ var (
6868
acctest.GenerateResourceFromRepresentationMap("oci_core_vcn", "test_vcn", acctest.Required, acctest.Create, CoreVcnRepresentation) +
6969
MysqlMysqlConfigurationResourceConfig +
7070
acctest.GenerateResourceFromRepresentationMap("oci_mysql_mysql_db_system", "test_mysql_backup_db_system", acctest.Required, acctest.Create, MysqlMysqlDbSystemRepresentation) +
71-
AvailabilityDomainConfig +
72-
DefinedTagsDependencies
71+
AvailabilityDomainConfig
7372
)
7473

7574
// issue-routing-tag: mysql/default

internal/integrationtest/mysql_mysql_configuration_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ var (
149149
}
150150

151151
MysqlMysqlConfigurationResourceDependencies = utils.MysqlConfigurationIdVariable +
152+
utils.MysqlConfigurationIdVariableE3_2_32_OCID +
152153
DefinedTagsDependencies
153154
)
154155

internal/integrationtest/mysql_mysql_db_system_resource_test.go

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,17 @@ var (
7979
"ignore_changes": acctest.Representation{RepType: acctest.Required, Create: []string{"defined_tags"}},
8080
}
8181

82+
mysqlDbSystemRepresentationShapeAndConfigUpdate = map[string]interface{}{
83+
"admin_password": acctest.Representation{RepType: acctest.Required, Create: `BEstrO0ng_#11`},
84+
"admin_username": acctest.Representation{RepType: acctest.Required, Create: `adminUser`},
85+
"availability_domain": acctest.Representation{RepType: acctest.Required, Create: `${data.oci_identity_availability_domains.test_availability_domains.availability_domains.0.name}`},
86+
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
87+
"configuration_id": acctest.Representation{RepType: acctest.Optional, Create: `${var.MysqlConfigurationOCID[var.region]}`, Update: `${var.MysqlConfigurationE3_2_32_OCID[var.region]}`},
88+
"shape_name": acctest.Representation{RepType: acctest.Required, Create: `MySQL.VM.Standard.E3.1.8GB`, Update: `MySQL.VM.Standard.E3.2.32GB`},
89+
"subnet_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_core_subnet.test_subnet.id}`},
90+
"data_storage_size_in_gb": acctest.Representation{RepType: acctest.Required, Create: `50`},
91+
}
92+
8293
MysqlDbSystemSourceBackupResourceDependencies = MysqlMysqlDbSystemResourceDependencies + utils.MysqlHAConfigurationIdVariable +
8394
acctest.GenerateResourceFromRepresentationMap("oci_mysql_mysql_backup", "test_mysql_backup", acctest.Required, acctest.Create, MysqlMysqlBackupRepresentation) +
8495
acctest.GenerateResourceFromRepresentationMap("oci_mysql_mysql_db_system", "test_mysql_backup_db_system", acctest.Required, acctest.Create, MysqlMysqlDbSystemRepresentation)
@@ -590,8 +601,8 @@ func TestMysqlMysqlDbSystemResource_HA_enable(t *testing.T) {
590601
}
591602

592603
// issue-routing-tag: mysql/default
593-
func TestMysqlMysqlDbSystemResource_configurationId(t *testing.T) {
594-
httpreplay.SetScenario("TestMysqlMysqlDbSystemResource_configurationId")
604+
func TestMysqlMysqlDbSystemResource_updateConfigurationIdAndShape(t *testing.T) {
605+
httpreplay.SetScenario("TestMysqlMysqlDbSystemResource_updateConfigurationIdAndShape")
595606
defer httpreplay.SaveScenario()
596607

597608
config := acctest.ProviderTestConfig()
@@ -603,42 +614,42 @@ func TestMysqlMysqlDbSystemResource_configurationId(t *testing.T) {
603614

604615
var resId, resId2 string
605616

606-
updatedRepresentation := acctest.GetUpdatedRepresentationCopy("configuration_id",
607-
acctest.Representation{RepType: acctest.Optional, Create: `${var.MysqlConfigurationOCID[var.region]}`, Update: `${var.MysqlHAConfigurationOCID[var.region]}`},
608-
acctest.RepresentationCopyWithNewProperties(MysqlMysqlDbSystemRepresentation, map[string]interface{}{
609-
"backup_policy": acctest.RepresentationGroup{RepType: acctest.Optional, Group: MysqlDbSystemBackupPolicyNotUpdateableRepresentation},
610-
}))
611-
612617
// would be nice to make this look up work, but since this is terraform syntax we can't evaluate it.
613618
// Luckily configs are realm wide and the ocid will be the same across all regions. We should remove the map
614619
// at some point.
615620
// mysqlConfigurationOCIDVal := `${var.MysqlConfigurationOCID[var.region]}`
616-
// mysqlHAConfigurationOCIDVal := `${var.MysqlHAConfigurationOCID[var.region]}`
621+
// change configuration and shape from
622+
// MySQL.VM.Standard.E3.1.8GB.Standalone
617623
mysqlConfigurationOCIDVal := "ocid1.mysqlconfiguration.oc1..aaaaaaaalwzc2a22xqm56fwjwfymixnulmbq3v77p5v4lcbb6qhkftxf2trq"
618-
mysqlHAConfigurationOCIDVal := "ocid1.mysqlconfiguration.oc1..aaaaaaaantprksu6phqfgr5xvyut46wdfesdszonbclybfwvahgysfjbrb4q"
624+
// to
625+
// mysqlConfigurationOCIDVal2 := `${var.MysqlConfigurationE3_2_32_OCID[var.region]}`
626+
// MySQL.VM.Standard.E3.2.32GB.Standalone
627+
mysqlConfigurationE3_2_32_OCIDVal := "ocid1.mysqlconfiguration.oc1..aaaaaaaakremacvh2fizcznnja5rdxry2q4nyn27afjblyrimzjmrqblhfwa"
619628

620629
// NOTE: for now this test has to be separate from TestMysqlMysqlDbSystemResource_HA because the configuration and is_highly_available fields
621630
// cannot be changed at the same time. Once that is fixed, we should consolidate these two test cases
622631
acctest.ResourceTest(t, nil, []resource.TestStep{
623632
// verify standalone Create
624633
{
625-
Config: config + compartmentIdVariableStr + MysqlDbSystemSourceBackupResourceDependencies +
626-
acctest.GenerateResourceFromRepresentationMap("oci_mysql_mysql_db_system", "test_mysql_db_system", acctest.Optional, acctest.Create, updatedRepresentation),
634+
Config: config + compartmentIdVariableStr + MysqlMysqlDbSystemResourceDependencies +
635+
acctest.GenerateResourceFromRepresentationMap("oci_mysql_mysql_db_system", "test_mysql_db_system", acctest.Optional, acctest.Create, mysqlDbSystemRepresentationShapeAndConfigUpdate),
627636
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
628637
resource.TestCheckResourceAttr(resourceName, "configuration_id", mysqlConfigurationOCIDVal),
638+
resource.TestCheckResourceAttr(resourceName, "shape_name", "MySQL.VM.Standard.E3.1.8GB"),
629639

630640
func(s *terraform.State) (err error) {
631641
resId, err = acctest.FromInstanceState(s, resourceName, "id")
632642
return err
633643
},
634644
),
635645
},
636-
// verify update to HA enabled configuration
646+
// verify update to new configuration and shape
637647
{
638-
Config: config + compartmentIdVariableStr + MysqlDbSystemSourceBackupResourceDependencies +
639-
acctest.GenerateResourceFromRepresentationMap("oci_mysql_mysql_db_system", "test_mysql_db_system", acctest.Optional, acctest.Update, updatedRepresentation),
648+
Config: config + compartmentIdVariableStr + MysqlMysqlDbSystemResourceDependencies +
649+
acctest.GenerateResourceFromRepresentationMap("oci_mysql_mysql_db_system", "test_mysql_db_system", acctest.Optional, acctest.Update, mysqlDbSystemRepresentationShapeAndConfigUpdate),
640650
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
641-
resource.TestCheckResourceAttr(resourceName, "configuration_id", mysqlHAConfigurationOCIDVal),
651+
resource.TestCheckResourceAttr(resourceName, "configuration_id", mysqlConfigurationE3_2_32_OCIDVal),
652+
resource.TestCheckResourceAttr(resourceName, "shape_name", "MySQL.VM.Standard.E3.2.32GB"),
642653

643654
func(s *terraform.State) (err error) {
644655
resId2, err = acctest.FromInstanceState(s, resourceName, "id")

internal/integrationtest/mysql_mysql_db_system_test.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ var (
123123
acctest.GenerateResourceFromRepresentationMap("oci_core_subnet", "test_subnet", acctest.Required, acctest.Create, CoreSubnetRepresentation) +
124124
acctest.GenerateResourceFromRepresentationMap("oci_core_vcn", "test_vcn", acctest.Required, acctest.Create, CoreVcnRepresentation) +
125125
AvailabilityDomainConfig +
126-
MysqlMysqlVersionResourceConfig +
127-
DefinedTagsDependencies
126+
MysqlMysqlVersionResourceConfig
128127
)
129128

130129
// issue-routing-tag: mysql/default

internal/service/mysql/mysql_mysql_db_system_resource.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ func MysqlMysqlDbSystemResource() *schema.Resource {
5050
"shape_name": {
5151
Type: schema.TypeString,
5252
Required: true,
53-
ForceNew: true,
5453
},
5554
"subnet_id": {
5655
Type: schema.TypeString,
@@ -1030,6 +1029,11 @@ func (s *MysqlMysqlDbSystemResourceCrud) Update() error {
10301029
}
10311030
}
10321031

1032+
if shapeName, ok := s.D.GetOkExists("shape_name"); ok && s.D.HasChange("shape_name") {
1033+
tmp := shapeName.(string)
1034+
request.ShapeName = &tmp
1035+
}
1036+
10331037
request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(s.DisableNotFoundRetries, "mysql")
10341038

10351039
_, err := s.Client.UpdateDbSystem(context.Background(), request)

internal/utils/helpers.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,16 @@ const (
7979
us-phoenix-1 = "ocid1.mysqlconfiguration.oc1..aaaaaaaalwzc2a22xqm56fwjwfymixnulmbq3v77p5v4lcbb6qhkftxf2trq"
8080
}
8181
}
82-
`
82+
`
83+
MysqlConfigurationIdVariableE3_2_32_OCID = `
84+
variable "MysqlConfigurationE3_2_32_OCID" {
85+
type = "map"
86+
default = {
87+
us-ashburn-1 = "ocid1.mysqlconfiguration.oc1..aaaaaaaakremacvh2fizcznnja5rdxry2q4nyn27afjblyrimzjmrqblhfwa"
88+
us-phoenix-1 = "ocid1.mysqlconfiguration.oc1..aaaaaaaakremacvh2fizcznnja5rdxry2q4nyn27afjblyrimzjmrqblhfwa"
89+
}
90+
}
91+
`
8392
MysqlHAConfigurationIdVariable = `
8493
variable "MysqlHAConfigurationOCID" {
8594
type = "map"

website/docs/r/mysql_mysql_db_system.html.markdown

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ The following arguments are supported:
105105

106106
At some point in the window, the system may incur a brief service disruption as the backup is performed.
107107
* `compartment_id` - (Required) The OCID of the compartment.
108-
* `configuration_id` - (Optional) The OCID of the Configuration to be used for this DB System.
108+
* `configuration_id` - (Optional) (Updatable) The OCID of the Configuration to be used for this DB System.
109109
* `crash_recovery` - (Optional) (Updatable) Whether to run the DB System with InnoDB Redo Logs and the Double Write Buffer enabled or disabled, and whether to enable or disable syncing of the Binary Logs.
110-
* `data_storage_size_in_gb` - (Optional) Initial size of the data volume in GBs that will be created and attached. Keep in mind that this only specifies the size of the database data volume, the log volume for the database will be scaled appropriately with its shape. It is required if you are creating a new database. It cannot be set if you are creating a database from a backup.
110+
* `data_storage_size_in_gb` - (Optional) (Updatable) Initial size of the data volume in GBs that will be created and attached. Keep in mind that this only specifies the size of the database data volume, the log volume for the database will be scaled appropriately with its shape. It is required if you are creating a new database. It cannot be set if you are creating a database from a backup.
111111
* `defined_tags` - (Optional) (Updatable) Usage of predefined tag keys. These predefined keys are scoped to namespaces. Example: `{"foo-namespace.bar-key": "value"}`
112112
* `deletion_policy` - (Optional) (Updatable) Policy for how the DB System and related resources should be handled at the time of its deletion.
113113
* `automatic_backup_retention` - (Optional) (Updatable) Specifies if any automatic backups created for a DB System should be retained or deleted when the DB System is deleted.
@@ -140,7 +140,7 @@ The following arguments are supported:
140140
"{time-of-day}" is the "Time" portion of an RFC3339-formatted timestamp. Any second or sub-second time data will be truncated to zero.
141141
* `port` - (Optional) The port for primary endpoint of the DB System to listen on.
142142
* `port_x` - (Optional) The TCP network port on which X Plugin listens for connections. This is the X Plugin equivalent of port.
143-
* `shape_name` - (Required) The name of the shape. The shape determines the resources allocated
143+
* `shape_name` - (Required) (Updatable) The name of the shape. The shape determines the resources allocated
144144
* CPU cores and memory for VM shapes; CPU cores, memory and storage for non-VM (or bare metal) shapes. To get a list of shapes, use the [ListShapes](https://docs.cloud.oracle.com/iaas/api/#/en/mysql/20190415/ShapeSummary/ListShapes) operation.
145145
* `source` - (Optional) Parameters detailing how to provision the initial data of the system.
146146
* `backup_id` - (Required when source_type=BACKUP) The OCID of the backup to be used as the source for the new DB System.

0 commit comments

Comments
 (0)