Skip to content

Commit b20f325

Browse files
Terraform Team Automationsagarp337
authored andcommitted
Added - Support for Node Subsetting | ADB-D
1 parent 5636cc1 commit b20f325

File tree

32 files changed

+538
-98
lines changed

32 files changed

+538
-98
lines changed

examples/database/atp-d/main.tf

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ resource "oci_database_autonomous_container_database" "test_autonomous_container
5959
db_version = "19.18.0.1.0"
6060
}
6161

62+
variable "cloud_exadata_infrastructure_un_allocated_resource_db_servers" {
63+
default = []
64+
}
65+
6266
resource "random_string" "autonomous_database_admin_password" {
6367
length = 16
6468
min_numeric = 1
@@ -146,4 +150,7 @@ output "autonomous_container_databases" {
146150
data "oci_database_cloud_exadata_infrastructure_un_allocated_resource" "test_cloud_exadata_infrastructure_un_allocated_resources" {
147151
#Required
148152
cloud_exadata_infrastructure_id = oci_database_cloud_exadata_infrastructure.test_cloud_exadata_infrastructure.id
153+
154+
#Optional
155+
db_servers = var.cloud_exadata_infrastructure_un_allocated_resource_db_servers
149156
}

internal/integrationtest/database_cloud_exadata_infrastructure_un_allocated_resource_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
var (
1919
DatabaseCloudExadataInfrastructureUnAllocatedResourceSingularDataSourceRepresentation = map[string]interface{}{
2020
"cloud_exadata_infrastructure_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_database_cloud_exadata_infrastructure.test_cloud_exadata_infrastructure.id}`},
21+
"db_servers": acctest.Representation{RepType: acctest.Optional, Create: []string{`dbServers`}},
2122
}
2223

2324
DatabaseCloudExadataInfrastructureUnAllocatedResourceResourceConfig = acctest.GenerateResourceFromRepresentationMap("oci_database_cloud_exadata_infrastructure", "test_cloud_exadata_infrastructure", acctest.Required, acctest.Create, DatabaseCloudExadataInfrastructureRepresentation) +
@@ -46,7 +47,6 @@ func TestDatabaseCloudExadataInfrastructureUnAllocatedResourceResource_basic(t *
4647
compartmentIdVariableStr + DatabaseCloudExadataInfrastructureUnAllocatedResourceResourceConfig,
4748
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
4849
resource.TestCheckResourceAttrSet(singularDatasourceName, "cloud_exadata_infrastructure_id"),
49-
5050
resource.TestCheckResourceAttr(singularDatasourceName, "cloud_autonomous_vm_clusters.#", "0"),
5151
resource.TestCheckResourceAttrSet(singularDatasourceName, "cloud_exadata_infrastructure_display_name"),
5252
resource.TestCheckResourceAttrSet(singularDatasourceName, "exadata_storage_in_tbs"),
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Copyright (c) 2017, 2023, 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+
"testing"
9+
10+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
11+
12+
"github.com/oracle/terraform-provider-oci/httpreplay"
13+
"github.com/oracle/terraform-provider-oci/internal/acctest"
14+
15+
"github.com/oracle/terraform-provider-oci/internal/utils"
16+
)
17+
18+
var (
19+
DatabaseDatabaseExadataInfrastructureUnAllocatedResourceSingularDataSourceRepresentation = map[string]interface{}{
20+
"exadata_infrastructure_id": acctest.Representation{RepType: acctest.Required, Create: `${oci_database_exadata_infrastructure.test_exadata_infrastructure.id}`},
21+
"db_servers": acctest.Representation{RepType: acctest.Optional, Create: []string{`dbServers`}},
22+
}
23+
24+
DatabaseExadataInfrastructureUnAllocatedResourceResourceConfig = acctest.GenerateResourceFromRepresentationMap("oci_database_exadata_infrastructure", "test_exadata_infrastructure", acctest.Required, acctest.Create, DatabaseExadataInfrastructureRepresentation)
25+
)
26+
27+
// issue-routing-tag: database/ExaCC
28+
func TestDatabaseExadataInfrastructureUnAllocatedResourceResource_basic(t *testing.T) {
29+
httpreplay.SetScenario("TestDatabaseExadataInfrastructureUnAllocatedResourceResource_basic")
30+
defer httpreplay.SaveScenario()
31+
32+
config := acctest.ProviderTestConfig()
33+
34+
compartmentId := utils.GetEnvSettingWithBlankDefault("compartment_ocid")
35+
compartmentIdVariableStr := fmt.Sprintf("variable \"compartment_id\" { default = \"%s\" }\n", compartmentId)
36+
37+
singularDatasourceName := "data.oci_database_exadata_infrastructure_un_allocated_resource.test_exadata_infrastructure_un_allocated_resource"
38+
39+
acctest.SaveConfigContent("", "", "", t)
40+
41+
acctest.ResourceTest(t, nil, []resource.TestStep{
42+
// verify singular datasource
43+
{
44+
Config: config +
45+
acctest.GenerateDataSourceFromRepresentationMap("oci_database_exadata_infrastructure_un_allocated_resource", "test_exadata_infrastructure_un_allocated_resource", acctest.Required, acctest.Create, DatabaseDatabaseExadataInfrastructureUnAllocatedResourceSingularDataSourceRepresentation) +
46+
compartmentIdVariableStr + DatabaseExadataInfrastructureUnAllocatedResourceResourceConfig,
47+
Check: acctest.ComposeAggregateTestCheckFuncWrapper(
48+
resource.TestCheckResourceAttrSet(singularDatasourceName, "exadata_infrastructure_id"),
49+
50+
resource.TestCheckResourceAttr(singularDatasourceName, "autonomous_vm_clusters.#", "0"),
51+
resource.TestCheckResourceAttrSet(singularDatasourceName, "display_name"),
52+
resource.TestCheckResourceAttrSet(singularDatasourceName, "exadata_storage_in_tbs"),
53+
resource.TestCheckResourceAttrSet(singularDatasourceName, "id"),
54+
resource.TestCheckResourceAttrSet(singularDatasourceName, "local_storage_in_gbs"),
55+
resource.TestCheckResourceAttrSet(singularDatasourceName, "memory_in_gbs"),
56+
resource.TestCheckResourceAttrSet(singularDatasourceName, "ocpus"),
57+
),
58+
},
59+
})
60+
}

internal/service/database/database_cloud_autonomous_vm_cluster_data_source.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ func (s *DatabaseCloudAutonomousVmClusterDataSourceCrud) SetData() error {
120120
s.D.Set("db_node_storage_size_in_gbs", *s.Res.DbNodeStorageSizeInGBs)
121121
}
122122

123+
s.D.Set("db_servers", s.Res.DbServers)
124+
123125
if s.Res.DefinedTags != nil {
124126
s.D.Set("defined_tags", tfresource.DefinedTagsToMap(s.Res.DefinedTags))
125127
}

internal/service/database/database_cloud_autonomous_vm_cluster_resource.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -874,6 +874,8 @@ func (s *DatabaseCloudAutonomousVmClusterResourceCrud) SetData() error {
874874
s.D.Set("db_node_storage_size_in_gbs", *s.Res.DbNodeStorageSizeInGBs)
875875
}
876876

877+
s.D.Set("db_servers", s.Res.DbServers)
878+
877879
if s.Res.DefinedTags != nil {
878880
s.D.Set("defined_tags", tfresource.DefinedTagsToMap(s.Res.DefinedTags))
879881
}

internal/service/database/database_cloud_autonomous_vm_clusters_data_source.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,8 @@ func (s *DatabaseCloudAutonomousVmClustersDataSourceCrud) SetData() error {
178178
cloudAutonomousVmCluster["db_node_storage_size_in_gbs"] = *r.DbNodeStorageSizeInGBs
179179
}
180180

181+
cloudAutonomousVmCluster["db_servers"] = r.DbServers
182+
181183
if r.DefinedTags != nil {
182184
cloudAutonomousVmCluster["defined_tags"] = tfresource.DefinedTagsToMap(r.DefinedTags)
183185
}

internal/service/database/database_cloud_exadata_infrastructure_un_allocated_resource_data_source.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ func DatabaseCloudExadataInfrastructureUnAllocatedResourceDataSource() *schema.R
2020
Type: schema.TypeString,
2121
Required: true,
2222
},
23+
"db_servers": {
24+
Type: schema.TypeList,
25+
Optional: true,
26+
Elem: &schema.Schema{
27+
Type: schema.TypeString,
28+
},
29+
},
2330
// Computed
2431
"cloud_autonomous_vm_clusters": {
2532
Type: schema.TypeList,
@@ -92,6 +99,19 @@ func (s *DatabaseCloudExadataInfrastructureUnAllocatedResourceDataSourceCrud) Ge
9299
request.CloudExadataInfrastructureId = &tmp
93100
}
94101

102+
if dbServers, ok := s.D.GetOkExists("db_servers"); ok {
103+
interfaces := dbServers.([]interface{})
104+
tmp := make([]string, len(interfaces))
105+
for i := range interfaces {
106+
if interfaces[i] != nil {
107+
tmp[i] = interfaces[i].(string)
108+
}
109+
}
110+
if len(tmp) != 0 || s.D.HasChange("db_servers") {
111+
request.DbServers = tmp
112+
}
113+
}
114+
95115
request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(false, "database")
96116

97117
response, err := s.Client.GetCloudExadataInfrastructureUnallocatedResources(context.Background(), request)
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
// Copyright (c) 2017, 2023, 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 DatabaseExadataInfrastructureUnAllocatedResourceDataSource() *schema.Resource {
17+
return &schema.Resource{
18+
Read: readSingularDatabaseExadataInfrastructureUnAllocatedResource,
19+
Schema: map[string]*schema.Schema{
20+
"db_servers": {
21+
Type: schema.TypeList,
22+
Optional: true,
23+
Elem: &schema.Schema{
24+
Type: schema.TypeString,
25+
},
26+
},
27+
"exadata_infrastructure_id": {
28+
Type: schema.TypeString,
29+
Required: true,
30+
},
31+
// Computed
32+
"autonomous_vm_clusters": {
33+
Type: schema.TypeList,
34+
Computed: true,
35+
Elem: &schema.Resource{
36+
Schema: map[string]*schema.Schema{
37+
// Required
38+
39+
// Optional
40+
41+
// Computed
42+
"id": {
43+
Type: schema.TypeString,
44+
Computed: true,
45+
},
46+
"un_allocated_adb_storage_in_tbs": {
47+
Type: schema.TypeFloat,
48+
Computed: true,
49+
},
50+
},
51+
},
52+
},
53+
"display_name": {
54+
Type: schema.TypeString,
55+
Computed: true,
56+
},
57+
"exadata_storage_in_tbs": {
58+
Type: schema.TypeFloat,
59+
Computed: true,
60+
},
61+
"local_storage_in_gbs": {
62+
Type: schema.TypeInt,
63+
Computed: true,
64+
},
65+
"memory_in_gbs": {
66+
Type: schema.TypeInt,
67+
Computed: true,
68+
},
69+
"ocpus": {
70+
Type: schema.TypeInt,
71+
Computed: true,
72+
},
73+
},
74+
}
75+
}
76+
77+
func readSingularDatabaseExadataInfrastructureUnAllocatedResource(d *schema.ResourceData, m interface{}) error {
78+
sync := &DatabaseExadataInfrastructureUnAllocatedResourceDataSourceCrud{}
79+
sync.D = d
80+
sync.Client = m.(*client.OracleClients).DatabaseClient()
81+
82+
return tfresource.ReadResource(sync)
83+
}
84+
85+
type DatabaseExadataInfrastructureUnAllocatedResourceDataSourceCrud struct {
86+
D *schema.ResourceData
87+
Client *oci_database.DatabaseClient
88+
Res *oci_database.GetExadataInfrastructureUnAllocatedResourcesResponse
89+
}
90+
91+
func (s *DatabaseExadataInfrastructureUnAllocatedResourceDataSourceCrud) VoidState() {
92+
s.D.SetId("")
93+
}
94+
95+
func (s *DatabaseExadataInfrastructureUnAllocatedResourceDataSourceCrud) Get() error {
96+
request := oci_database.GetExadataInfrastructureUnAllocatedResourcesRequest{}
97+
98+
if dbServers, ok := s.D.GetOkExists("db_servers"); ok {
99+
interfaces := dbServers.([]interface{})
100+
tmp := make([]string, len(interfaces))
101+
for i := range interfaces {
102+
if interfaces[i] != nil {
103+
tmp[i] = interfaces[i].(string)
104+
}
105+
}
106+
if len(tmp) != 0 || s.D.HasChange("db_servers") {
107+
request.DbServers = tmp
108+
}
109+
}
110+
111+
if exadataInfrastructureId, ok := s.D.GetOkExists("exadata_infrastructure_id"); ok {
112+
tmp := exadataInfrastructureId.(string)
113+
request.ExadataInfrastructureId = &tmp
114+
}
115+
116+
request.RequestMetadata.RetryPolicy = tfresource.GetRetryPolicy(false, "database")
117+
118+
response, err := s.Client.GetExadataInfrastructureUnAllocatedResources(context.Background(), request)
119+
if err != nil {
120+
return err
121+
}
122+
123+
s.Res = &response
124+
return nil
125+
}
126+
127+
func (s *DatabaseExadataInfrastructureUnAllocatedResourceDataSourceCrud) SetData() error {
128+
if s.Res == nil {
129+
return nil
130+
}
131+
132+
s.D.SetId(*s.Res.Id)
133+
134+
autonomousVmClusters := []interface{}{}
135+
for _, item := range s.Res.AutonomousVmClusters {
136+
autonomousVmClusters = append(autonomousVmClusters, AutonomousVmClusterResourceDetailsToMap(item))
137+
}
138+
s.D.Set("autonomous_vm_clusters", autonomousVmClusters)
139+
140+
if s.Res.DisplayName != nil {
141+
s.D.Set("display_name", *s.Res.DisplayName)
142+
}
143+
144+
if s.Res.ExadataStorageInTBs != nil {
145+
s.D.Set("exadata_storage_in_tbs", *s.Res.ExadataStorageInTBs)
146+
}
147+
148+
if s.Res.LocalStorageInGbs != nil {
149+
s.D.Set("local_storage_in_gbs", *s.Res.LocalStorageInGbs)
150+
}
151+
152+
if s.Res.MemoryInGBs != nil {
153+
s.D.Set("memory_in_gbs", *s.Res.MemoryInGBs)
154+
}
155+
156+
if s.Res.Ocpus != nil {
157+
s.D.Set("ocpus", *s.Res.Ocpus)
158+
}
159+
160+
return nil
161+
}
162+
163+
func AutonomousVmClusterResourceDetailsToMap(obj oci_database.AutonomousVmClusterResourceDetails) map[string]interface{} {
164+
result := map[string]interface{}{}
165+
166+
if obj.Id != nil {
167+
result["id"] = string(*obj.Id)
168+
}
169+
170+
if obj.UnAllocatedAdbStorageInTBs != nil {
171+
result["un_allocated_adb_storage_in_tbs"] = float64(*obj.UnAllocatedAdbStorageInTBs)
172+
}
173+
174+
return result
175+
}

internal/service/database/register_datasource.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ func RegisterDatasource() {
7676
tfresource.RegisterDatasource("oci_database_db_versions", DatabaseDbVersionsDataSource())
7777
tfresource.RegisterDatasource("oci_database_exadata_infrastructure", DatabaseExadataInfrastructureDataSource())
7878
tfresource.RegisterDatasource("oci_database_exadata_infrastructure_download_config_file", DatabaseExadataInfrastructureDownloadConfigFileDataSource())
79+
tfresource.RegisterDatasource("oci_database_exadata_infrastructure_un_allocated_resource", DatabaseExadataInfrastructureUnAllocatedResourceDataSource())
7980
tfresource.RegisterDatasource("oci_database_exadata_infrastructures", DatabaseExadataInfrastructuresDataSource())
8081
tfresource.RegisterDatasource("oci_database_exadata_iorm_config", DatabaseExadataIormConfigDataSource())
8182
tfresource.RegisterDatasource("oci_database_external_container_database", DatabaseExternalContainerDatabaseDataSource())

website/docs/d/database_autonomous_container_database.html.markdown

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ The following attributes are exported:
4848
* `cloud_autonomous_vm_cluster_id` - The [OCID](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/identifiers.htm) of the cloud Autonomous Exadata VM Cluster.
4949
* `compartment_id` - The OCID of the compartment.
5050
* `compute_model` - The compute model of the Autonomous VM Cluster. See [Compute Models in Autonomous Database on Dedicated Exadata Infrastructure](https://docs.oracle.com/en/cloud/paas/autonomous-database/dedicated/adbak) for more details.
51-
* `db_name` - The database name for the Autonomous Container Database. The name must be unique within the Cloud Autonomous VM Cluster, must start with an alphabetic character and followed by 1 to 7 alphanumeric characters.
51+
* `db_name` - The Database name for the Autonomous Container Database. The name must be unique within the Cloud Autonomous VM Cluster, starting with an alphabetic character, followed by 1 to 7 alphanumeric characters.
5252
* `db_unique_name` - **Deprecated.** The `DB_UNIQUE_NAME` value is set by Oracle Cloud Infrastructure. Do not specify a value for this parameter. Specifying a value for this field will cause Terraform operations to fail.
5353
* `db_version` - Oracle Database version of the Autonomous Container Database.
5454
* `defined_tags` - Defined tags for this resource. Each key is predefined and scoped to a namespace. For more information, see [Resource Tags](https://docs.cloud.oracle.com/iaas/Content/General/Concepts/resourcetags.htm).

0 commit comments

Comments
 (0)