Skip to content

Commit c7b8aac

Browse files
Terraform Team Automationravinitp
authored andcommitted
Added - Support for MDS: Integrate with Database Management Service
1 parent d0e5277 commit c7b8aac

13 files changed

+118
-0
lines changed

examples/mysql/main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ resource "oci_mysql_mysql_db_system" "test_mysql_db_system" {
112112

113113
#Optional
114114
crash_recovery = "ENABLED"
115+
database_management = "ENABLED"
115116

116117
#Optional
117118
deletion_policy {

internal/integrationtest/mysql_mysql_db_system_resource_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -784,3 +784,56 @@ func TestMysqlMysqlDbSystemResource_updateConfigurationIdAndShape(t *testing.T)
784784
},
785785
})
786786
}
787+
788+
// issue-routing-tag: mysql/default
789+
func TestMysqlMysqlDbSystemResource_databaseManagement(t *testing.T) {
790+
httpreplay.SetScenario("TestMysqlMysqlDbSystemResource_databaseManagement")
791+
defer httpreplay.SaveScenario()
792+
793+
config := acctest.ProviderTestConfig()
794+
795+
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
796+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
797+
798+
resourceName := "oci_mysql_mysql_db_system.test_mysql_db_system"
799+
800+
var resId, resId2 string
801+
802+
updatedRepresentation := acctest.GetUpdatedRepresentationCopy("database_management", acctest.Representation{RepType: acctest.Optional, Create: `ENABLED`, Update: `DISABLED`},
803+
acctest.RepresentationCopyWithNewProperties(MysqlMysqlDbSystemRepresentation, map[string]interface{}{
804+
"backup_policy": acctest.RepresentationGroup{RepType: acctest.Optional, Group: MysqlDbSystemBackupPolicyNotUpdateableRepresentation},
805+
}))
806+
807+
acctest.ResourceTest(t, nil, []resource.TestStep{
808+
// verify Create with optional fields
809+
{
810+
Config: config + compartmentIdVariableStr + MysqlDbSystemSourceBackupResourceDependencies +
811+
acctest.GenerateResourceFromRepresentationMap("oci_mysql_mysql_db_system", "test_mysql_db_system", acctest.Optional, acctest.Create, updatedRepresentation),
812+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
813+
resource.TestCheckResourceAttr(resourceName, "database_management", "ENABLED"),
814+
815+
func(s *terraform.State) (err error) {
816+
resId, err = acctest.FromInstanceState(s, resourceName, "id")
817+
return err
818+
},
819+
),
820+
},
821+
822+
// verify updates to updatable parameters
823+
{
824+
Config: config + compartmentIdVariableStr + MysqlDbSystemSourceBackupResourceDependencies +
825+
acctest.GenerateResourceFromRepresentationMap("oci_mysql_mysql_db_system", "test_mysql_db_system", acctest.Optional, acctest.Update, updatedRepresentation),
826+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
827+
resource.TestCheckResourceAttr(resourceName, "database_management", "DISABLED"),
828+
829+
func(s *terraform.State) (err error) {
830+
resId2, err = acctest.FromInstanceState(s, resourceName, "id")
831+
if resId != resId2 {
832+
return fmt.Errorf("Resource recreated when it was supposed to be updated.")
833+
}
834+
return err
835+
},
836+
),
837+
},
838+
})
839+
}

internal/integrationtest/mysql_mysql_db_system_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ var (
3838
MysqlMysqlMysqlDbSystemDataSourceRepresentation = map[string]interface{}{
3939
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
4040
"configuration_id": acctest.Representation{RepType: acctest.Optional, Create: `${var.MysqlConfigurationOCID[var.region]}`},
41+
"database_management": acctest.Representation{RepType: acctest.Optional, Create: []oci_mysql.ListDbSystemsDatabaseManagementEnum{`ENABLED`}},
4142
"db_system_id": acctest.Representation{RepType: acctest.Optional, Create: `${oci_mysql_mysql_db_system.test_mysql_db_system.id}`},
4243
"display_name": acctest.Representation{RepType: acctest.Optional, Create: `DBSystem001`, Update: `displayName2`},
4344
"is_heat_wave_cluster_attached": acctest.Representation{RepType: acctest.Optional, Create: `false`},
@@ -60,6 +61,7 @@ var (
6061
"backup_policy": acctest.RepresentationGroup{RepType: acctest.Optional, Group: MysqlMysqlDbSystemBackupPolicyRepresentation},
6162
"crash_recovery": acctest.Representation{RepType: acctest.Optional, Create: `ENABLED`},
6263
"data_storage_size_in_gb": acctest.Representation{RepType: acctest.Required, Create: `50`},
64+
"database_management": acctest.Representation{RepType: acctest.Optional, Create: `ENABLED`},
6365
"defined_tags": acctest.Representation{RepType: acctest.Optional, Create: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "value")}`, Update: `${map("${oci_identity_tag_namespace.tag-namespace1.name}.${oci_identity_tag.tag1.name}", "updatedValue")}`},
6466
"deletion_policy": acctest.RepresentationGroup{RepType: acctest.Optional, Group: mysqlDbSystemDeletionPolicyRepresentation},
6567
"description": acctest.Representation{RepType: acctest.Optional, Create: `MySQL Database Service`, Update: `description2`},
@@ -188,6 +190,7 @@ func TestMysqlMysqlDbSystemResource_basic(t *testing.T) {
188190
resource.TestCheckResourceAttrSet(resourceName, "configuration_id"),
189191
resource.TestCheckResourceAttr(resourceName, "crash_recovery", "ENABLED"),
190192
resource.TestCheckResourceAttr(resourceName, "data_storage_size_in_gb", "50"),
193+
resource.TestCheckResourceAttr(resourceName, "database_management", "ENABLED"),
191194
resource.TestCheckResourceAttr(resourceName, "deletion_policy.#", "1"),
192195
resource.TestCheckResourceAttr(resourceName, "deletion_policy.0.automatic_backup_retention", "DELETE"),
193196
resource.TestCheckResourceAttr(resourceName, "deletion_policy.0.final_backup", "SKIP_FINAL_BACKUP"),
@@ -243,6 +246,7 @@ func TestMysqlMysqlDbSystemResource_basic(t *testing.T) {
243246
resource.TestCheckResourceAttrSet(resourceName, "configuration_id"),
244247
resource.TestCheckResourceAttr(resourceName, "crash_recovery", "ENABLED"),
245248
resource.TestCheckResourceAttr(resourceName, "data_storage_size_in_gb", "50"),
249+
resource.TestCheckResourceAttr(resourceName, "database_management", "ENABLED"),
246250
resource.TestCheckResourceAttr(resourceName, "deletion_policy.#", "1"),
247251
resource.TestCheckResourceAttr(resourceName, "deletion_policy.0.automatic_backup_retention", "RETAIN"),
248252
resource.TestCheckResourceAttr(resourceName, "deletion_policy.0.final_backup", "REQUIRE_FINAL_BACKUP"),
@@ -301,6 +305,7 @@ func TestMysqlMysqlDbSystemResource_basic(t *testing.T) {
301305
resource.TestCheckResourceAttr(datasourceName, "db_systems.0.compartment_id", compartmentId),
302306
resource.TestCheckResourceAttr(datasourceName, "db_systems.0.crash_recovery", "ENABLED"),
303307
resource.TestCheckResourceAttr(datasourceName, "db_systems.0.current_placement.#", "1"),
308+
resource.TestCheckResourceAttr(datasourceName, "db_systems.0.database_management", "ENABLED"),
304309
resource.TestCheckResourceAttr(datasourceName, "db_systems.0.deletion_policy.#", "1"),
305310
resource.TestCheckResourceAttr(datasourceName, "db_systems.0.deletion_policy.0.automatic_backup_retention", "RETAIN"),
306311
resource.TestCheckResourceAttr(datasourceName, "db_systems.0.deletion_policy.0.final_backup", "REQUIRE_FINAL_BACKUP"),
@@ -342,6 +347,7 @@ func TestMysqlMysqlDbSystemResource_basic(t *testing.T) {
342347
resource.TestCheckResourceAttr(singularDatasourceName, "crash_recovery", "ENABLED"),
343348
resource.TestCheckResourceAttr(singularDatasourceName, "current_placement.#", "1"),
344349
resource.TestCheckResourceAttr(singularDatasourceName, "data_storage_size_in_gb", "50"),
350+
resource.TestCheckResourceAttr(singularDatasourceName, "database_management", "ENABLED"),
345351
resource.TestCheckResourceAttr(singularDatasourceName, "deletion_policy.#", "1"),
346352
resource.TestCheckResourceAttr(singularDatasourceName, "deletion_policy.0.automatic_backup_retention", "RETAIN"),
347353
resource.TestCheckResourceAttr(singularDatasourceName, "deletion_policy.0.final_backup", "REQUIRE_FINAL_BACKUP"),
@@ -378,6 +384,8 @@ func TestMysqlMysqlDbSystemResource_basic(t *testing.T) {
378384
"admin_password",
379385
"admin_username",
380386
"shutdown_type",
387+
"time_created",
388+
"time_updated",
381389
},
382390
ResourceName: resourceName,
383391
},

internal/service/mysql/mysql_mysql_backup_resource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,10 @@ func MysqlMysqlBackupResource() *schema.Resource {
173173
Type: schema.TypeInt,
174174
Computed: true,
175175
},
176+
"database_management": {
177+
Type: schema.TypeString,
178+
Computed: true,
179+
},
176180
"defined_tags": {
177181
Type: schema.TypeMap,
178182
Computed: true,
@@ -731,6 +735,8 @@ func DbSystemSnapshotToMap(obj *oci_mysql.DbSystemSnapshot) map[string]interface
731735
result["data_storage_size_in_gb"] = int(*obj.DataStorageSizeInGBs)
732736
}
733737

738+
result["database_management"] = string(obj.DatabaseManagement)
739+
734740
if obj.DefinedTags != nil {
735741
result["defined_tags"] = tfresource.DefinedTagsToMap(obj.DefinedTags)
736742
}

internal/service/mysql/mysql_mysql_db_system_data_source.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ func (s *MysqlMysqlDbSystemDataSourceCrud) SetData() error {
102102
s.D.Set("data_storage_size_in_gb", *s.Res.DataStorageSizeInGBs)
103103
}
104104

105+
s.D.Set("database_management", s.Res.DatabaseManagement)
106+
105107
if s.Res.DefinedTags != nil {
106108
s.D.Set("defined_tags", tfresource.DefinedTagsToMap(s.Res.DefinedTags))
107109
}

internal/service/mysql/mysql_mysql_db_system_resource.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,11 @@ func MysqlMysqlDbSystemResource() *schema.Resource {
147147
Optional: true,
148148
Computed: true,
149149
},
150+
"database_management": {
151+
Type: schema.TypeString,
152+
Optional: true,
153+
Computed: true,
154+
},
150155
"defined_tags": {
151156
Type: schema.TypeMap,
152157
Optional: true,
@@ -781,6 +786,7 @@ func (s *MysqlMysqlDbSystemResourceCrud) ID() string {
781786
func (s *MysqlMysqlDbSystemResourceCrud) CreatedPending() []string {
782787
return []string{
783788
string(oci_mysql.DbSystemLifecycleStateCreating),
789+
string(oci_mysql.DbSystemLifecycleStateUpdating),
784790
}
785791
}
786792

@@ -862,6 +868,10 @@ func (s *MysqlMysqlDbSystemResourceCrud) Create() error {
862868
request.DataStorageSizeInGBs = &tmp
863869
}
864870

871+
if databaseManagement, ok := s.D.GetOkExists("database_management"); ok {
872+
request.DatabaseManagement = oci_mysql.DatabaseManagementStatusEnum(databaseManagement.(string))
873+
}
874+
865875
if definedTags, ok := s.D.GetOkExists("defined_tags"); ok {
866876
convertedDefinedTags, err := tfresource.MapToDefinedTags(definedTags.(map[string]interface{}))
867877
if err != nil {
@@ -1021,6 +1031,10 @@ func (s *MysqlMysqlDbSystemResourceCrud) Update() error {
10211031
request.DataStorageSizeInGBs = &tmp
10221032
}
10231033

1034+
if databaseManagement, ok := s.D.GetOkExists("database_management"); ok && s.D.HasChange("database_management") {
1035+
request.DatabaseManagement = oci_mysql.DatabaseManagementStatusEnum(databaseManagement.(string))
1036+
}
1037+
10241038
if definedTags, ok := s.D.GetOkExists("defined_tags"); ok && s.D.HasChange("defined_tags") {
10251039
convertedDefinedTags, err := tfresource.MapToDefinedTags(definedTags.(map[string]interface{}))
10261040
if err != nil {
@@ -1134,6 +1148,8 @@ func (s *MysqlMysqlDbSystemResourceCrud) SetData() error {
11341148
s.D.Set("data_storage_size_in_gb", *s.Res.DataStorageSizeInGBs)
11351149
}
11361150

1151+
s.D.Set("database_management", s.Res.DatabaseManagement)
1152+
11371153
if s.Res.DefinedTags != nil {
11381154
s.D.Set("defined_tags", tfresource.DefinedTagsToMap(s.Res.DefinedTags))
11391155
}

internal/service/mysql/mysql_mysql_db_systems_data_source.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ func MysqlMysqlDbSystemsDataSource() *schema.Resource {
2626
Type: schema.TypeString,
2727
Optional: true,
2828
},
29+
"database_management": {
30+
Type: schema.TypeList,
31+
Optional: true,
32+
Elem: &schema.Schema{
33+
Type: schema.TypeString,
34+
},
35+
},
2936
"db_system_id": {
3037
Type: schema.TypeString,
3138
Optional: true,
@@ -86,6 +93,19 @@ func (s *MysqlMysqlDbSystemsDataSourceCrud) Get() error {
8693
request.ConfigurationId = &tmp
8794
}
8895

96+
if databaseManagement, ok := s.D.GetOkExists("database_management"); ok {
97+
interfaces := databaseManagement.([]interface{})
98+
tmp := make([]oci_mysql.ListDbSystemsDatabaseManagementEnum, len(interfaces))
99+
for i := range interfaces {
100+
if interfaces[i] != nil {
101+
tmp[i] = interfaces[i].(oci_mysql.ListDbSystemsDatabaseManagementEnum)
102+
}
103+
}
104+
if len(tmp) != 0 || s.D.HasChange("database_management") {
105+
request.DatabaseManagement = tmp
106+
}
107+
}
108+
89109
if dbSystemId, ok := s.D.GetOkExists("db_system_id"); ok {
90110
tmp := dbSystemId.(string)
91111
request.DbSystemId = &tmp
@@ -164,6 +184,8 @@ func (s *MysqlMysqlDbSystemsDataSourceCrud) SetData() error {
164184
mysqlDbSystem["current_placement"] = nil
165185
}
166186

187+
mysqlDbSystem["database_management"] = r.DatabaseManagement
188+
167189
if r.DefinedTags != nil {
168190
mysqlDbSystem["defined_tags"] = tfresource.DefinedTagsToMap(r.DefinedTags)
169191
}

website/docs/d/mysql_mysql_backup.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ The following attributes are exported:
7272
* `configuration_id` - The OCID of the Configuration to be used for Instances in this DB System.
7373
* `crash_recovery` - 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.
7474
* `data_storage_size_in_gb` - Initial size of the data volume in GiBs that will be created and attached.
75+
* `database_management` - Whether to enable monitoring via the Database Management service.
7576
* `defined_tags` - Defined tags for this resource. Each key is predefined and scoped to a namespace. Example: `{"foo-namespace.bar-key": "value"}`
7677
* `deletion_policy` - The Deletion policy for the DB System.
7778
* `automatic_backup_retention` - Specifies if any automatic backups created for a DB System should be retained or deleted when the DB System is deleted.

website/docs/d/mysql_mysql_backups.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ The following attributes are exported:
9191
* `configuration_id` - The OCID of the Configuration to be used for Instances in this DB System.
9292
* `crash_recovery` - 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.
9393
* `data_storage_size_in_gb` - Initial size of the data volume in GiBs that will be created and attached.
94+
* `database_management` - Whether to enable monitoring via the Database Management service.
9495
* `defined_tags` - Defined tags for this resource. Each key is predefined and scoped to a namespace. Example: `{"foo-namespace.bar-key": "value"}`
9596
* `deletion_policy` - The Deletion policy for the DB System.
9697
* `automatic_backup_retention` - Specifies if any automatic backups created for a DB System should be retained or deleted when the DB System is deleted.

website/docs/d/mysql_mysql_db_system.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ The following attributes are exported:
108108
* `availability_domain` - The availability domain in which the DB System is placed.
109109
* `fault_domain` - The fault domain in which the DB System is placed.
110110
* `data_storage_size_in_gb` - Initial size of the data volume in GiBs that will be created and attached.
111+
* `database_management` - Whether to enable monitoring via the Database Management service.
111112
* `defined_tags` - Defined tags for this resource. Each key is predefined and scoped to a namespace. Example: `{"foo-namespace.bar-key": "value"}`
112113
* `deletion_policy` - The Deletion policy for the DB System.
113114
* `automatic_backup_retention` - Specifies if any automatic backups created for a DB System should be retained or deleted when the DB System is deleted.

0 commit comments

Comments
 (0)