Skip to content

Commit 13c5eb2

Browse files
govindrao55srishtipmishra
authored andcommitted
Support for Non-Rolling patch mode added to database_maintenance_run_resource
1 parent 0a24476 commit 13c5eb2

11 files changed

+76
-16
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
- Support for Generic Artifacts Service
1010
- Support Update `DrgAttachment` of types `Virtual_Circuit`, `RPC` and `IPSec`
1111
- Support for E3 Flex Notebooks added to `datascience`
12+
- Support for Non-Rolling patch mode added to `database_maintenance_run_resource`
1213

1314
## 4.27.0 (May 19, 2021)
1415

oci/database_maintenance_run_data_source.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,16 @@ func (s *DatabaseMaintenanceRunDataSourceCrud) SetData() error {
8888

8989
s.D.Set("maintenance_type", s.Res.MaintenanceType)
9090

91+
if s.Res.PatchFailureCount != nil {
92+
s.D.Set("patch_failure_count", *s.Res.PatchFailureCount)
93+
}
94+
9195
if s.Res.PatchId != nil {
9296
s.D.Set("patch_id", *s.Res.PatchId)
9397
}
9498

99+
s.D.Set("patching_mode", s.Res.PatchingMode)
100+
95101
if s.Res.PeerMaintenanceRunId != nil {
96102
s.D.Set("peer_maintenance_run_id", *s.Res.PeerMaintenanceRunId)
97103
}

oci/database_maintenance_run_resource.go

Lines changed: 40 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,11 @@ func DatabaseMaintenanceRunResource() *schema.Resource {
5151
Optional: true,
5252
Computed: true,
5353
},
54+
"patching_mode": {
55+
Type: schema.TypeString,
56+
Optional: true,
57+
Computed: true,
58+
},
5459
"time_scheduled": {
5560
Type: schema.TypeString,
5661
Optional: true,
@@ -83,6 +88,10 @@ func DatabaseMaintenanceRunResource() *schema.Resource {
8388
Type: schema.TypeString,
8489
Computed: true,
8590
},
91+
"patch_failure_count": {
92+
Type: schema.TypeInt,
93+
Computed: true,
94+
},
8695
"peer_maintenance_run_id": {
8796
Type: schema.TypeString,
8897
Computed: true,
@@ -146,6 +155,10 @@ type DatabaseMaintenanceRunResourceCrud struct {
146155
DisableNotFoundRetries bool
147156
}
148157

158+
type DatabaseMaintenanceUpdateResource struct {
159+
Details *oci_database.UpdateMaintenanceRunDetails
160+
}
161+
149162
func (s *DatabaseMaintenanceRunResourceCrud) ID() string {
150163
return *s.Res.Id
151164
}
@@ -201,6 +214,10 @@ func (s *DatabaseMaintenanceRunResourceCrud) Create() error {
201214
request.PatchId = &tmp
202215
}
203216

217+
if patchingMode, ok := s.D.GetOkExists("patching_mode"); ok {
218+
request.PatchingMode = oci_database.UpdateMaintenanceRunDetailsPatchingModeEnum(patchingMode.(string))
219+
}
220+
204221
if timeScheduled, ok := s.D.GetOkExists("time_scheduled"); ok {
205222
tmp, err := time.Parse(time.RFC3339, timeScheduled.(string))
206223
if err != nil {
@@ -243,26 +260,31 @@ func (s *DatabaseMaintenanceRunResourceCrud) Get() error {
243260
}
244261

245262
func (s *DatabaseMaintenanceRunResourceCrud) Update() error {
263+
246264
request := oci_database.UpdateMaintenanceRunRequest{}
247265

248-
if isEnabled, ok := s.D.GetOkExists("is_enabled"); ok {
266+
if isEnabled, ok := s.D.GetOkExists("is_enabled"); ok && s.D.HasChange("is_enabled") {
249267
tmp := isEnabled.(bool)
250268
request.IsEnabled = &tmp
251269
}
252270

253-
if isPatchNowEnabled, ok := s.D.GetOkExists("is_patch_now_enabled"); ok {
271+
if isPatchNowEnabled, ok := s.D.GetOkExists("is_patch_now_enabled"); ok && s.D.HasChange("is_patch_now_enabled") {
254272
tmp := isPatchNowEnabled.(bool)
255273
request.IsPatchNowEnabled = &tmp
256274
}
257275

258276
tmp := s.D.Id()
259277
request.MaintenanceRunId = &tmp
260278

261-
if patchId, ok := s.D.GetOkExists("patch_id"); ok {
279+
if patchId, ok := s.D.GetOkExists("patch_id"); ok && s.D.HasChange("patchId") {
262280
tmp := patchId.(string)
263281
request.PatchId = &tmp
264282
}
265283

284+
if patchingMode, ok := s.D.GetOkExists("patching_mode"); ok && s.D.HasChange("patching_mode") {
285+
request.PatchingMode = oci_database.UpdateMaintenanceRunDetailsPatchingModeEnum(patchingMode.(string))
286+
}
287+
266288
if timeScheduled, ok := s.D.GetOkExists("time_scheduled"); ok {
267289
tmp, err := time.Parse(time.RFC3339, timeScheduled.(string))
268290
if err != nil {
@@ -273,13 +295,18 @@ func (s *DatabaseMaintenanceRunResourceCrud) Update() error {
273295

274296
request.RequestMetadata.RetryPolicy = getRetryPolicy(s.DisableNotFoundRetries, "database")
275297

276-
response, err := s.Client.UpdateMaintenanceRun(context.Background(), request)
298+
_, err := s.Client.UpdateMaintenanceRun(context.Background(), request)
277299
if err != nil {
278300
return err
279301
}
280-
281-
s.Res = &response.MaintenanceRun
282-
return nil
302+
// Workaround: Sleep for some time before polling the configuration. Because update happens asynchronously, polling too
303+
// soon may result in service returning stale configuration values.
304+
time.Sleep(time.Second * 10)
305+
306+
// Requests to update may succeed instantly but may not see the actual update take effect
307+
// until minutes later. Add polling here to return only when the change has taken effect.
308+
maintenanceRunUpdatePatchingModeFunc := func() bool { return s.Res.LifecycleState != oci_database.MaintenanceRunLifecycleStateUpdating }
309+
return WaitForResourceCondition(s, maintenanceRunUpdatePatchingModeFunc, s.D.Timeout(schema.TimeoutUpdate))
283310
}
284311

285312
func (s *DatabaseMaintenanceRunResourceCrud) SetData() error {
@@ -303,10 +330,16 @@ func (s *DatabaseMaintenanceRunResourceCrud) SetData() error {
303330

304331
s.D.Set("maintenance_type", s.Res.MaintenanceType)
305332

333+
if s.Res.PatchFailureCount != nil {
334+
s.D.Set("patch_failure_count", *s.Res.PatchFailureCount)
335+
}
336+
306337
if s.Res.PatchId != nil {
307338
s.D.Set("patch_id", *s.Res.PatchId)
308339
}
309340

341+
s.D.Set("patching_mode", s.Res.PatchingMode)
342+
310343
if s.Res.PeerMaintenanceRunId != nil {
311344
s.D.Set("peer_maintenance_run_id", *s.Res.PeerMaintenanceRunId)
312345
}

oci/database_maintenance_run_test.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@ var (
3131

3232
maintenanceRunRepresentation = map[string]interface{}{
3333
"maintenance_run_id": Representation{repType: Required, create: `${var.maintenance_run_id}`},
34-
"is_enabled": Representation{repType: Required, create: `false`, update: `true`},
35-
"is_patch_now_enabled": Representation{repType: Optional, update: `true`},
34+
"is_enabled": Representation{repType: Required, create: `true`},
35+
"is_patch_now_enabled": Representation{repType: Optional},
3636
"patch_id": Representation{repType: Optional, create: `${var.maintenance_run_patch_id}`},
37-
"time_scheduled": Representation{repType: Optional, create: mrTimeScheduledCreate.Format(time.RFC3339Nano), update: mrTimeScheduledUpdate.Format(time.RFC3339Nano)},
37+
"patching_mode": Representation{repType: Optional, create: `ROLLING`, update: `NONROLLING`},
38+
"time_scheduled": Representation{repType: Required, create: mrTimeScheduledCreate.Format(time.RFC3339Nano), update: mrTimeScheduledUpdate.Format(time.RFC3339Nano)},
3839
}
3940

4041
MaintenanceRunResourceDependencies = ""
@@ -90,6 +91,7 @@ func TestDatabaseMaintenanceRunResource_basic(t *testing.T) {
9091
{
9192
Config: config + compartmentIdVariableStr + maintenanceRunIdVariableStr + patchIdVariableStr + MaintenanceRunResourceDependencies,
9293
},
94+
9395
// verify create with optionals
9496
{
9597
Config: config + compartmentIdVariableStr + maintenanceRunIdVariableStr + patchIdVariableStr + MaintenanceRunResourceDependencies +
@@ -98,9 +100,10 @@ func TestDatabaseMaintenanceRunResource_basic(t *testing.T) {
98100
resource.TestCheckResourceAttrSet(resourceName, "compartment_id"),
99101
resource.TestCheckResourceAttrSet(resourceName, "display_name"),
100102
resource.TestCheckResourceAttrSet(resourceName, "id"),
101-
resource.TestCheckResourceAttr(resourceName, "is_enabled", "false"),
103+
resource.TestCheckResourceAttr(resourceName, "is_enabled", "true"),
102104
resource.TestCheckResourceAttrSet(resourceName, "maintenance_run_id"),
103105
resource.TestCheckResourceAttrSet(resourceName, "patch_id"),
106+
resource.TestCheckResourceAttr(resourceName, "patching_mode", "ROLLING"),
104107
resource.TestCheckResourceAttrSet(resourceName, "state"),
105108
resource.TestCheckResourceAttr(resourceName, "time_scheduled", mrTimeScheduledCreate.Format(time.RFC3339Nano)),
106109

@@ -128,8 +131,9 @@ func TestDatabaseMaintenanceRunResource_basic(t *testing.T) {
128131
resource.TestCheckResourceAttr(resourceName, "is_patch_now_enabled", "true"),
129132
resource.TestCheckResourceAttrSet(resourceName, "maintenance_run_id"),
130133
resource.TestCheckResourceAttrSet(resourceName, "patch_id"),
134+
resource.TestCheckResourceAttr(resourceName, "patching_mode", "NONROLLING"),
131135
resource.TestCheckResourceAttrSet(resourceName, "state"),
132-
resource.TestCheckResourceAttr(resourceName, "time_scheduled", mrTimeScheduledUpdate.Format(time.RFC3339Nano)),
136+
resource.TestCheckResourceAttrSet(resourceName, "time_scheduled"),
133137

134138
func(s *terraform.State) (err error) {
135139
resId2, err = fromInstanceState(s, resourceName, "id")
@@ -154,6 +158,9 @@ func TestDatabaseMaintenanceRunResource_basic(t *testing.T) {
154158
resource.TestCheckResourceAttrSet(singularDatasourceName, "id"),
155159
resource.TestCheckResourceAttrSet(singularDatasourceName, "maintenance_subtype"),
156160
resource.TestCheckResourceAttrSet(singularDatasourceName, "maintenance_type"),
161+
resource.TestCheckResourceAttrSet(singularDatasourceName, "patch_failure_count"),
162+
resource.TestCheckResourceAttr(singularDatasourceName, "patching_mode", "NONROLLING"),
163+
resource.TestCheckResourceAttrSet(singularDatasourceName, "peer_maintenance_run_id"),
157164
resource.TestCheckResourceAttrSet(singularDatasourceName, "state"),
158165
resource.TestCheckResourceAttrSet(singularDatasourceName, "target_resource_type"),
159166
resource.TestCheckResourceAttrSet(singularDatasourceName, "time_scheduled"),

oci/database_maintenance_runs_data_source.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,16 @@ func (s *DatabaseMaintenanceRunsDataSourceCrud) SetData() error {
157157

158158
maintenanceRun["maintenance_type"] = r.MaintenanceType
159159

160+
if r.PatchFailureCount != nil {
161+
maintenanceRun["patch_failure_count"] = *r.PatchFailureCount
162+
}
163+
160164
if r.PatchId != nil {
161165
maintenanceRun["patch_id"] = *r.PatchId
162166
}
163167

168+
maintenanceRun["patching_mode"] = r.PatchingMode
169+
164170
if r.PeerMaintenanceRunId != nil {
165171
maintenanceRun["peer_maintenance_run_id"] = *r.PeerMaintenanceRunId
166172
}

website/docs/d/database_autonomous_database.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ The following attributes are exported:
9696
* `private_endpoint_label` - The private endpoint label for the resource.
9797
* `refreshable_mode` - The refresh mode of the clone. AUTOMATIC indicates that the clone is automatically being refreshed with data from the source Autonomous Database.
9898
* `refreshable_status` - The refresh status of the clone. REFRESHING indicates that the clone is currently being refreshed with data from the source Autonomous Database.
99-
* `role` - The Data Guard role of the Autonomous Container Database, if Autonomous Data Guard is enabled.
99+
* `role` - The Data Guard role of the Autonomous Container Database, if Autonomous Data Guard is enabled.
100100
* `service_console_url` - The URL of the Service Console for the Autonomous Database.
101101
* `source_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the source Autonomous Database that was cloned to create the current Autonomous Database.
102102
* `standby_db` - Autonomous Data Guard standby database details.

website/docs/d/database_autonomous_databases.html.markdown

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,7 @@ The following attributes are exported:
122122
* `private_endpoint_label` - The private endpoint label for the resource.
123123
* `refreshable_mode` - The refresh mode of the clone. AUTOMATIC indicates that the clone is automatically being refreshed with data from the source Autonomous Database.
124124
* `refreshable_status` - The refresh status of the clone. REFRESHING indicates that the clone is currently being refreshed with data from the source Autonomous Database.
125-
* `role` - The Data Guard role of the Autonomous Container Database, if Autonomous Data Guard is enabled.
126-
* `service_console_url` - The URL of the Service Console for the Autonomous Database.
125+
* `role` - The Data Guard role of the Autonomous Container Database, if Autonomous Data Guard is enabled.
127126
* `source_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the source Autonomous Database that was cloned to create the current Autonomous Database.
128127
* `standby_db` - Autonomous Data Guard standby database details.
129128
* `lag_time_in_seconds` - The amount of time, in seconds, that the data of the standby database lags the data of the primary database. Can be used to determine the potential data loss in the event of a failover.

website/docs/d/database_autonomous_databases_clones.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ The following attributes are exported:
112112
* `private_endpoint_label` - The private endpoint label for the resource. Setting this to an empty string, after the private endpoint database gets created, will change the same private endpoint database to the public endpoint database.
113113
* `refreshable_mode` - The refresh mode of the clone. AUTOMATIC indicates that the clone is automatically being refreshed with data from the source Autonomous Database.
114114
* `refreshable_status` - The refresh status of the clone. REFRESHING indicates that the clone is currently being refreshed with data from the source Autonomous Database.
115-
* `role` - The Data Guard role of the Autonomous Container Database, if Autonomous Data Guard is enabled.
115+
* `role` - The Data Guard role of the Autonomous Container Database, if Autonomous Data Guard is enabled.
116116
* `service_console_url` - The URL of the Service Console for the Autonomous Database.
117117
* `source_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the source Autonomous Database that was cloned to create the current Autonomous Database.
118118
* `standby_db` - Autonomous Data Guard standby database details.

website/docs/d/database_maintenance_run.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,9 @@ The following attributes are exported:
3939
* `lifecycle_details` - Additional information about the current lifecycle state.
4040
* `maintenance_subtype` - Maintenance sub-type.
4141
* `maintenance_type` - Maintenance type.
42+
* `patch_failure_count` - Contain the patch failure count.
4243
* `patch_id` - The unique identifier of the patch. The identifier string includes the patch type, the Oracle Database version, and the patch creation date (using the format YYMMDD). For example, the identifier `ru_patch_19.9.0.0_201030` is used for an RU patch for Oracle Database 19.9.0.0 that was released October 30, 2020.
44+
* `patching_mode` - Maintenance method, it will be either "ROLLING" or "NONROLLING". Default value is ROLLING.
4345
* `peer_maintenance_run_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the maintenance run for the Autonomous Data Guard association's peer container database.
4446
* `state` - The current state of the maintenance run. For Autonomous Database on shared Exadata infrastructure, valid states are IN_PROGRESS, SUCCEEDED and FAILED.
4547
* `target_resource_id` - The ID of the target resource on which the maintenance run occurs.

website/docs/d/database_maintenance_runs.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,9 @@ The following attributes are exported:
5858
* `lifecycle_details` - Additional information about the current lifecycle state.
5959
* `maintenance_subtype` - Maintenance sub-type.
6060
* `maintenance_type` - Maintenance type.
61+
* `patch_failure_count` - Contain the patch failure count.
6162
* `patch_id` - The unique identifier of the patch. The identifier string includes the patch type, the Oracle Database version, and the patch creation date (using the format YYMMDD). For example, the identifier `ru_patch_19.9.0.0_201030` is used for an RU patch for Oracle Database 19.9.0.0 that was released October 30, 2020.
63+
* `patching_mode` - Maintenance method, it will be either "ROLLING" or "NONROLLING". Default value is ROLLING.
6264
* `peer_maintenance_run_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the maintenance run for the Autonomous Data Guard association's peer container database.
6365
* `state` - The current state of the maintenance run. For Autonomous Database on shared Exadata infrastructure, valid states are IN_PROGRESS, SUCCEEDED and FAILED.
6466
* `target_resource_id` - The ID of the target resource on which the maintenance run occurs.

0 commit comments

Comments
 (0)