Skip to content

Commit 000388a

Browse files
karthikoracle1993jiaqchenO
authored andcommitted
Bug fix - Terraform for fix autostart and autostop removal of scheduled operations
1 parent 5a00344 commit 000388a

File tree

3 files changed

+326
-68
lines changed

3 files changed

+326
-68
lines changed

internal/integrationtest/database_autonomous_database_resource_test.go

Lines changed: 201 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4323,3 +4323,204 @@ func TestDatabaseAutonomousDatabase_opsi_dbms(t *testing.T) {
43234323
},
43244324
})
43254325
}
4326+
4327+
func TestDatabaseAutonomousDatabaseResource_scheduledOperations(t *testing.T) {
4328+
httpreplay.SetScenario("TestDatabaseAutonomousDatabaseResource_scheduledOperations")
4329+
defer httpreplay.SaveScenario()
4330+
4331+
config := acctest.ProviderTestConfig()
4332+
4333+
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
4334+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
4335+
4336+
okvSecret = utils.GetEnvSettingWithBlankDefault("okv_secret")
4337+
OkvSecretVariableStr = fmt.Sprintf("variable \"okv_secret\" { default = \"%s\" }\n", okvSecret)
4338+
4339+
resourceName := "oci_database_autonomous_database.test_autonomous_database"
4340+
// Save TF content to Create resource with optional properties. This has to be exactly the same as the config part in the "Create with optionals" step in the test.
4341+
acctest.SaveConfigContent(config+compartmentIdVariableStr+DatabaseAutonomousDatabaseResourceDependencies+
4342+
acctest.GenerateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", acctest.Optional, acctest.Create, DatabaseAutonomousDatabaseRepresentation), "database", "autonomousDatabase", t)
4343+
4344+
acctest.ResourceTest(t, testAccCheckDatabaseAutonomousDatabaseDestroy, []resource.TestStep{
4345+
//0. Verify Create
4346+
{
4347+
Config: config + compartmentIdVariableStr + DatabaseAutonomousDatabaseResourceDependencies +
4348+
acctest.GenerateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", acctest.Optional, acctest.Create, DatabaseAutonomousDatabaseRepresentation),
4349+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
4350+
resource.TestCheckResourceAttr(resourceName, "admin_password", "BEstrO0ng_#11"),
4351+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
4352+
resource.TestCheckResourceAttr(resourceName, "cpu_core_count", "1"),
4353+
resource.TestCheckResourceAttr(resourceName, "db_name", adbName),
4354+
// verify computed field db_workload to be defaulted to OLTP
4355+
resource.TestCheckResourceAttr(resourceName, "db_workload", "OLTP"),
4356+
acctest.CheckResourceSetContainsElementWithProperties(resourceName, "scheduled_operations", map[string]string{
4357+
"day_of_week.0.name": "MONDAY",
4358+
"scheduled_start_time": "09:00",
4359+
"scheduled_stop_time": "19:00",
4360+
}, nil),
4361+
acctest.CheckResourceSetContainsElementWithProperties(resourceName, "scheduled_operations", map[string]string{
4362+
"day_of_week.0.name": "TUESDAY",
4363+
"scheduled_start_time": "09:00",
4364+
"scheduled_stop_time": "19:00",
4365+
}, nil),
4366+
acctest.CheckResourceSetContainsElementWithProperties(resourceName, "scheduled_operations", map[string]string{
4367+
"day_of_week.0.name": "WEDNESDAY",
4368+
"scheduled_start_time": "09:00",
4369+
"scheduled_stop_time": "19:00",
4370+
}, nil),
4371+
acctest.CheckResourceSetContainsElementWithProperties(resourceName, "scheduled_operations", map[string]string{
4372+
"day_of_week.0.name": "THURSDAY",
4373+
"scheduled_start_time": "09:00",
4374+
"scheduled_stop_time": "19:00",
4375+
}, nil),
4376+
acctest.CheckResourceSetContainsElementWithProperties(resourceName, "scheduled_operations", map[string]string{
4377+
"day_of_week.0.name": "FRIDAY",
4378+
"scheduled_start_time": "09:00",
4379+
"scheduled_stop_time": "19:00",
4380+
}, nil),
4381+
acctest.CheckResourceSetContainsElementWithProperties(resourceName, "scheduled_operations", map[string]string{
4382+
"day_of_week.0.name": "SATURDAY",
4383+
"scheduled_start_time": "09:00",
4384+
"scheduled_stop_time": "19:00",
4385+
}, nil),
4386+
acctest.CheckResourceSetContainsElementWithProperties(resourceName, "scheduled_operations", map[string]string{
4387+
"day_of_week.0.name": "SUNDAY",
4388+
"scheduled_start_time": "09:00",
4389+
"scheduled_stop_time": "19:00",
4390+
}, nil),
4391+
4392+
func(s *terraform.State) (err error) {
4393+
_, err = acctest.FromInstanceState(s, resourceName, "id")
4394+
return err
4395+
},
4396+
),
4397+
},
4398+
//test to verify if the plan fails.
4399+
{
4400+
Config: config + compartmentIdVariableStr + DatabaseAutonomousDatabaseResourceDependencies +
4401+
acctest.GenerateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", acctest.Optional, acctest.Create,
4402+
acctest.RepresentationCopyWithNewProperties(acctest.RepresentationCopyWithRemovedProperties(DatabaseAutonomousDatabaseRepresentation, []string{"scheduled_operations"}),
4403+
map[string]interface{}{
4404+
"scheduled_operations": []acctest.RepresentationGroup{
4405+
{RepType: acctest.Optional, Group: DatabaseAutonomousDatabaseScheduledOperationsRepresentationFriday},
4406+
{RepType: acctest.Optional, Group: DatabaseAutonomousDatabaseScheduledOperationsRepresentationSaturday},
4407+
{RepType: acctest.Optional, Group: DatabaseAutonomousDatabaseScheduledOperationsRepresentationMonday},
4408+
{RepType: acctest.Optional, Group: DatabaseAutonomousDatabaseScheduledOperationsRepresentationThursday},
4409+
{RepType: acctest.Optional, Group: DatabaseAutonomousDatabaseScheduledOperationsRepresentationWednesday},
4410+
{RepType: acctest.Optional, Group: DatabaseAutonomousDatabaseScheduledOperationsRepresentationTuesday},
4411+
{RepType: acctest.Optional, Group: DatabaseAutonomousDatabaseScheduledOperationsRepresentationSunday}},
4412+
})),
4413+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
4414+
resource.TestCheckResourceAttr(resourceName, "admin_password", "BEstrO0ng_#11"),
4415+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
4416+
resource.TestCheckResourceAttr(resourceName, "cpu_core_count", "1"),
4417+
resource.TestCheckResourceAttr(resourceName, "db_name", adbName),
4418+
// verify computed field db_workload to be defaulted to OLTP
4419+
resource.TestCheckResourceAttr(resourceName, "db_workload", "OLTP"),
4420+
acctest.CheckResourceSetContainsElementWithProperties(resourceName, "scheduled_operations", map[string]string{
4421+
"day_of_week.0.name": "MONDAY",
4422+
"scheduled_start_time": "09:00",
4423+
"scheduled_stop_time": "19:00",
4424+
}, nil),
4425+
acctest.CheckResourceSetContainsElementWithProperties(resourceName, "scheduled_operations", map[string]string{
4426+
"day_of_week.0.name": "TUESDAY",
4427+
"scheduled_start_time": "09:00",
4428+
"scheduled_stop_time": "19:00",
4429+
}, nil),
4430+
acctest.CheckResourceSetContainsElementWithProperties(resourceName, "scheduled_operations", map[string]string{
4431+
"day_of_week.0.name": "WEDNESDAY",
4432+
"scheduled_start_time": "09:00",
4433+
"scheduled_stop_time": "19:00",
4434+
}, nil),
4435+
acctest.CheckResourceSetContainsElementWithProperties(resourceName, "scheduled_operations", map[string]string{
4436+
"day_of_week.0.name": "THURSDAY",
4437+
"scheduled_start_time": "09:00",
4438+
"scheduled_stop_time": "19:00",
4439+
}, nil),
4440+
acctest.CheckResourceSetContainsElementWithProperties(resourceName, "scheduled_operations", map[string]string{
4441+
"day_of_week.0.name": "FRIDAY",
4442+
"scheduled_start_time": "09:00",
4443+
"scheduled_stop_time": "19:00",
4444+
}, nil),
4445+
acctest.CheckResourceSetContainsElementWithProperties(resourceName, "scheduled_operations", map[string]string{
4446+
"day_of_week.0.name": "SATURDAY",
4447+
"scheduled_start_time": "09:00",
4448+
"scheduled_stop_time": "19:00",
4449+
}, nil),
4450+
acctest.CheckResourceSetContainsElementWithProperties(resourceName, "scheduled_operations", map[string]string{
4451+
"day_of_week.0.name": "SUNDAY",
4452+
"scheduled_start_time": "09:00",
4453+
"scheduled_stop_time": "19:00",
4454+
}, nil),
4455+
4456+
func(s *terraform.State) (err error) {
4457+
_, err = acctest.FromInstanceState(s, resourceName, "id")
4458+
return err
4459+
},
4460+
),
4461+
},
4462+
{
4463+
Config: config + compartmentIdVariableStr + DatabaseAutonomousDatabaseResourceDependencies +
4464+
acctest.GenerateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database", acctest.Optional, acctest.Create,
4465+
acctest.RepresentationCopyWithNewProperties(acctest.RepresentationCopyWithRemovedProperties(DatabaseAutonomousDatabaseRepresentation, []string{"scheduled_operations"}),
4466+
map[string]interface{}{
4467+
"scheduled_operations": []acctest.RepresentationGroup{
4468+
{RepType: acctest.Optional, Group: DatabaseAutonomousDatabaseScheduledOperationsRepresentationMondayUpdated},
4469+
{RepType: acctest.Optional, Group: DatabaseAutonomousDatabaseScheduledOperationsRepresentationTuesday},
4470+
{RepType: acctest.Optional, Group: DatabaseAutonomousDatabaseScheduledOperationsRepresentationWednesday},
4471+
{RepType: acctest.Optional, Group: DatabaseAutonomousDatabaseScheduledOperationsRepresentationThursday},
4472+
{RepType: acctest.Optional, Group: DatabaseAutonomousDatabaseScheduledOperationsRepresentationFriday},
4473+
{RepType: acctest.Optional, Group: DatabaseAutonomousDatabaseScheduledOperationsRepresentationSaturday},
4474+
{RepType: acctest.Optional, Group: DatabaseAutonomousDatabaseScheduledOperationsRepresentationSunday}},
4475+
})),
4476+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
4477+
resource.TestCheckResourceAttr(resourceName, "admin_password", "BEstrO0ng_#11"),
4478+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
4479+
resource.TestCheckResourceAttr(resourceName, "cpu_core_count", "1"),
4480+
resource.TestCheckResourceAttr(resourceName, "db_name", adbName),
4481+
// verify computed field db_workload to be defaulted to OLTP
4482+
resource.TestCheckResourceAttr(resourceName, "db_workload", "OLTP"),
4483+
acctest.CheckResourceSetContainsElementWithProperties(resourceName, "scheduled_operations", map[string]string{
4484+
"day_of_week.0.name": "MONDAY",
4485+
"scheduled_start_time": "09:00",
4486+
"scheduled_stop_time": "",
4487+
}, nil),
4488+
acctest.CheckResourceSetContainsElementWithProperties(resourceName, "scheduled_operations", map[string]string{
4489+
"day_of_week.0.name": "TUESDAY",
4490+
"scheduled_start_time": "09:00",
4491+
"scheduled_stop_time": "19:00",
4492+
}, nil),
4493+
acctest.CheckResourceSetContainsElementWithProperties(resourceName, "scheduled_operations", map[string]string{
4494+
"day_of_week.0.name": "WEDNESDAY",
4495+
"scheduled_start_time": "09:00",
4496+
"scheduled_stop_time": "19:00",
4497+
}, nil),
4498+
acctest.CheckResourceSetContainsElementWithProperties(resourceName, "scheduled_operations", map[string]string{
4499+
"day_of_week.0.name": "THURSDAY",
4500+
"scheduled_start_time": "09:00",
4501+
"scheduled_stop_time": "19:00",
4502+
}, nil),
4503+
acctest.CheckResourceSetContainsElementWithProperties(resourceName, "scheduled_operations", map[string]string{
4504+
"day_of_week.0.name": "FRIDAY",
4505+
"scheduled_start_time": "09:00",
4506+
"scheduled_stop_time": "19:00",
4507+
}, nil),
4508+
acctest.CheckResourceSetContainsElementWithProperties(resourceName, "scheduled_operations", map[string]string{
4509+
"day_of_week.0.name": "SATURDAY",
4510+
"scheduled_start_time": "09:00",
4511+
"scheduled_stop_time": "19:00",
4512+
}, nil),
4513+
acctest.CheckResourceSetContainsElementWithProperties(resourceName, "scheduled_operations", map[string]string{
4514+
"day_of_week.0.name": "SUNDAY",
4515+
"scheduled_start_time": "09:00",
4516+
"scheduled_stop_time": "19:00",
4517+
}, nil),
4518+
4519+
func(s *terraform.State) (err error) {
4520+
_, err = acctest.FromInstanceState(s, resourceName, "id")
4521+
return err
4522+
},
4523+
),
4524+
},
4525+
})
4526+
}

0 commit comments

Comments
 (0)