Skip to content

Commit 21678ba

Browse files
Terraform Team Automationvsin12
authored andcommitted
Added - Support for ADB-S: Restore / Clone from backup from last available timestamp
(cherry picked from commit 8feb79e)
1 parent c54bd2b commit 21678ba

10 files changed

+237
-138
lines changed

examples/database/adb/autonomous_database.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,20 @@ resource "oci_database_autonomous_database" "autonomous_database_from_backup_tim
138138
}
139139
*/
140140

141+
resource "oci_database_autonomous_database" "autonomous_database_from_backup_latest" {
142+
#Required
143+
admin_password = random_string.autonomous_database_admin_password.result
144+
compartment_id = var.compartment_ocid
145+
cpu_core_count = "1"
146+
data_storage_size_in_tbs = "1"
147+
db_name = "adbdb3"
148+
149+
clone_type = "FULL"
150+
source = "BACKUP_FROM_TIMESTAMP"
151+
autonomous_database_id = oci_database_autonomous_database_backup.autonomous_database_backup.autonomous_database_id
152+
use_latest_available_backup_time_stamp = "true"
153+
}
154+
141155
data "oci_database_autonomous_databases" "autonomous_databases" {
142156
#Required
143157
compartment_id = var.compartment_ocid

internal/integrationtest/database_autonomous_database_resource_test.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,12 @@ var (
112112
"timestamp": acctest.Representation{RepType: acctest.Required, Create: `${oci_database_autonomous_database_backup.test_autonomous_database_backup.time_ended}`},
113113
})
114114

115+
autonomousDatabaseRepresentationForSourceFromLatestBackup = acctest.RepresentationCopyWithNewProperties(
116+
acctest.RepresentationCopyWithRemovedProperties(acctest.GetUpdatedRepresentationCopy("db_name", acctest.Representation{RepType: acctest.Required, Create: adbBackupTimestampName}, autonomousDatabaseRepresentationForSourceFromBackupTimestamp), []string{"timestamp"}),
117+
map[string]interface{}{
118+
"use_latest_available_backup_time_stamp": acctest.Representation{RepType: acctest.Required, Create: `true`},
119+
})
120+
115121
autonomousDatabaseDataGuardRepresentation = acctest.RepresentationCopyWithNewProperties(
116122
acctest.RepresentationCopyWithRemovedProperties(DatabaseAutonomousDatabaseRepresentation, []string{"scheduled_operations"}),
117123
map[string]interface{}{
@@ -509,6 +515,71 @@ func TestResourceDatabaseAutonomousDatabaseDedicated(t *testing.T) {
509515
})
510516
}
511517

518+
// issue-routing-tag: database/dbaas-adb
519+
func TestResourceDatabaseAutonomousDatabaseResource_FromBackupWithLatest(t *testing.T) {
520+
httpreplay.SetScenario("TestResourceDatabaseAutonomousDatabaseResource_FromBackupWithLatest")
521+
defer httpreplay.SaveScenario()
522+
config := acctest.ProviderTestConfig()
523+
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
524+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
525+
526+
resourceName := "oci_database_autonomous_database.test_autonomous_database_from_backuptimestamp"
527+
528+
acctest.ResourceTest(t, testAccCheckDatabaseAutonomousDatabaseDestroy, []resource.TestStep{
529+
//1. Create dependencies
530+
{
531+
Config: config + compartmentIdVariableStr + AutonomousDatabaseFromBackupDependencies,
532+
},
533+
//2. verify create
534+
{
535+
Config: config + compartmentIdVariableStr + AutonomousDatabaseFromBackupDependencies +
536+
acctest.GenerateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database_from_backuptimestamp", acctest.Required, acctest.Create, autonomousDatabaseRepresentationForSourceFromLatestBackup),
537+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
538+
resource.TestCheckResourceAttr(resourceName, "admin_password", "BEstrO0ng_#11"),
539+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
540+
resource.TestCheckResourceAttr(resourceName, "cpu_core_count", "1"),
541+
resource.TestCheckResourceAttr(resourceName, "data_storage_size_in_tbs", "1"),
542+
resource.TestCheckResourceAttrSet(resourceName, "db_name"),
543+
544+
func(s *terraform.State) (err error) {
545+
resId, err := acctest.FromInstanceState(s, resourceName, "id")
546+
sourceresId, err := acctest.FromInstanceState(s, "oci_database_autonomous_database.test_autonomous_database", "id")
547+
if resId == sourceresId {
548+
return fmt.Errorf("resource not created when it was supposed to be created")
549+
}
550+
return err
551+
},
552+
),
553+
},
554+
//3. delete before next Create
555+
{
556+
Config: config + compartmentIdVariableStr + AutonomousDatabaseFromBackupDependencies,
557+
},
558+
//4. verify Create with optionals
559+
{
560+
Config: config + compartmentIdVariableStr + AutonomousDatabaseFromBackupDependencies +
561+
acctest.GenerateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database_from_backuptimestamp", acctest.Optional, acctest.Create, autonomousDatabaseRepresentationForSourceFromLatestBackup),
562+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
563+
resource.TestCheckResourceAttr(resourceName, "admin_password", "BEstrO0ng_#11"),
564+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
565+
resource.TestCheckResourceAttr(resourceName, "cpu_core_count", "1"),
566+
resource.TestCheckResourceAttr(resourceName, "data_storage_size_in_tbs", "1"),
567+
resource.TestCheckResourceAttrSet(resourceName, "db_name"),
568+
resource.TestCheckResourceAttr(resourceName, "db_workload", "OLTP"),
569+
resource.TestCheckResourceAttr(resourceName, "display_name", "example_autonomous_database"),
570+
resource.TestCheckResourceAttr(resourceName, "freeform_tags.%", "1"),
571+
resource.TestCheckResourceAttrSet(resourceName, "id"),
572+
resource.TestCheckResourceAttr(resourceName, "is_auto_scaling_enabled", "false"),
573+
resource.TestCheckResourceAttr(resourceName, "is_dedicated", "false"),
574+
resource.TestCheckResourceAttr(resourceName, "is_preview_version_with_service_terms_accepted", "false"),
575+
resource.TestCheckResourceAttr(resourceName, "license_model", "LICENSE_INCLUDED"),
576+
resource.TestCheckResourceAttrSet(resourceName, "state"),
577+
resource.TestCheckResourceAttrSet(resourceName, "state"),
578+
),
579+
},
580+
})
581+
}
582+
512583
// issue-routing-tag: database/dbaas-adb
513584
func TestResourceDatabaseAutonomousDatabaseResource_preview(t *testing.T) {
514585
t.Skip("Skip this test as this is a seasonal feature only when Dbaas has a preview to be released.")

internal/service/database/database_autonomous_database_backup_resource.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,15 @@ func DatabaseAutonomousDatabaseBackupResource() *schema.Resource {
3333
Required: true,
3434
ForceNew: true,
3535
},
36+
37+
// Optional
3638
"display_name": {
3739
Type: schema.TypeString,
38-
Required: true,
40+
Optional: true,
41+
Computed: true,
3942
ForceNew: true,
4043
},
4144

42-
// Optional
43-
4445
// Computed
4546
"compartment_id": {
4647
Type: schema.TypeString,

internal/service/database/database_autonomous_database_resource.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,12 @@ func DatabaseAutonomousDatabaseResource() *schema.Resource {
360360
ForceNew: true,
361361
DiffSuppressFunc: tfresource.TimeDiffSuppressFunction,
362362
},
363+
"use_latest_available_backup_time_stamp": {
364+
Type: schema.TypeBool,
365+
Optional: true,
366+
Computed: true,
367+
ForceNew: true,
368+
},
363369
"vault_id": {
364370
Type: schema.TypeString,
365371
Optional: true,
@@ -2258,6 +2264,10 @@ func (s *DatabaseAutonomousDatabaseResourceCrud) populateTopLevelPolymorphicCrea
22582264
}
22592265
details.Timestamp = &oci_common.SDKTime{Time: tmp}
22602266
}
2267+
if useLatestAvailableBackupTimeStamp, ok := s.D.GetOkExists("use_latest_available_backup_time_stamp"); ok {
2268+
tmp := useLatestAvailableBackupTimeStamp.(bool)
2269+
details.UseLatestAvailableBackupTimeStamp = &tmp
2270+
}
22612271
if adminPassword, ok := s.D.GetOkExists("admin_password"); ok {
22622272
tmp := adminPassword.(string)
22632273
details.AdminPassword = &tmp

website/docs/d/database_autonomous_database.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,9 +71,9 @@ The following attributes are exported:
7171
* `graph_studio_url` - The URL of the Graph Studio for the Autonomous Database.
7272
* `machine_learning_user_management_url` - Oracle Machine Learning user management URL.
7373
* `sql_dev_web_url` - Oracle SQL Developer Web URL.
74-
* `cpu_core_count` - The number of OCPU cores to be made available to the database. For Autonomous Databases on dedicated Exadata infrastructure, the maximum number of cores is determined by the infrastructure shape. See [Characteristics of Infrastructure Shapes](https://www.oracle.com/pls/topic/lookup?ctx=en/cloud/paas/autonomous-database&id=ATPFG-GUID-B0F033C1-CC5A-42F0-B2E7-3CECFEDA1FD1) for shape details.
74+
* `cpu_core_count` - The number of OCPU cores to be made available to the database. When the ECPU is selected, the value for cpuCoreCount is 0. For Autonomous Databases on dedicated Exadata infrastructure, the maximum number of cores is determined by the infrastructure shape. See [Characteristics of Infrastructure Shapes](https://www.oracle.com/pls/topic/lookup?ctx=en/cloud/paas/autonomous-database&id=ATPFG-GUID-B0F033C1-CC5A-42F0-B2E7-3CECFEDA1FD1) for shape details.
7575

76-
**Note:** This parameter cannot be used with the `ocpuCount` parameter.
76+
**Note:** This parameter cannot be used with the `ocpuCount` parameter.
7777
* `customer_contacts` - Customer Contacts.
7878
* `email` - The email address used by Oracle to send notifications regarding databases and infrastructure.
7979
* `data_safe_status` - Status of the Data Safe registration for this Autonomous Database. Could be REGISTERED or NOT_REGISTERED.

website/docs/d/database_autonomous_databases.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,9 @@ The following attributes are exported:
9797
* `graph_studio_url` - The URL of the Graph Studio for the Autonomous Database.
9898
* `machine_learning_user_management_url` - Oracle Machine Learning user management URL.
9999
* `sql_dev_web_url` - Oracle SQL Developer Web URL.
100-
* `cpu_core_count` - The number of OCPU cores to be made available to the database. For Autonomous Databases on dedicated Exadata infrastructure, the maximum number of cores is determined by the infrastructure shape. See [Characteristics of Infrastructure Shapes](https://www.oracle.com/pls/topic/lookup?ctx=en/cloud/paas/autonomous-database&id=ATPFG-GUID-B0F033C1-CC5A-42F0-B2E7-3CECFEDA1FD1) for shape details.
100+
* `cpu_core_count` - The number of OCPU cores to be made available to the database. When the ECPU is selected, the value for cpuCoreCount is 0. For Autonomous Databases on dedicated Exadata infrastructure, the maximum number of cores is determined by the infrastructure shape. See [Characteristics of Infrastructure Shapes](https://www.oracle.com/pls/topic/lookup?ctx=en/cloud/paas/autonomous-database&id=ATPFG-GUID-B0F033C1-CC5A-42F0-B2E7-3CECFEDA1FD1) for shape details.
101101

102-
**Note:** This parameter cannot be used with the `ocpuCount` parameter.
102+
**Note:** This parameter cannot be used with the `ocpuCount` parameter.
103103
* `customer_contacts` - Customer Contacts.
104104
* `email` - The email address used by Oracle to send notifications regarding databases and infrastructure.
105105
* `data_safe_status` - Status of the Data Safe registration for this Autonomous Database. Could be REGISTERED or NOT_REGISTERED.

website/docs/d/database_autonomous_databases_clones.html.markdown

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ The following attributes are exported:
8787
* `graph_studio_url` - The URL of the Graph Studio for the Autonomous Database.
8888
* `machine_learning_user_management_url` - Oracle Machine Learning user management URL.
8989
* `sql_dev_web_url` - Oracle SQL Developer Web URL.
90-
* `cpu_core_count` - The number of OCPU cores to be made available to the database. For Autonomous Databases on dedicated Exadata infrastructure, the maximum number of cores is determined by the infrastructure shape. See [Characteristics of Infrastructure Shapes](https://www.oracle.com/pls/topic/lookup?ctx=en/cloud/paas/autonomous-database&id=ATPFG-GUID-B0F033C1-CC5A-42F0-B2E7-3CECFEDA1FD1) for shape details.
90+
* `cpu_core_count` - The number of OCPU cores to be made available to the database. When the ECPU is selected, the value for cpuCoreCount is 0. For Autonomous Databases on dedicated Exadata infrastructure, the maximum number of cores is determined by the infrastructure shape. See [Characteristics of Infrastructure Shapes](https://www.oracle.com/pls/topic/lookup?ctx=en/cloud/paas/autonomous-database&id=ATPFG-GUID-B0F033C1-CC5A-42F0-B2E7-3CECFEDA1FD1) for shape details.
9191

92-
**Note:** This parameter cannot be used with the `ocpuCount` parameter.
92+
**Note:** This parameter cannot be used with the `ocpuCount` parameter.
9393
* `customer_contacts` - Customer Contacts.
9494
* `email` - The email address used by Oracle to send notifications regarding databases and infrastructure.
9595
* `data_safe_status` - Status of the Data Safe registration for this Autonomous Database.

0 commit comments

Comments
 (0)