Skip to content

Commit 688e82a

Browse files
Anirban ChatterjeeMaxrovr
authored andcommitted
Added - Support for [Elastic Pool Support for Child Tenancies] Terraform Support in Prod Region ADB-S: Elastic Pool Support for Child Tenancies
1 parent 4a96fad commit 688e82a

File tree

4 files changed

+371
-0
lines changed

4 files changed

+371
-0
lines changed
Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
// Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
package integrationtest
5+
6+
import (
7+
"fmt"
8+
"os"
9+
"testing"
10+
11+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
12+
"github.com/hashicorp/terraform-plugin-testing/terraform"
13+
14+
"github.com/oracle/terraform-provider-oci/httpreplay"
15+
"github.com/oracle/terraform-provider-oci/internal/acctest"
16+
17+
"github.com/oracle/terraform-provider-oci/internal/utils"
18+
)
19+
20+
var (
21+
autonomousDatabaseRepresentationRPNew = acctest.RepresentationCopyWithNewProperties(acctest.RepresentationCopyWithRemovedProperties(DatabaseAutonomousDatabaseRepresentation, []string{"cpu_core_count", "db_tools_details"}), map[string]interface{}{
22+
"compute_count": acctest.Representation{RepType: acctest.Required, Create: `4.0`, Update: `4.0`},
23+
"compute_model": acctest.Representation{RepType: acctest.Required, Create: `ECPU`},
24+
"resource_pool_summary": acctest.RepresentationGroup{RepType: acctest.Required, Group: DatabaseAutonomousDatabaseRPSummaryRepresentation},
25+
})
26+
27+
autonomousDatabaseRepresentationRPUpdateNew = acctest.RepresentationCopyWithNewProperties(acctest.RepresentationCopyWithRemovedProperties(DatabaseAutonomousDatabaseRepresentation, []string{"cpu_core_count", "db_tools_details"}), map[string]interface{}{
28+
"compute_count": acctest.Representation{RepType: acctest.Required, Create: `4.0`, Update: `4.0`},
29+
"compute_model": acctest.Representation{RepType: acctest.Required, Create: `ECPU`},
30+
"resource_pool_summary": acctest.RepresentationGroup{RepType: acctest.Required, Group: DatabaseAutonomousDatabaseRPSummaryRepresentation},
31+
})
32+
33+
DatabaseAutonomousDatabaseResourcePoolLeaderIdRepresentationNew = acctest.RepresentationCopyWithNewProperties(acctest.RepresentationCopyWithRemovedProperties(DatabaseAutonomousDatabaseRepresentation, []string{"cpu_core_count", "db_tools_details"}), map[string]interface{}{
34+
"compute_count": acctest.Representation{RepType: acctest.Required, Create: `10.0`, Update: `10.0`},
35+
"compute_model": acctest.Representation{RepType: acctest.Required, Create: `ECPU`},
36+
"resource_pool_leader_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_database_autonomous_database.test_autonomous_database_leader.id}`, Update: ` `},
37+
"db_name": acctest.Representation{RepType: acctest.Required, Create: adbMemberName},
38+
})
39+
40+
DatabaseAutonomousDatabaseResourcePoolLeaderIdUpdateRepresentationNew = acctest.RepresentationCopyWithNewProperties(acctest.RepresentationCopyWithRemovedProperties(DatabaseAutonomousDatabaseRepresentation, []string{"cpu_core_count", "admin_password", "db_tools_details"}), map[string]interface{}{
41+
"compute_count": acctest.Representation{RepType: acctest.Required, Create: `10.0`, Update: `12.0`},
42+
"resource_pool_leader_id": acctest.Representation{RepType: acctest.Required, Update: ` `},
43+
"db_name": acctest.Representation{RepType: acctest.Required, Create: adbMemberName},
44+
})
45+
46+
DatabaseAutonomousDatabaseResourcePoolMemberDataSourceRepresentation = map[string]interface{}{
47+
"autonomous_database_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_database_autonomous_database.test_autonomous_database_leader.id}`},
48+
}
49+
)
50+
51+
// issue-routing-tag: database/dbaas-adb
52+
func TestDatabaseAutonomousDatabaseResourcePoolMemberResource_basic(t *testing.T) {
53+
shouldSkipADBStest := os.Getenv("TF_VAR_should_skip_adbs_test")
54+
55+
if shouldSkipADBStest == "true" {
56+
t.Skip("Skipping TestDatabaseAutonomousDatabaseResourcePoolMemberResource_basic test.\n" + "Current TF_VAR_should_skip_adbs_test=" + shouldSkipADBStest)
57+
}
58+
59+
httpreplay.SetScenario("TestDatabaseAutonomousDatabaseResourcePoolMemberResource_basic")
60+
defer httpreplay.SaveScenario()
61+
62+
config := acctest.ProviderTestConfig()
63+
64+
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
65+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
66+
67+
resourceName := "oci_database_autonomous_database.test_autonomous_database_leader"
68+
resourceMemberName := "oci_database_autonomous_database.test_autonomous_database_member"
69+
datasourceName := "data.oci_database_autonomous_database_resource_pool_members.test_autonomous_database_resource_pool_members"
70+
71+
var resId, resId2 string
72+
73+
// 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.
74+
acctest.SaveConfigContent(config+compartmentIdVariableStr+DatabaseAutonomousDatabaseResourceDependencies+
75+
acctest.GenerateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database_leader", acctest.Optional, acctest.Create, autonomousDatabaseRepresentationRPNew), "database", "autonomousDatabase", t)
76+
77+
acctest.ResourceTest(t, testAccCheckDatabaseAutonomousDatabaseDestroy, []resource.TestStep{
78+
//0. Verify leader create
79+
{
80+
Config: config + compartmentIdVariableStr + DatabaseAutonomousDatabaseResourceDependencies +
81+
acctest.GenerateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database_leader", acctest.Required, acctest.Create, autonomousDatabaseRepresentationRPNew),
82+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
83+
resource.TestCheckResourceAttr(resourceName, "admin_password", "BEstrO0ng_#11"),
84+
resource.TestCheckResourceAttr(resourceName, "compartment_id", compartmentId),
85+
resource.TestCheckResourceAttr(resourceName, "cpu_core_count", "0"),
86+
resource.TestCheckResourceAttr(resourceName, "compute_count", "4"),
87+
resource.TestCheckResourceAttr(resourceName, "compute_model", "ECPU"),
88+
resource.TestCheckResourceAttr(resourceName, "db_name", adbName),
89+
// verify computed field db_workload to be defaulted to OLTP
90+
resource.TestCheckResourceAttr(resourceName, "db_workload", "OLTP"),
91+
resource.TestCheckResourceAttrSet(resourceName, "resource_pool_summary.#"),
92+
resource.TestCheckResourceAttrSet(resourceName, "resource_pool_summary.#"),
93+
resource.TestCheckResourceAttr(resourceName, "resource_pool_summary.#", "1"),
94+
resource.TestCheckResourceAttr(resourceName, "resource_pool_summary.0.is_disabled", "false"),
95+
resource.TestCheckResourceAttr(resourceName, "resource_pool_summary.0.pool_size", "128"),
96+
97+
func(s *terraform.State) (err error) {
98+
resId, err = acctest.FromInstanceState(s, resourceName, "id")
99+
return err
100+
},
101+
),
102+
},
103+
//1. Verify member create
104+
{
105+
Config: config + compartmentIdVariableStr + DatabaseAutonomousDatabaseResourceDependencies +
106+
acctest.GenerateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database_leader", acctest.Required, acctest.Create,
107+
acctest.RepresentationCopyWithNewProperties(autonomousDatabaseRepresentationRPNew, map[string]interface{}{
108+
"resource_pool_summary": acctest.RepresentationGroup{RepType: acctest.Required, Group: DatabaseAutonomousDatabaseRPSummaryRepresentation},
109+
})) + acctest.GenerateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database_member", acctest.Required, acctest.Create, DatabaseAutonomousDatabaseResourcePoolLeaderIdRepresentationNew),
110+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
111+
resource.TestCheckResourceAttr(resourceMemberName, "admin_password", "BEstrO0ng_#11"),
112+
resource.TestCheckResourceAttr(resourceMemberName, "compartment_id", compartmentId),
113+
resource.TestCheckResourceAttr(resourceMemberName, "cpu_core_count", "0"),
114+
resource.TestCheckResourceAttr(resourceMemberName, "compute_count", "10"),
115+
resource.TestCheckResourceAttr(resourceMemberName, "compute_model", "ECPU"),
116+
resource.TestCheckResourceAttr(resourceMemberName, "db_name", adbMemberName),
117+
// verify computed field db_workload to be defaulted to OLTP
118+
resource.TestCheckResourceAttr(resourceMemberName, "db_workload", "OLTP"),
119+
resource.TestCheckResourceAttrSet(resourceMemberName, "resource_pool_leader_id"),
120+
121+
func(s *terraform.State) (err error) {
122+
resId, err = acctest.FromInstanceState(s, resourceMemberName, "id")
123+
return err
124+
},
125+
),
126+
},
127+
//2. Verify list resource pool member
128+
{
129+
Config: config +
130+
acctest.GenerateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database_leader", acctest.Required, acctest.Create,
131+
acctest.RepresentationCopyWithNewProperties(autonomousDatabaseRepresentationRPNew, map[string]interface{}{
132+
"resource_pool_summary": acctest.RepresentationGroup{RepType: acctest.Required, Group: DatabaseAutonomousDatabaseRPSummaryUpdateRepresentation},
133+
})) +
134+
acctest.GenerateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database_member", acctest.Required, acctest.Create, DatabaseAutonomousDatabaseResourcePoolLeaderIdRepresentationNew) +
135+
acctest.GenerateDataSourceFromRepresentationMap("oci_database_autonomous_database_resource_pool_members", "test_autonomous_database_resource_pool_members", acctest.Required, acctest.Create, DatabaseAutonomousDatabaseResourcePoolMemberDataSourceRepresentation) +
136+
compartmentIdVariableStr,
137+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
138+
resource.TestCheckResourceAttrSet(datasourceName, "resource_pool_member_collection.#"),
139+
resource.TestCheckResourceAttr(datasourceName, "resource_pool_member_collection.0.items.#", "1"),
140+
),
141+
},
142+
//3. Verify member leaving the resource pool leader
143+
{
144+
Config: config + compartmentIdVariableStr + DatabaseAutonomousDatabaseResourceDependencies + acctest.GenerateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database_leader", acctest.Required, acctest.Create,
145+
acctest.RepresentationCopyWithNewProperties(autonomousDatabaseRepresentationRPNew, map[string]interface{}{
146+
"resource_pool_summary": acctest.RepresentationGroup{RepType: acctest.Required, Group: DatabaseAutonomousDatabaseRPSummaryRepresentation},
147+
})) + acctest.GenerateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database_member", acctest.Required, acctest.Update, DatabaseAutonomousDatabaseResourcePoolLeaderIdUpdateRepresentationNew),
148+
149+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
150+
resource.TestCheckResourceAttrSet(resourceMemberName, "resource_pool_leader_id"),
151+
resource.TestCheckResourceAttr(resourceMemberName, "resource_pool_leader_id", " "),
152+
153+
func(s *terraform.State) (err error) {
154+
resId2, err = acctest.FromInstanceState(s, resourceMemberName, "id")
155+
if resId != resId2 {
156+
return fmt.Errorf("resource recreated when it was supposed to be updated")
157+
}
158+
return err
159+
},
160+
),
161+
},
162+
//4. Verify disable resource pool leader
163+
{
164+
Config: config + compartmentIdVariableStr + DatabaseAutonomousDatabaseResourceDependencies +
165+
acctest.GenerateResourceFromRepresentationMap("oci_database_autonomous_database", "test_autonomous_database_leader", acctest.Required, acctest.Create,
166+
acctest.RepresentationCopyWithNewProperties(autonomousDatabaseRepresentationRPUpdateNew, map[string]interface{}{
167+
"resource_pool_summary": acctest.RepresentationGroup{RepType: acctest.Required, Group: DatabaseAutonomousDatabaseRPDisableSummaryRepresentation},
168+
})),
169+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
170+
resource.TestCheckResourceAttr(resourceName, "compute_model", "ECPU"),
171+
resource.TestCheckResourceAttr(resourceName, "total_backup_storage_size_in_gbs", "1000"),
172+
resource.TestCheckResourceAttrSet(resourceName, "resource_pool_summary.#"),
173+
resource.TestCheckResourceAttr(resourceName, "resource_pool_summary.#", "1"),
174+
resource.TestCheckResourceAttr(resourceName, "resource_pool_summary.0.is_disabled", "true"),
175+
func(s *terraform.State) (err error) {
176+
resId, err = acctest.FromInstanceState(s, resourceName, "id")
177+
return err
178+
},
179+
),
180+
},
181+
})
182+
}
Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,144 @@
1+
// Copyright (c) 2017, 2024, Oracle and/or its affiliates. All rights reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
package database
5+
6+
import (
7+
"context"
8+
9+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
10+
oci_database "github.com/oracle/oci-go-sdk/v65/database"
11+
12+
"github.com/oracle/terraform-provider-oci/internal/client"
13+
"github.com/oracle/terraform-provider-oci/internal/tfresource"
14+
)
15+
16+
func DatabaseAutonomousDatabaseResourcePoolMembersDataSource() *schema.Resource {
17+
return &schema.Resource{
18+
Read: readDatabaseAutonomousDatabaseResourcePoolMembers,
19+
Schema: map[string]*schema.Schema{
20+
"filter": tfresource.DataSourceFiltersSchema(),
21+
"autonomous_database_id": {
22+
Type: schema.TypeString,
23+
Required: true,
24+
},
25+
"resource_pool_member_collection": {
26+
Type: schema.TypeList,
27+
Computed: true,
28+
Elem: &schema.Resource{
29+
Schema: map[string]*schema.Schema{
30+
// Required
31+
32+
// Optional
33+
34+
// Computed
35+
"items": {
36+
Type: schema.TypeList,
37+
Computed: true,
38+
Elem: &schema.Resource{
39+
Schema: map[string]*schema.Schema{
40+
// Required
41+
42+
// Optional
43+
44+
// Computed
45+
"id": {
46+
Type: schema.TypeString,
47+
Computed: true,
48+
},
49+
},
50+
},
51+
},
52+
},
53+
},
54+
},
55+
},
56+
}
57+
}
58+
59+
func readDatabaseAutonomousDatabaseResourcePoolMembers(d *schema.ResourceData, m interface{}) error {
60+
sync := &DatabaseAutonomousDatabaseResourcePoolMembersDataSourceCrud{}
61+
sync.D = d
62+
sync.Client = m.(*client.OracleClients).DatabaseClient()
63+
64+
return tfresource.ReadResource(sync)
65+
}
66+
67+
type DatabaseAutonomousDatabaseResourcePoolMembersDataSourceCrud struct {
68+
D *schema.ResourceData
69+
Client *oci_database.DatabaseClient
70+
Res *oci_database.ListResourcePoolMembersResponse
71+
}
72+
73+
func (s *DatabaseAutonomousDatabaseResourcePoolMembersDataSourceCrud) VoidState() {
74+
s.D.SetId("")
75+
}
76+
77+
func (s *DatabaseAutonomousDatabaseResourcePoolMembersDataSourceCrud) Get() error {
78+
request := oci_database.ListResourcePoolMembersRequest{}
79+
80+
if autonomousDatabaseId, ok := s.D.GetOkExists("autonomous_database_id"); ok {
81+
tmp := autonomousDatabaseId.(string)
82+
request.AutonomousDatabaseId = &tmp
83+
}
84+
85+
request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(false, "database")
86+
87+
response, err := s.Client.ListResourcePoolMembers(context.Background(), request)
88+
if err != nil {
89+
return err
90+
}
91+
92+
s.Res = &response
93+
request.Page = s.Res.OpcNextPage
94+
95+
for request.Page != nil {
96+
listResponse, err := s.Client.ListResourcePoolMembers(context.Background(), request)
97+
if err != nil {
98+
return err
99+
}
100+
101+
s.Res.Items = append(s.Res.Items, listResponse.Items...)
102+
request.Page = listResponse.OpcNextPage
103+
}
104+
105+
return nil
106+
}
107+
108+
func (s *DatabaseAutonomousDatabaseResourcePoolMembersDataSourceCrud) SetData() error {
109+
if s.Res == nil {
110+
return nil
111+
}
112+
113+
s.D.SetId(tfresource.GenerateDataSourceHashID("DatabaseAutonomousDatabaseResourcePoolMembersDataSource-", DatabaseAutonomousDatabaseResourcePoolMembersDataSource(), s.D))
114+
resources := []map[string]interface{}{}
115+
autonomousDatabaseResourcePoolMember := map[string]interface{}{}
116+
117+
items := []interface{}{}
118+
for _, item := range s.Res.Items {
119+
items = append(items, ResourcePoolMemberSummaryToMap(item))
120+
}
121+
autonomousDatabaseResourcePoolMember["items"] = items
122+
123+
if f, fOk := s.D.GetOkExists("filter"); fOk {
124+
items = tfresource.ApplyFiltersInCollection(f.(*schema.Set), items, DatabaseAutonomousDatabaseResourcePoolMembersDataSource().Schema["resource_pool_member_collection"].Elem.(*schema.Resource).Schema)
125+
autonomousDatabaseResourcePoolMember["items"] = items
126+
}
127+
128+
resources = append(resources, autonomousDatabaseResourcePoolMember)
129+
if err := s.D.Set("resource_pool_member_collection", resources); err != nil {
130+
return err
131+
}
132+
133+
return nil
134+
}
135+
136+
func ResourcePoolMemberSummaryToMap(obj oci_database.ResourcePoolMemberSummary) map[string]interface{} {
137+
result := map[string]interface{}{}
138+
139+
if obj.Id != nil {
140+
result["id"] = string(*obj.Id)
141+
}
142+
143+
return result
144+
}

internal/service/database/register_datasource.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func RegisterDatasource() {
2525
tfresource.RegisterDatasource("oci_database_autonomous_database_peers", DatabaseAutonomousDatabasePeersDataSource())
2626
tfresource.RegisterDatasource("oci_database_autonomous_database_refreshable_clones", DatabaseAutonomousDatabaseRefreshableClonesDataSource())
2727
tfresource.RegisterDatasource("oci_database_autonomous_database_regional_wallet_management", DatabaseAutonomousDatabaseRegionalWalletManagementDataSource())
28+
tfresource.RegisterDatasource("oci_database_autonomous_database_resource_pool_members", DatabaseAutonomousDatabaseResourcePoolMembersDataSource())
2829
tfresource.RegisterDatasource("oci_database_autonomous_database_software_image", DatabaseAutonomousDatabaseSoftwareImageDataSource())
2930
tfresource.RegisterDatasource("oci_database_autonomous_database_software_images", DatabaseAutonomousDatabaseSoftwareImagesDataSource())
3031
tfresource.RegisterDatasource("oci_database_autonomous_database_wallet", DatabaseAutonomousDatabaseWalletDataSource())
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
subcategory: "Database"
3+
layout: "oci"
4+
page_title: "Oracle Cloud Infrastructure: oci_database_autonomous_database_resource_pool_members"
5+
sidebar_current: "docs-oci-datasource-database-autonomous_database_resource_pool_members"
6+
description: |-
7+
Provides the list of Autonomous Database Resource Pool Members in Oracle Cloud Infrastructure Database service
8+
---
9+
10+
# Data Source: oci_database_autonomous_database_resource_pool_members
11+
This data source provides the list of Autonomous Database Resource Pool Members in Oracle Cloud Infrastructure Database service.
12+
13+
Lists the OCIDs of the Autonomous Database resource pool members for the specified Autonomous Database leader.
14+
15+
16+
## Example Usage
17+
18+
```hcl
19+
data "oci_database_autonomous_database_resource_pool_members" "test_autonomous_database_resource_pool_members" {
20+
#Required
21+
autonomous_database_id = oci_database_autonomous_database.test_autonomous_database.id
22+
}
23+
```
24+
25+
## Argument Reference
26+
27+
The following arguments are supported:
28+
29+
* `autonomous_database_id` - (Required) The database [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm).
30+
31+
32+
## Attributes Reference
33+
34+
The following attributes are exported:
35+
36+
* `resource_pool_member_collection` - The list of resource_pool_member_collection.
37+
38+
### AutonomousDatabaseResourcePoolMember Reference
39+
40+
The following attributes are exported:
41+
42+
* `items` - List of resource pool member summary.
43+
* `id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the Autonomous Database.
44+

0 commit comments

Comments
 (0)