Skip to content

Commit 332373d

Browse files
Vinicius MonteiroNagaRajuPasunuri
authored andcommitted
Added - Support for HeatWave MySQL Service: Configurable Version Upgrade Policies
1 parent ed5bce2 commit 332373d

11 files changed

+278
-0
lines changed

examples/mysql/main.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,9 @@ resource "oci_mysql_mysql_db_system" "test_mysql_db_system" {
127127

128128
maintenance {
129129
window_start_time = "sun 01:00"
130+
maintenance_schedule_type = "REGULAR"
131+
version_preference = "OLDEST"
132+
version_track_preference = "FOLLOW"
130133
}
131134

132135
nsg_ids = [oci_core_network_security_group.test_network_security_group.id]
@@ -187,6 +190,7 @@ data "oci_mysql_mysql_configurations" "test_mysql_configurations" {
187190
#Optional
188191
state = "ACTIVE"
189192
shape_name = "MySQL.VM.Standard.E3.1.8GB"
193+
display_name = "MySQL.VM.Standard.E3.1.8GB.Standalone"
190194
}
191195

192196
data "oci_mysql_mysql_backups" "test_mysql_backups" {
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
// Copyright (c) 2025, Oracle and/or its affiliates. All rights reserved.
2+
3+
package integrationtest
4+
5+
import (
6+
"fmt"
7+
"testing"
8+
9+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
10+
"github.com/hashicorp/terraform-plugin-testing/terraform"
11+
12+
"github.com/oracle/terraform-provider-oci/httpreplay"
13+
"github.com/oracle/terraform-provider-oci/internal/acctest"
14+
"github.com/oracle/terraform-provider-oci/internal/utils"
15+
)
16+
17+
var (
18+
mysqlDbSystemMaintenance = map[string]interface{}{
19+
// standard required properties
20+
"admin_password": acctest.Representation{RepType: acctest.Required, Create: `BEstrO0ng_#11`},
21+
"admin_username": acctest.Representation{RepType: acctest.Required, Create: `adminUser`},
22+
"availability_domain": acctest.Representation{RepType: acctest.Required, Create: `${data.oci_identity_availability_domains.test_availability_domains.availability_domains.0.name}`},
23+
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
24+
"shape_name": acctest.Representation{RepType: acctest.Required, Create: `MySQL.2`},
25+
"subnet_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_core_subnet.test_subnet.id}`},
26+
"data_storage_size_in_gb": acctest.Representation{RepType: acctest.Required, Create: `50`},
27+
28+
// use an easier to track display name
29+
"display_name": acctest.Representation{RepType: acctest.Optional, Create: `TestDbSystemMaintenanceCvup`},
30+
31+
// avoid wasting time setting up DBM when that's not what we're testing here
32+
"database_management": acctest.Representation{RepType: acctest.Optional, Create: `DISABLED`},
33+
34+
// disable backup policy to avoid wasting even more time and resources
35+
"backup_policy": acctest.RepresentationGroup{RepType: acctest.Required, Group: disabledBackupPolicy},
36+
37+
// create with custom maintenance details and then change the values on update
38+
"maintenance": acctest.RepresentationGroup{RepType: acctest.Optional, Group: mysqlDbSystemMaintenanceRepresentation},
39+
}
40+
41+
mysqlDbSystemMaintenanceRepresentation = map[string]interface{}{
42+
"window_start_time": acctest.Representation{RepType: acctest.Required, Create: `sun 01:00`},
43+
"maintenance_schedule_type": acctest.Representation{RepType: acctest.Optional, Create: `EARLY`, Update: `REGULAR`},
44+
"version_preference": acctest.Representation{RepType: acctest.Optional, Create: `OLDEST`, Update: `SECOND_NEWEST`},
45+
"version_track_preference": acctest.Representation{RepType: acctest.Optional, Create: `LONG_TERM_SUPPORT`, Update: `INNOVATION`},
46+
}
47+
)
48+
49+
func TestMysqlMysqlDbSystemResource_maintenance(t *testing.T) {
50+
httpreplay.SetScenario("TestMysqlMysqlDbSystemResource_maintenance")
51+
defer httpreplay.SaveScenario()
52+
53+
config := acctest.ProviderTestConfig()
54+
55+
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
56+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
57+
58+
resourceName := "oci_mysql_mysql_db_system.test_mysql_db_system"
59+
60+
var resId, resId2 string
61+
62+
acctest.ResourceTest(t, nil, []resource.TestStep{
63+
// verify Create with custom CVUP values
64+
{
65+
Config: config + compartmentIdVariableStr + MysqlMysqlDbSystemResourceDependencies +
66+
acctest.GenerateResourceFromRepresentationMap("oci_mysql_mysql_db_system", "test_mysql_db_system", acctest.Optional, acctest.Create, mysqlDbSystemMaintenance),
67+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
68+
resource.TestCheckResourceAttr(resourceName, "maintenance.#", "1"),
69+
resource.TestCheckResourceAttr(resourceName, "maintenance.0.maintenance_schedule_type", "EARLY"),
70+
resource.TestCheckResourceAttr(resourceName, "maintenance.0.version_preference", "OLDEST"),
71+
resource.TestCheckResourceAttr(resourceName, "maintenance.0.version_track_preference", "LONG_TERM_SUPPORT"),
72+
resource.TestCheckResourceAttrSet(resourceName, "maintenance.0.target_version"),
73+
resource.TestCheckResourceAttrSet(resourceName, "maintenance.0.time_scheduled"),
74+
resource.TestCheckResourceAttr(resourceName, "maintenance.0.window_start_time", "sun 01:00"),
75+
76+
func(s *terraform.State) (err error) {
77+
resId, err = acctest.FromInstanceState(s, resourceName, "id")
78+
return err
79+
},
80+
),
81+
},
82+
83+
// verify it is possible to change the CVUP details
84+
{
85+
Config: config + compartmentIdVariableStr + MysqlMysqlDbSystemResourceDependencies +
86+
acctest.GenerateResourceFromRepresentationMap("oci_mysql_mysql_db_system", "test_mysql_db_system", acctest.Optional, acctest.Update, mysqlDbSystemMaintenance),
87+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
88+
resource.TestCheckResourceAttr(resourceName, "maintenance.#", "1"),
89+
resource.TestCheckResourceAttr(resourceName, "maintenance.0.maintenance_schedule_type", "REGULAR"),
90+
resource.TestCheckResourceAttr(resourceName, "maintenance.0.version_preference", "SECOND_NEWEST"),
91+
resource.TestCheckResourceAttr(resourceName, "maintenance.0.version_track_preference", "INNOVATION"),
92+
resource.TestCheckResourceAttrSet(resourceName, "maintenance.0.target_version"),
93+
resource.TestCheckResourceAttrSet(resourceName, "maintenance.0.time_scheduled"),
94+
resource.TestCheckResourceAttr(resourceName, "maintenance.0.window_start_time", "sun 01:00"),
95+
96+
func(s *terraform.State) (err error) {
97+
resId2, err = acctest.FromInstanceState(s, resourceName, "id")
98+
if resId != resId2 {
99+
return fmt.Errorf("Resource recreated when it was supposed to be updated.")
100+
}
101+
return err
102+
},
103+
),
104+
},
105+
106+
// clear before next Create
107+
{
108+
Config: config + compartmentIdVariableStr + MysqlMysqlDbSystemResourceDependencies,
109+
},
110+
111+
// verify Create with default CVUP values
112+
{
113+
Config: config + compartmentIdVariableStr + MysqlMysqlDbSystemResourceDependencies +
114+
acctest.GenerateResourceFromRepresentationMap("oci_mysql_mysql_db_system", "test_mysql_db_system", acctest.Optional, acctest.Create, MysqlMysqlDbSystemRepresentation),
115+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
116+
resource.TestCheckResourceAttr(resourceName, "maintenance.#", "1"),
117+
resource.TestCheckResourceAttr(resourceName, "maintenance.0.maintenance_schedule_type", "REGULAR"),
118+
resource.TestCheckResourceAttr(resourceName, "maintenance.0.version_preference", "OLDEST"),
119+
resource.TestCheckResourceAttr(resourceName, "maintenance.0.version_track_preference", "FOLLOW"),
120+
resource.TestCheckResourceAttrSet(resourceName, "maintenance.0.target_version"),
121+
resource.TestCheckResourceAttrSet(resourceName, "maintenance.0.time_scheduled"),
122+
resource.TestCheckResourceAttr(resourceName, "maintenance.0.window_start_time", "sun 01:00"),
123+
124+
func(s *terraform.State) (err error) {
125+
resId, err = acctest.FromInstanceState(s, resourceName, "id")
126+
return err
127+
},
128+
),
129+
},
130+
})
131+
}

internal/integrationtest/mysql_mysql_db_system_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ func TestMysqlMysqlDbSystemResource_basic(t *testing.T) {
236236
resource.TestCheckResourceAttr(resourceName, "ip_address", "10.0.0.3"),
237237
resource.TestCheckResourceAttr(resourceName, "is_highly_available", "false"),
238238
resource.TestCheckResourceAttr(resourceName, "maintenance.#", "1"),
239+
resource.TestCheckResourceAttr(resourceName, "maintenance.0.maintenance_schedule_type", "REGULAR"),
240+
resource.TestCheckResourceAttr(resourceName, "maintenance.0.version_preference", "OLDEST"),
241+
resource.TestCheckResourceAttr(resourceName, "maintenance.0.version_track_preference", "FOLLOW"),
242+
resource.TestCheckResourceAttrSet(resourceName, "maintenance.0.target_version"),
243+
resource.TestCheckResourceAttrSet(resourceName, "maintenance.0.time_scheduled"),
239244
resource.TestCheckResourceAttr(resourceName, "maintenance.0.window_start_time", "sun 01:00"),
240245
resource.TestCheckResourceAttr(resourceName, "port", "3306"),
241246
resource.TestCheckResourceAttr(resourceName, "port_x", "33306"),
@@ -429,6 +434,11 @@ func TestMysqlMysqlDbSystemResource_basic(t *testing.T) {
429434
resource.TestCheckResourceAttr(singularDatasourceName, "is_heat_wave_cluster_attached", "false"),
430435
resource.TestCheckResourceAttr(singularDatasourceName, "is_highly_available", "false"),
431436
resource.TestCheckResourceAttr(singularDatasourceName, "maintenance.#", "1"),
437+
resource.TestCheckResourceAttr(singularDatasourceName, "maintenance.0.maintenance_schedule_type", "REGULAR"),
438+
resource.TestCheckResourceAttr(singularDatasourceName, "maintenance.0.version_preference", "OLDEST"),
439+
resource.TestCheckResourceAttr(singularDatasourceName, "maintenance.0.version_track_preference", "FOLLOW"),
440+
resource.TestCheckResourceAttrSet(singularDatasourceName, "maintenance.0.target_version"),
441+
resource.TestCheckResourceAttrSet(singularDatasourceName, "maintenance.0.time_scheduled"),
432442
resource.TestCheckResourceAttr(singularDatasourceName, "maintenance.0.window_start_time", "sun 01:00"),
433443
resource.TestCheckResourceAttrSet(singularDatasourceName, "mysql_version"),
434444
resource.TestCheckResourceAttr(singularDatasourceName, "port", "3306"),

internal/service/mysql/mysql_mysql_backup_resource.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,26 @@ func MysqlMysqlBackupResource() *schema.Resource {
492492
// Optional
493493

494494
// Computed
495+
"maintenance_schedule_type": {
496+
Type: schema.TypeString,
497+
Computed: true,
498+
},
499+
"target_version": {
500+
Type: schema.TypeString,
501+
Computed: true,
502+
},
503+
"time_scheduled": {
504+
Type: schema.TypeString,
505+
Computed: true,
506+
},
507+
"version_preference": {
508+
Type: schema.TypeString,
509+
Computed: true,
510+
},
511+
"version_track_preference": {
512+
Type: schema.TypeString,
513+
Computed: true,
514+
},
495515
"window_start_time": {
496516
Type: schema.TypeString,
497517
Computed: true,
@@ -1453,6 +1473,20 @@ func DbSystemSnapshotSummaryToMap(obj *oci_mysql.DbSystemSnapshotSummary) map[st
14531473
func MaintenanceDetailsToMap(obj *oci_mysql.MaintenanceDetails) map[string]interface{} {
14541474
result := map[string]interface{}{}
14551475

1476+
result["maintenance_schedule_type"] = string(obj.MaintenanceScheduleType)
1477+
1478+
if obj.TargetVersion != nil {
1479+
result["target_version"] = string(*obj.TargetVersion)
1480+
}
1481+
1482+
if obj.TimeScheduled != nil {
1483+
result["time_scheduled"] = obj.TimeScheduled.String()
1484+
}
1485+
1486+
result["version_preference"] = string(obj.VersionPreference)
1487+
1488+
result["version_track_preference"] = string(obj.VersionTrackPreference)
1489+
14561490
if obj.WindowStartTime != nil {
14571491
result["window_start_time"] = string(*obj.WindowStartTime)
14581492
}

internal/service/mysql/mysql_mysql_db_system_resource.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,31 @@ func MysqlMysqlDbSystemResource() *schema.Resource {
365365
},
366366

367367
// Optional
368+
"maintenance_schedule_type": {
369+
Type: schema.TypeString,
370+
Optional: true,
371+
Computed: true,
372+
},
373+
"version_preference": {
374+
Type: schema.TypeString,
375+
Optional: true,
376+
Computed: true,
377+
},
378+
"version_track_preference": {
379+
Type: schema.TypeString,
380+
Optional: true,
381+
Computed: true,
382+
},
368383

369384
// Computed
385+
"target_version": {
386+
Type: schema.TypeString,
387+
Computed: true,
388+
},
389+
"time_scheduled": {
390+
Type: schema.TypeString,
391+
Computed: true,
392+
},
370393
},
371394
},
372395
},
@@ -2273,6 +2296,18 @@ func (s *MysqlMysqlDbSystemResourceCrud) mapToUpdateDeletionPolicyDetails(fieldK
22732296
func (s *MysqlMysqlDbSystemResourceCrud) mapToCreateMaintenanceDetails(fieldKeyFormat string) (oci_mysql.CreateMaintenanceDetails, error) {
22742297
result := oci_mysql.CreateMaintenanceDetails{}
22752298

2299+
if maintenanceScheduleType, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "maintenance_schedule_type")); ok {
2300+
result.MaintenanceScheduleType = oci_mysql.MaintenanceScheduleTypeEnum(maintenanceScheduleType.(string))
2301+
}
2302+
2303+
if versionPreference, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "version_preference")); ok {
2304+
result.VersionPreference = oci_mysql.VersionPreferenceEnum(versionPreference.(string))
2305+
}
2306+
2307+
if versionTrackPreference, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "version_track_preference")); ok {
2308+
result.VersionTrackPreference = oci_mysql.VersionTrackPreferenceEnum(versionTrackPreference.(string))
2309+
}
2310+
22762311
if windowStartTime, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "window_start_time")); ok {
22772312
tmp := windowStartTime.(string)
22782313
result.WindowStartTime = &tmp
@@ -2673,6 +2708,18 @@ func (s *MysqlMysqlDbSystemResourceCrud) mapToUpdateBackupPolicyDetails(fieldKey
26732708
func (s *MysqlMysqlDbSystemResourceCrud) mapToUpdateMaintenanceDetails(fieldKeyFormat string) (oci_mysql.UpdateMaintenanceDetails, error) {
26742709
result := oci_mysql.UpdateMaintenanceDetails{}
26752710

2711+
if maintenanceScheduleType, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "maintenance_schedule_type")); ok {
2712+
result.MaintenanceScheduleType = oci_mysql.MaintenanceScheduleTypeEnum(maintenanceScheduleType.(string))
2713+
}
2714+
2715+
if versionPreference, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "version_preference")); ok {
2716+
result.VersionPreference = oci_mysql.VersionPreferenceEnum(versionPreference.(string))
2717+
}
2718+
2719+
if versionTrackPreference, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "version_track_preference")); ok {
2720+
result.VersionTrackPreference = oci_mysql.VersionTrackPreferenceEnum(versionTrackPreference.(string))
2721+
}
2722+
26762723
if windowStartTime, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "window_start_time")); ok {
26772724
tmp := windowStartTime.(string)
26782725
result.WindowStartTime = &tmp

website/docs/d/mysql_mysql_backup.html.markdown

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,13 @@ The following attributes are exported:
129129
* `ip_address` - The IP address the DB System is configured to listen on. A private IP address of the primary endpoint of the DB System. Must be an available IP address within the subnet's CIDR. This will be a "dotted-quad" style IPv4 address.
130130
* `is_highly_available` - Specifies if the DB System is highly available.
131131
* `maintenance` - The Maintenance Policy for the DB System or Read Replica that this model is included in.
132+
* `maintenance_schedule_type` - The maintenance schedule type of the DB system. EARLY: Maintenance schedule follows a cycle where upgrades are performed when versions become deprecated. REGULAR: Maintenance schedule follows the normal cycle where upgrades are performed when versions become unavailable.
133+
* `target_version` - The version that is expected to be targeted during the next scheduled maintenance run.
134+
* `time_scheduled` - The time the scheduled maintenance is expected to start, as described by [RFC 3339](https://tools.ietf.org/rfc/rfc3339).
135+
* `version_preference` - The preferred version to target when performing an automatic MySQL upgrade.
136+
137+
OLDEST: Choose the oldest available MySQL version based on the current version of the DB System. SECOND_NEWEST: Choose the MySQL version before the newest for auto-upgrade. NEWEST: Choose the latest and greatest MySQL version available for auto-upgrade.
138+
* `version_track_preference` - The preferred version track to target when performing an automatic MySQL upgrade. LONG_TERM_SUPPORT: No MySQL database behavior changes. INNOVATION: Provides access to the latest features and all bug fixes. FOLLOW: Follows the track of the current MySQL version.
132139
* `window_start_time` - The start time of the maintenance window.
133140

134141
This string is of the format: "{day-of-week} {time-of-day}".

website/docs/d/mysql_mysql_backups.html.markdown

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,13 @@ The following attributes are exported:
150150
* `ip_address` - The IP address the DB System is configured to listen on. A private IP address of the primary endpoint of the DB System. Must be an available IP address within the subnet's CIDR. This will be a "dotted-quad" style IPv4 address.
151151
* `is_highly_available` - Specifies if the DB System is highly available.
152152
* `maintenance` - The Maintenance Policy for the DB System or Read Replica that this model is included in.
153+
* `maintenance_schedule_type` - The maintenance schedule type of the DB system. EARLY: Maintenance schedule follows a cycle where upgrades are performed when versions become deprecated. REGULAR: Maintenance schedule follows the normal cycle where upgrades are performed when versions become unavailable.
154+
* `target_version` - The version that is expected to be targeted during the next scheduled maintenance run.
155+
* `time_scheduled` - The time the scheduled maintenance is expected to start, as described by [RFC 3339](https://tools.ietf.org/rfc/rfc3339).
156+
* `version_preference` - The preferred version to target when performing an automatic MySQL upgrade.
157+
158+
OLDEST: Choose the oldest available MySQL version based on the current version of the DB System. SECOND_NEWEST: Choose the MySQL version before the newest for auto-upgrade. NEWEST: Choose the latest and greatest MySQL version available for auto-upgrade.
159+
* `version_track_preference` - The preferred version track to target when performing an automatic MySQL upgrade. LONG_TERM_SUPPORT: No MySQL database behavior changes. INNOVATION: Provides access to the latest features and all bug fixes. FOLLOW: Follows the track of the current MySQL version.
153160
* `window_start_time` - The start time of the maintenance window.
154161

155162
This string is of the format: "{day-of-week} {time-of-day}".

website/docs/d/mysql_mysql_db_system.html.markdown

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,13 @@ The following attributes are exported:
179179
* `is_highly_available` - Specifies if the DB System is highly available.
180180
* `lifecycle_details` - Additional information about the current lifecycleState.
181181
* `maintenance` - The Maintenance Policy for the DB System or Read Replica that this model is included in.
182+
* `maintenance_schedule_type` - The maintenance schedule type of the DB system. EARLY: Maintenance schedule follows a cycle where upgrades are performed when versions become deprecated. REGULAR: Maintenance schedule follows the normal cycle where upgrades are performed when versions become unavailable.
183+
* `target_version` - The version that is expected to be targeted during the next scheduled maintenance run.
184+
* `time_scheduled` - The time the scheduled maintenance is expected to start, as described by [RFC 3339](https://tools.ietf.org/rfc/rfc3339).
185+
* `version_preference` - The preferred version to target when performing an automatic MySQL upgrade.
186+
187+
OLDEST: Choose the oldest available MySQL version based on the current version of the DB System. SECOND_NEWEST: Choose the MySQL version before the newest for auto-upgrade. NEWEST: Choose the latest and greatest MySQL version available for auto-upgrade.
188+
* `version_track_preference` - The preferred version track to target when performing an automatic MySQL upgrade. LONG_TERM_SUPPORT: No MySQL database behavior changes. INNOVATION: Provides access to the latest features and all bug fixes. FOLLOW: Follows the track of the current MySQL version.
182189
* `window_start_time` - The start time of the maintenance window.
183190

184191
This string is of the format: "{day-of-week} {time-of-day}".

0 commit comments

Comments
 (0)