Skip to content

Commit 0bddcd1

Browse files
Terraform Team Automationjotruon
authored andcommitted
Added - Support for [ADB-S] Elastic Resource Pools
1 parent 5e6970d commit 0bddcd1

11 files changed

+580
-7
lines changed

internal/integrationtest/database_autonomous_database_resource_test.go

Lines changed: 237 additions & 0 deletions
Large diffs are not rendered by default.

internal/integrationtest/database_autonomous_database_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ var (
5252
adbCloneName = utils.RandomString(1, utils.CharsetWithoutDigits) + utils.RandomString(13, utils.Charset)
5353
tfStaticCompartmentId = utils.GetEnvSettingWithBlankDefault("compartment_id_for_static_resource")
5454
tfStaticCompartmentIdVariableStr = fmt.Sprintf("variable \"compartment_id_for_static_resource\" { default = \"%s\" }\n", tfStaticCompartmentId)
55+
adbMemberName = utils.RandomString(1, utils.CharsetWithoutDigits) + utils.RandomString(13, utils.Charset)
5556

5657
DatabaseAutonomousDatabaseRepresentation = map[string]interface{}{
5758
"compartment_id": acctest.Representation{RepType: acctest.Required, Create: `${var.compartment_id}`},
@@ -110,6 +111,11 @@ var (
110111
DatabaseAutonomousDatabaseCustomerContactsRepresentation = map[string]interface{}{
111112
"email": acctest.Representation{RepType: acctest.Optional, Create: `test@oracle.com`, Update: `test2@oracle.com`},
112113
}
114+
DatabaseAutonomousDatabaseResourcePoolSummaryRepresentation = map[string]interface{}{
115+
"is_disabled": acctest.Representation{RepType: acctest.Optional, Create: `false`, Update: `true`},
116+
"pool_size": acctest.Representation{RepType: acctest.Optional, Create: `128`, Update: `256`},
117+
}
118+
113119
DatabaseAutonomousDatabaseScheduledOperationsRepresentation = map[string]interface{}{
114120
"day_of_week": acctest.RepresentationGroup{RepType: acctest.Required, Group: DatabaseAutonomousDatabaseScheduledOperationsDayOfWeekRepresentation},
115121
"scheduled_start_time": acctest.Representation{RepType: acctest.Optional, Create: `09:00`, Update: `10:00`},

internal/service/database/database_autonomous_database_data_source.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,16 @@ func (s *DatabaseAutonomousDatabaseDataSourceCrud) SetData() error {
346346
s.D.Set("remote_disaster_recovery_configuration", nil)
347347
}
348348

349+
if s.Res.ResourcePoolLeaderId != nil {
350+
s.D.Set("resource_pool_leader_id", *s.Res.ResourcePoolLeaderId)
351+
}
352+
353+
if s.Res.ResourcePoolSummary != nil {
354+
s.D.Set("resource_pool_summary", []interface{}{ResourcePoolSummaryToMap(s.Res.ResourcePoolSummary)})
355+
} else {
356+
s.D.Set("resource_pool_summary", nil)
357+
}
358+
349359
s.D.Set("role", s.Res.Role)
350360

351361
scheduledOperations := []interface{}{}
@@ -410,6 +420,10 @@ func (s *DatabaseAutonomousDatabaseDataSourceCrud) SetData() error {
410420
s.D.Set("time_maintenance_end", s.Res.TimeMaintenanceEnd.String())
411421
}
412422

423+
if s.Res.TimeOfJoiningResourcePool != nil {
424+
s.D.Set("time_of_joining_resource_pool", s.Res.TimeOfJoiningResourcePool.String())
425+
}
426+
413427
if s.Res.TimeOfLastFailover != nil {
414428
s.D.Set("time_of_last_failover", s.Res.TimeOfLastFailover.String())
415429
}

internal/service/database/database_autonomous_database_resource.go

Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@ package database
66
import (
77
"context"
88
"fmt"
9+
"io"
910
"log"
11+
"os"
1012
"strings"
1113
"time"
1214

@@ -308,6 +310,37 @@ func DatabaseAutonomousDatabaseResource() *schema.Resource {
308310
Computed: true,
309311
ForceNew: true,
310312
},
313+
"resource_pool_leader_id": {
314+
Type: schema.TypeString,
315+
Optional: true,
316+
Computed: true,
317+
},
318+
"resource_pool_summary": {
319+
Type: schema.TypeList,
320+
Optional: true,
321+
Computed: true,
322+
MaxItems: 1,
323+
MinItems: 1,
324+
Elem: &schema.Resource{
325+
Schema: map[string]*schema.Schema{
326+
// Required
327+
328+
// Optional
329+
"is_disabled": {
330+
Type: schema.TypeBool,
331+
Optional: true,
332+
Computed: true,
333+
},
334+
"pool_size": {
335+
Type: schema.TypeInt,
336+
Optional: true,
337+
Computed: true,
338+
},
339+
340+
// Computed
341+
},
342+
},
343+
},
311344
"scheduled_operations": {
312345
Type: schema.TypeList,
313346
Optional: true,
@@ -923,6 +956,10 @@ func DatabaseAutonomousDatabaseResource() *schema.Resource {
923956
Type: schema.TypeString,
924957
Computed: true,
925958
},
959+
"time_of_joining_resource_pool": {
960+
Type: schema.TypeString,
961+
Computed: true,
962+
},
926963
"time_of_last_failover": {
927964
Type: schema.TypeString,
928965
Computed: true,
@@ -1553,6 +1590,22 @@ func (s *DatabaseAutonomousDatabaseResourceCrud) Update() error {
15531590
request.RefreshableMode = oci_database.UpdateAutonomousDatabaseDetailsRefreshableModeEnum(refreshableMode.(string))
15541591
}
15551592

1593+
if resourcePoolLeaderId, ok := s.D.GetOk("resource_pool_leader_id"); ok && s.D.HasChange("resource_pool_leader_id") {
1594+
tmp := resourcePoolLeaderId.(string)
1595+
request.ResourcePoolLeaderId = &tmp
1596+
}
1597+
1598+
if resourcePoolSummary, ok := s.D.GetOkExists("resource_pool_summary"); ok && s.D.HasChange("resource_pool_summary") {
1599+
if tmpList := resourcePoolSummary.([]interface{}); len(tmpList) > 0 {
1600+
fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "resource_pool_summary", 0)
1601+
tmp, err := s.mapToResourcePoolSummary(fieldKeyFormat)
1602+
if err != nil {
1603+
return err
1604+
}
1605+
request.ResourcePoolSummary = &tmp
1606+
}
1607+
}
1608+
15561609
if scheduledOperations, ok := s.D.GetOkExists("scheduled_operations"); ok && s.D.HasChange("scheduled_operations") {
15571610
interfaces := scheduledOperations.([]interface{})
15581611
tmp := make([]oci_database.ScheduledOperationDetails, len(interfaces))
@@ -1940,6 +1993,16 @@ func (s *DatabaseAutonomousDatabaseResourceCrud) SetData() error {
19401993
s.D.Set("remote_disaster_recovery_configuration", nil)
19411994
}
19421995

1996+
if s.Res.ResourcePoolLeaderId != nil {
1997+
s.D.Set("resource_pool_leader_id", *s.Res.ResourcePoolLeaderId)
1998+
}
1999+
2000+
if s.Res.ResourcePoolSummary != nil {
2001+
s.D.Set("resource_pool_summary", []interface{}{ResourcePoolSummaryToMap(s.Res.ResourcePoolSummary)})
2002+
} else {
2003+
s.D.Set("resource_pool_summary", nil)
2004+
}
2005+
19432006
s.D.Set("role", s.Res.Role)
19442007

19452008
scheduledOperations := []interface{}{}
@@ -2004,6 +2067,10 @@ func (s *DatabaseAutonomousDatabaseResourceCrud) SetData() error {
20042067
s.D.Set("time_maintenance_end", s.Res.TimeMaintenanceEnd.String())
20052068
}
20062069

2070+
if s.Res.TimeOfJoiningResourcePool != nil {
2071+
s.D.Set("time_of_joining_resource_pool", s.Res.TimeOfJoiningResourcePool.String())
2072+
}
2073+
20072074
if s.Res.TimeOfLastFailover != nil {
20082075
s.D.Set("time_of_last_failover", s.Res.TimeOfLastFailover.String())
20092076
}
@@ -2281,6 +2348,36 @@ func DisasterRecoveryConfigurationToMap(obj *oci_database.DisasterRecoveryConfig
22812348
return result
22822349
}
22832350

2351+
func (s *DatabaseAutonomousDatabaseResourceCrud) mapToResourcePoolSummary(fieldKeyFormat string) (oci_database.ResourcePoolSummary, error) {
2352+
result := oci_database.ResourcePoolSummary{}
2353+
2354+
if isDisabled, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "is_disabled")); ok {
2355+
tmp := isDisabled.(bool)
2356+
result.IsDisabled = &tmp
2357+
}
2358+
2359+
if poolSize, ok := s.D.GetOkExists(fmt.Sprintf(fieldKeyFormat, "pool_size")); ok {
2360+
tmp := poolSize.(int)
2361+
result.PoolSize = &tmp
2362+
}
2363+
2364+
return result, nil
2365+
}
2366+
2367+
func ResourcePoolSummaryToMap(obj *oci_database.ResourcePoolSummary) map[string]interface{} {
2368+
result := map[string]interface{}{}
2369+
2370+
if obj.IsDisabled != nil {
2371+
result["is_disabled"] = bool(*obj.IsDisabled)
2372+
}
2373+
2374+
if obj.PoolSize != nil {
2375+
result["pool_size"] = int(*obj.PoolSize)
2376+
}
2377+
2378+
return result
2379+
}
2380+
22842381
func (s *DatabaseAutonomousDatabaseResourceCrud) mapToScheduledOperationDetails(fieldKeyFormat string) (oci_database.ScheduledOperationDetails, error) {
22852382
result := oci_database.ScheduledOperationDetails{}
22862383

@@ -2509,6 +2606,24 @@ func (s *DatabaseAutonomousDatabaseResourceCrud) populateTopLevelPolymorphicCrea
25092606
tmp := privateEndpointLabel.(string)
25102607
details.PrivateEndpointLabel = &tmp
25112608
}
2609+
2610+
if resourcePoolLeaderId, ok := s.D.GetOkExists("resource_pool_leader_id"); ok {
2611+
tmp := resourcePoolLeaderId.(string)
2612+
details.ResourcePoolLeaderId = &tmp
2613+
}
2614+
2615+
if resourcePoolSummary, ok := s.D.GetOk("resource_pool_summary"); ok {
2616+
t := fmt.Sprintf("%s rp create", resourcePoolSummary)
2617+
_, _ = io.WriteString(os.Stdout, t)
2618+
if tmpList := resourcePoolSummary.([]interface{}); len(tmpList) > 0 {
2619+
fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "resource_pool_summary", 0)
2620+
tmp, err := s.mapToResourcePoolSummary(fieldKeyFormat)
2621+
if err != nil {
2622+
return err
2623+
}
2624+
details.ResourcePoolSummary = &tmp
2625+
}
2626+
}
25122627
if scheduledOperations, ok := s.D.GetOkExists("scheduled_operations"); ok {
25132628
interfaces := scheduledOperations.([]interface{})
25142629
tmp := make([]oci_database.ScheduledOperationDetails, len(interfaces))
@@ -2752,6 +2867,22 @@ func (s *DatabaseAutonomousDatabaseResourceCrud) populateTopLevelPolymorphicCrea
27522867
tmp := privateEndpointLabel.(string)
27532868
details.PrivateEndpointLabel = &tmp
27542869
}
2870+
if resourcePoolLeaderId, ok := s.D.GetOkExists("resource_pool_leader_id"); ok {
2871+
tmp := resourcePoolLeaderId.(string)
2872+
details.ResourcePoolLeaderId = &tmp
2873+
}
2874+
if resourcePoolSummary, ok := s.D.GetOkExists("resource_pool_summary"); ok {
2875+
t := fmt.Sprintf("%s rp create backup", resourcePoolSummary)
2876+
_, _ = io.WriteString(os.Stdout, t)
2877+
if tmpList := resourcePoolSummary.([]interface{}); len(tmpList) > 0 {
2878+
fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "resource_pool_summary", 0)
2879+
tmp, err := s.mapToResourcePoolSummary(fieldKeyFormat)
2880+
if err != nil {
2881+
return err
2882+
}
2883+
details.ResourcePoolSummary = &tmp
2884+
}
2885+
}
27552886
if scheduledOperations, ok := s.D.GetOkExists("scheduled_operations"); ok {
27562887
interfaces := scheduledOperations.([]interface{})
27572888
tmp := make([]oci_database.ScheduledOperationDetails, len(interfaces))
@@ -2987,6 +3118,22 @@ func (s *DatabaseAutonomousDatabaseResourceCrud) populateTopLevelPolymorphicCrea
29873118
if refreshableMode, ok := s.D.GetOkExists("refreshable_mode"); ok {
29883119
details.RefreshableMode = oci_database.CreateRefreshableAutonomousDatabaseCloneDetailsRefreshableModeEnum(refreshableMode.(string))
29893120
}
3121+
if resourcePoolLeaderId, ok := s.D.GetOkExists("resource_pool_leader_id"); ok {
3122+
tmp := resourcePoolLeaderId.(string)
3123+
details.ResourcePoolLeaderId = &tmp
3124+
}
3125+
if resourcePoolSummary, ok := s.D.GetOkExists("resource_pool_summary"); ok {
3126+
t := fmt.Sprintf("%s rp create clone to refreshable", resourcePoolSummary)
3127+
_, _ = io.WriteString(os.Stdout, t)
3128+
if tmpList := resourcePoolSummary.([]interface{}); len(tmpList) > 0 {
3129+
fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "resource_pool_summary", 0)
3130+
tmp, err := s.mapToResourcePoolSummary(fieldKeyFormat)
3131+
if err != nil {
3132+
return err
3133+
}
3134+
details.ResourcePoolSummary = &tmp
3135+
}
3136+
}
29903137
if scheduledOperations, ok := s.D.GetOkExists("scheduled_operations"); ok {
29913138
interfaces := scheduledOperations.([]interface{})
29923139
tmp := make([]oci_database.ScheduledOperationDetails, len(interfaces))
@@ -3201,6 +3348,23 @@ func (s *DatabaseAutonomousDatabaseResourceCrud) populateTopLevelPolymorphicCrea
32013348
tmp := privateEndpointLabel.(string)
32023349
details.PrivateEndpointLabel = &tmp
32033350
}
3351+
3352+
if resourcePoolLeaderId, ok := s.D.GetOkExists("resource_pool_leader_id"); ok {
3353+
tmp := resourcePoolLeaderId.(string)
3354+
details.ResourcePoolLeaderId = &tmp
3355+
}
3356+
if resourcePoolSummary, ok := s.D.GetOkExists("resource_pool_summary"); ok {
3357+
t := fmt.Sprintf("%s rp create cross region DG", resourcePoolSummary)
3358+
_, _ = io.WriteString(os.Stdout, t)
3359+
if tmpList := resourcePoolSummary.([]interface{}); len(tmpList) > 0 {
3360+
fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "resource_pool_summary", 0)
3361+
tmp, err := s.mapToResourcePoolSummary(fieldKeyFormat)
3362+
if err != nil {
3363+
return err
3364+
}
3365+
details.ResourcePoolSummary = &tmp
3366+
}
3367+
}
32043368
if scheduledOperations, ok := s.D.GetOkExists("scheduled_operations"); ok {
32053369
interfaces := scheduledOperations.([]interface{})
32063370
tmp := make([]oci_database.ScheduledOperationDetails, len(interfaces))
@@ -3421,6 +3585,23 @@ func (s *DatabaseAutonomousDatabaseResourceCrud) populateTopLevelPolymorphicCrea
34213585
tmp := privateEndpointLabel.(string)
34223586
details.PrivateEndpointLabel = &tmp
34233587
}
3588+
3589+
if resourcePoolLeaderId, ok := s.D.GetOkExists("resource_pool_leader_id"); ok {
3590+
tmp := resourcePoolLeaderId.(string)
3591+
details.ResourcePoolLeaderId = &tmp
3592+
}
3593+
if resourcePoolSummary, ok := s.D.GetOkExists("resource_pool_summary"); ok {
3594+
t := fmt.Sprintf("%s rp create cross region disaster recovery", resourcePoolSummary)
3595+
_, _ = io.WriteString(os.Stdout, t)
3596+
if tmpList := resourcePoolSummary.([]interface{}); len(tmpList) > 0 {
3597+
fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "resource_pool_summary", 0)
3598+
tmp, err := s.mapToResourcePoolSummary(fieldKeyFormat)
3599+
if err != nil {
3600+
return err
3601+
}
3602+
details.ResourcePoolSummary = &tmp
3603+
}
3604+
}
34243605
if scheduledOperations, ok := s.D.GetOkExists("scheduled_operations"); ok {
34253606
interfaces := scheduledOperations.([]interface{})
34263607
tmp := make([]oci_database.ScheduledOperationDetails, len(interfaces))
@@ -3648,6 +3829,22 @@ func (s *DatabaseAutonomousDatabaseResourceCrud) populateTopLevelPolymorphicCrea
36483829
tmp := privateEndpointLabel.(string)
36493830
details.PrivateEndpointLabel = &tmp
36503831
}
3832+
if resourcePoolLeaderId, ok := s.D.GetOkExists("resource_pool_leader_id"); ok {
3833+
tmp := resourcePoolLeaderId.(string)
3834+
details.ResourcePoolLeaderId = &tmp
3835+
}
3836+
if resourcePoolSummary, ok := s.D.GetOkExists("resource_pool_summary"); ok {
3837+
t := fmt.Sprintf("%s rp create database", resourcePoolSummary)
3838+
_, _ = io.WriteString(os.Stdout, t)
3839+
if tmpList := resourcePoolSummary.([]interface{}); len(tmpList) > 0 {
3840+
fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "resource_pool_summary", 0)
3841+
tmp, err := s.mapToResourcePoolSummary(fieldKeyFormat)
3842+
if err != nil {
3843+
return err
3844+
}
3845+
details.ResourcePoolSummary = &tmp
3846+
}
3847+
}
36513848
if scheduledOperations, ok := s.D.GetOkExists("scheduled_operations"); ok {
36523849
interfaces := scheduledOperations.([]interface{})
36533850
tmp := make([]oci_database.ScheduledOperationDetails, len(interfaces))
@@ -3875,6 +4072,22 @@ func (s *DatabaseAutonomousDatabaseResourceCrud) populateTopLevelPolymorphicCrea
38754072
tmp := privateEndpointLabel.(string)
38764073
details.PrivateEndpointLabel = &tmp
38774074
}
4075+
if resourcePoolLeaderId, ok := s.D.GetOkExists("resource_pool_leader_id"); ok {
4076+
tmp := resourcePoolLeaderId.(string)
4077+
details.ResourcePoolLeaderId = &tmp
4078+
}
4079+
if resourcePoolSummary, ok := s.D.GetOkExists("resource_pool_summary"); ok {
4080+
t := fmt.Sprintf("%s rp create none", resourcePoolSummary)
4081+
_, _ = io.WriteString(os.Stdout, t)
4082+
if tmpList := resourcePoolSummary.([]interface{}); len(tmpList) > 0 {
4083+
fieldKeyFormat := fmt.Sprintf("%s.%d.%%s", "resource_pool_summary", 0)
4084+
tmp, err := s.mapToResourcePoolSummary(fieldKeyFormat)
4085+
if err != nil {
4086+
return err
4087+
}
4088+
details.ResourcePoolSummary = &tmp
4089+
}
4090+
}
38784091
if scheduledOperations, ok := s.D.GetOkExists("scheduled_operations"); ok {
38794092
interfaces := scheduledOperations.([]interface{})
38804093
tmp := make([]oci_database.ScheduledOperationDetails, len(interfaces))

0 commit comments

Comments
 (0)