Skip to content

Commit 4cd9241

Browse files
karthikoracle1993ravinitp
authored andcommitted
BugFix Scheduled Operations optional computed value removal
1 parent c0977d4 commit 4cd9241

8 files changed

+74
-9
lines changed

internal/integrationtest/database_autonomous_database_resource_test.go

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4687,7 +4687,7 @@ func TestDatabaseAutonomousDatabaseResource_DeveloperDatabases(t *testing.T) {
46874687
t.Skip("Skipping TestDatabaseAutonomousDatabase_opsi_dbms test.\n" + "Current TF_VAR_should_skip_adbs_test=" + shouldSkipADBStest)
46884688
}
46894689

4690-
httpreplay.SetScenario("TestDatabaseAutonomousDatabaseResource_scheduledOperations")
4690+
httpreplay.SetScenario("TestDatabaseAutonomousDatabaseResource_DeveloperDatabases")
46914691
defer httpreplay.SaveScenario()
46924692

46934693
config := acctest.ProviderTestConfig()
@@ -5011,6 +5011,46 @@ func TestDatabaseAutonomousDatabaseResource_scheduledOperations(t *testing.T) {
50115011
},
50125012
),
50135013
},
5014+
//test to verify if the plan fails.
5015+
{
5016+
Config: config + compartmentIdVariableStr + DatabaseAutonomousDatabaseResourceDependencies +
5017+
acctest.GenerateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", acctest.Optional, acctest.Create,
5018+
acctest.RepresentationCopyWithNewProperties(autonomousDatabaseRepresentationForScheduledOperations,
5019+
map[string]interface{}{
5020+
"enable_delete_scheduled_operations": acctest.Representation{RepType: acctest.Optional, Create: `true`},
5021+
})),
5022+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
5023+
resource.TestCheckResourceAttr(resourceName, "admin_password", "BEstrO0ng_#11"),
5024+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
5025+
// verify computed field db_workload to be defaulted to OLTP
5026+
resource.TestCheckResourceAttr(resourceName, "db_workload", "OLTP"),
5027+
func(s *terraform.State) (err error) {
5028+
_, err = acctest.FromInstanceState(s, resourceName, "id")
5029+
return err
5030+
},
5031+
),
5032+
},
5033+
{
5034+
Config: config + compartmentIdVariableStr + DatabaseAutonomousDatabaseResourceDependencies +
5035+
acctest.GenerateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", acctest.Optional, acctest.Create,
5036+
acctest.RepresentationCopyWithNewProperties(autonomousDatabaseRepresentationForScheduledOperations,
5037+
map[string]interface{}{
5038+
"enable_delete_scheduled_operations": acctest.Representation{RepType: acctest.Optional, Create: `true`},
5039+
"cpu_core_count": acctest.Representation{RepType: acctest.Optional, Create: `10`},
5040+
})),
5041+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
5042+
resource.TestCheckResourceAttr(resourceName, "admin_password", "BEstrO0ng_#11"),
5043+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
5044+
// verify computed field db_workload to be defaulted to OLTP
5045+
resource.TestCheckResourceAttr(resourceName, "db_workload", "OLTP"),
5046+
resource.TestCheckResourceAttr(resourceName, "scheduled_operations.#", "0"),
5047+
resource.TestCheckResourceAttr(resourceName, "cpu_core_count", "10"),
5048+
func(s *terraform.State) (err error) {
5049+
_, err = acctest.FromInstanceState(s, resourceName, "id")
5050+
return err
5051+
},
5052+
),
5053+
},
50145054
})
50155055
}
50165056

@@ -5021,7 +5061,7 @@ func TestDatabaseAutonomousDatabaseResource_dbTools(t *testing.T) {
50215061
t.Skip("Skipping TestDatabaseAutonomousDatabaseResource_dbTools test.\n" + "Current TF_VAR_should_skip_adbs_test=" + shouldSkipADBStest)
50225062
}
50235063

5024-
httpreplay.SetScenario("TestDatabaseAutonomousDatabaseResource_scheduledOperations")
5064+
httpreplay.SetScenario("TestDatabaseAutonomousDatabaseResource_dbTools")
50255065
defer httpreplay.SaveScenario()
50265066

50275067
config := acctest.ProviderTestConfig()

internal/service/database/database_autonomous_database_resource.go

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,11 @@ func DatabaseAutonomousDatabaseResource() *schema.Resource {
222222
},
223223
},
224224
},
225+
// Optional
226+
"enable_delete_scheduled_operations": {
227+
Type: schema.TypeBool,
228+
Optional: true,
229+
},
225230
"db_version": {
226231
Type: schema.TypeString,
227232
Optional: true,
@@ -518,16 +523,17 @@ func DatabaseAutonomousDatabaseResource() *schema.Resource {
518523
},
519524
},
520525
"scheduled_operations": {
521-
Type: schema.TypeSet,
522-
Set: scheduledOperationsForSets,
523-
Optional: true,
524-
Computed: true,
526+
Type: schema.TypeSet,
527+
Set: scheduledOperationsForSets,
528+
Optional: true,
529+
Computed: true,
530+
DiffSuppressFunc: tfresource.ScheduledOperationDbSuppressfunc,
525531
Elem: &schema.Resource{
526532
Schema: map[string]*schema.Schema{
527533
// Required
528534
"day_of_week": {
529535
Type: schema.TypeList,
530-
Required: true,
536+
Optional: true,
531537
MaxItems: 1,
532538
MinItems: 1,
533539
Elem: &schema.Resource{
@@ -2153,6 +2159,12 @@ func (s *DatabaseAutonomousDatabaseResourceCrud) Update() error {
21532159
request.ScheduledOperations = tmp
21542160
}
21552161
}
2162+
if enableDeleteScheduledOps, ok := s.D.GetOkExists("enable_delete_scheduled_operations"); ok && s.D.HasChange("enable_delete_scheduled_operations") {
2163+
_, scheduledOpsOk := s.D.GetOkExists("scheduled_operations")
2164+
if enableDeleteScheduledOps == true && scheduledOpsOk {
2165+
request.ScheduledOperations = []oci_database.ScheduledOperationDetails{}
2166+
}
2167+
}
21562168

21572169
if dbToolsDetails, ok := s.D.GetOkExists("db_tools_details"); ok && s.D.HasChange("db_tools_details") {
21582170
set := dbToolsDetails.(*schema.Set)

internal/tfresource/crud_helpers.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,3 +1461,10 @@ func ValidateBoolInSlice(valid []bool) schema.SchemaValidateFunc {
14611461
return
14621462
}
14631463
}
1464+
func ScheduledOperationDbSuppressfunc(k string, old, new string, d *schema.ResourceData) bool {
1465+
enableSchduledOpDelete, _ := d.GetOkExists("enable_delete_scheduled_operations")
1466+
if enableSchduledOpDelete.(bool) {
1467+
return true
1468+
}
1469+
return false
1470+
}

website/docs/d/database_autonomous_database.html.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,8 @@ AL32UTF8, AR8ADOS710, AR8ADOS720, AR8APTEC715, AR8ARABICMACS, AR8ASMO8X, AR8ISO8
262262
* `resource_pool_summary` - The configuration details for resource pool
263263
* `is_disabled` - Indicates if the resource pool should be deleted for the Autonomous Database.
264264
* `pool_size` - Resource pool size.
265-
* `role` - The Data Guard role of the Autonomous Container Database or Autonomous Database, if Autonomous Data Guard is enabled.
265+
* `role` - The Data Guard role of the Autonomous Container Database or Autonomous Database, if Autonomous Data Guard is enabled.
266+
* `enable_delete_scheduled_operations` - If omitted or set to false the provider will not delete scheduled_operations from the Autonomous Database. If set to true, provider will delete scheduled_operations from the Autonomous Database.
266267
* `scheduled_operations` - The list of scheduled operations. Consists of values such as dayOfWeek, scheduledStartTime, scheduledStopTime.
267268

268269
This cannot be updated in parallel with any of the following: licenseModel, dbEdition, cpuCoreCount, computeCount, computeModel, whitelistedIps, isMTLSConnectionRequired, openMode, permissionLevel, dbWorkload, privateEndpointLabel, nsgIds, dbVersion, isRefreshable, dbName, dbToolsDetails, isLocalDataGuardEnabled, or isFreeTier.

website/docs/d/database_autonomous_databases.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ AL32UTF8, AR8ADOS710, AR8ADOS720, AR8APTEC715, AR8ARABICMACS, AR8ASMO8X, AR8ISO8
293293
* `is_disabled` - Indicates if the resource pool should be deleted for the Autonomous Database.
294294
* `pool_size` - Resource pool size.
295295
* `role` - The Data Guard role of the Autonomous Container Database or Autonomous Database, if Autonomous Data Guard is enabled.
296+
* `enable_delete_scheduled_operations` - If omitted or set to false the provider will not delete scheduled_operations from the Autonomous Database. If set to true, provider will delete scheduled_operations from the Autonomous Database.
296297
* `scheduled_operations` - The list of scheduled operations. Consists of values such as dayOfWeek, scheduledStartTime, scheduledStopTime.
297298

298299
This cannot be updated in parallel with any of the following: licenseModel, dbEdition, cpuCoreCount, computeCount, computeModel, whitelistedIps, isMTLSConnectionRequired, openMode, permissionLevel, dbWorkload, privateEndpointLabel, nsgIds, dbVersion, isRefreshable, dbName, dbToolsDetails, isLocalDataGuardEnabled, or isFreeTier.

website/docs/d/database_autonomous_databases_clones.html.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,7 @@ AL32UTF8, AR8ADOS710, AR8ADOS720, AR8APTEC715, AR8ARABICMACS, AR8ASMO8X, AR8ISO8
282282
* `is_disabled` - Indicates if the resource pool should be deleted for the Autonomous Database.
283283
* `pool_size` - Resource pool size.
284284
* `role` - The Data Guard role of the Autonomous Container Database or Autonomous Database, if Autonomous Data Guard is enabled.
285+
* `enable_delete_scheduled_operations` - If omitted or set to false the provider will not delete scheduled_operations from the Autonomous Database. If set to true, provider will delete scheduled_operations from the Autonomous Database.
285286
* `scheduled_operations` - The list of scheduled operations. Consists of values such as dayOfWeek, scheduledStartTime, scheduledStopTime.
286287

287288
This cannot be updated in parallel with any of the following: licenseModel, dbEdition, cpuCoreCount, computeCount, computeModel, whitelistedIps, isMTLSConnectionRequired, openMode, permissionLevel, dbWorkload, privateEndpointLabel, nsgIds, dbVersion, isRefreshable, dbName, dbToolsDetails, isLocalDataGuardEnabled, or isFreeTier.

website/docs/r/database_autonomous_database.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ The following arguments are supported:
280280
* `resource_pool_summary` - (Optional) (Updatable) The configuration details for resource pool
281281
* `is_disabled` - (Optional) (Updatable) Indicates if the resource pool should be deleted for the Autonomous Database.
282282
* `pool_size` - (Optional) (Updatable) Resource pool size.
283+
* `enable_delete_scheduled_operations` - If omitted or set to false the provider will not delete scheduled_operations from the Autonomous Database. If set to true, provider will delete scheduled_operations from the Autonomous Database.
283284
* `scheduled_operations` - (Optional) (Updatable) The list of scheduled operations. Consists of values such as dayOfWeek, scheduledStartTime, scheduledStopTime.
284285

285286
This cannot be updated in parallel with any of the following: licenseModel, dbEdition, cpuCoreCount, computeCount, computeModel, whitelistedIps, isMTLSConnectionRequired, openMode, permissionLevel, dbWorkload, privateEndpointLabel, nsgIds, dbVersion, isRefreshable, dbName, dbToolsDetails, isLocalDataGuardEnabled, or isFreeTier.
@@ -579,6 +580,7 @@ AL32UTF8, AR8ADOS710, AR8ADOS720, AR8APTEC715, AR8ARABICMACS, AR8ASMO8X, AR8ISO8
579580
* `is_snapshot_standby` - Indicates if user wants to convert to a snapshot standby. For example, true would set a standby database to snapshot standby database. False would set a snapshot standby database back to regular standby database.
580581
* `time_snapshot_standby_enabled_till` - Time and date stored as an RFC 3339 formatted timestamp string. For example, 2022-01-01T12:00:00.000Z would set a limit for the snapshot standby to be converted back to a cross-region standby database.
581582
* `role` - The Data Guard role of the Autonomous Container Database or Autonomous Database, if Autonomous Data Guard is enabled.
583+
* `enable_delete_scheduled_operations` - If omitted or set to false the provider will not delete scheduled_operations from the Autonomous Database. If set to true, provider will delete scheduled_operations from the Autonomous Database.
582584
* `scheduled_operations` - The list of scheduled operations. Consists of values such as dayOfWeek, scheduledStartTime, scheduledStopTime.
583585

584586
This cannot be updated in parallel with any of the following: licenseModel, dbEdition, cpuCoreCount, computeCount, computeModel, whitelistedIps, isMTLSConnectionRequired, openMode, permissionLevel, dbWorkload, privateEndpointLabel, nsgIds, dbVersion, isRefreshable, dbName, dbToolsDetails, isLocalDataGuardEnabled, or isFreeTier.

website/docs/r/database_autonomous_database_saas_admin_user.html.markdown

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,8 @@ The following attributes are exported:
246246
* `resource_pool_summary` - The configuration details for resource pool
247247
* `is_disabled` - Indicates if the resource pool should be deleted for the Autonomous Database.
248248
* `pool_size` - Resource pool size.
249-
* `role` - The Data Guard role of the Autonomous Container Database or Autonomous Database, if Autonomous Data Guard is enabled.
249+
* `role` - The Data Guard role of the Autonomous Container Database or Autonomous Database, if Autonomous Data Guard is enabled.
250+
* `enable_delete_scheduled_operations` - If omitted or set to false the provider will not delete scheduled_operations from the Autonomous Database. If set to true, provider will delete scheduled_operations from the Autonomous Database.
250251
* `scheduled_operations` - The list of scheduled operations. Consists of values such as dayOfWeek, scheduledStartTime, scheduledStopTime.
251252

252253
This cannot be updated in parallel with any of the following: licenseModel, dbEdition, cpuCoreCount, computeCount, computeModel, whitelistedIps, isMTLSConnectionRequired, openMode, permissionLevel, dbWorkload, privateEndpointLabel, nsgIds, dbVersion, isRefreshable, dbName, dbToolsDetails, isLocalDataGuardEnabled, or isFreeTier.

0 commit comments

Comments
 (0)