Skip to content

Commit 00c0628

Browse files
Feat: Add google_oracle_database_db_nodes datasource (#11988) (#8420)
[upstream:4cabc2cd2ee2b0dafb207beea9de6851aee1de5c] Signed-off-by: Modular Magician <[email protected]>
1 parent 92d3880 commit 00c0628

File tree

5 files changed

+335
-0
lines changed

5 files changed

+335
-0
lines changed

Diff for: .changelog/11988.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:new-datasource
2+
`google_oracle_database_db_nodes`
3+
```

Diff for: google-beta/provider/provider_mmv1_resources.go

+1
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,7 @@ var handwrittenDatasources = map[string]*schema.Resource{
293293
"google_monitoring_app_engine_service": monitoring.DataSourceMonitoringServiceAppEngine(),
294294
"google_monitoring_uptime_check_ips": monitoring.DataSourceGoogleMonitoringUptimeCheckIps(),
295295
"google_netblock_ip_ranges": resourcemanager.DataSourceGoogleNetblockIpRanges(),
296+
"google_oracle_database_db_nodes": oracledatabase.DataSourceOracleDatabaseDbNodes(),
296297
"google_oracle_database_db_servers": oracledatabase.DataSourceOracleDatabaseDbServers(),
297298
"google_oracle_database_cloud_vm_cluster": oracledatabase.DataSourceOracleDatabaseCloudVmCluster(),
298299
"google_oracle_database_cloud_exadata_infrastructure": oracledatabase.DataSourceOracleDatabaseCloudExadataInfrastructure(),
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,216 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
package oracledatabase
4+
5+
import (
6+
"fmt"
7+
8+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
9+
"github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource"
10+
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
11+
)
12+
13+
func DataSourceOracleDatabaseDbNodes() *schema.Resource {
14+
dsSchema := map[string]*schema.Schema{
15+
"project": {
16+
Type: schema.TypeString,
17+
Optional: true,
18+
Description: "The ID of the project in which the dataset is located. If it is not provided, the provider project is used.",
19+
},
20+
"location": {
21+
Type: schema.TypeString,
22+
Required: true,
23+
Description: "location",
24+
},
25+
"cloud_vm_cluster": {
26+
Type: schema.TypeString,
27+
Required: true,
28+
Description: "vmcluster",
29+
},
30+
"db_nodes": {
31+
Type: schema.TypeList,
32+
Computed: true,
33+
Elem: &schema.Resource{
34+
Schema: map[string]*schema.Schema{
35+
"name": {
36+
Type: schema.TypeString,
37+
Computed: true,
38+
Description: "The dbnode name",
39+
},
40+
"properties": {
41+
Type: schema.TypeList,
42+
Computed: true,
43+
Elem: &schema.Resource{
44+
Schema: map[string]*schema.Schema{
45+
"ocid": {
46+
Type: schema.TypeString,
47+
Computed: true,
48+
Description: "Output only",
49+
},
50+
"ocpu_count": {
51+
Type: schema.TypeInt,
52+
Computed: true,
53+
Description: "Output only",
54+
},
55+
"memory_size_gb": {
56+
Type: schema.TypeInt,
57+
Computed: true,
58+
Description: "Output only",
59+
},
60+
"db_node_storage_size_gb": {
61+
Type: schema.TypeInt,
62+
Computed: true,
63+
Description: "Output only",
64+
},
65+
"db_server_ocid": {
66+
Type: schema.TypeString,
67+
Computed: true,
68+
Description: "Output only",
69+
},
70+
"hostname": {
71+
Type: schema.TypeString,
72+
Computed: true,
73+
Description: "Output only",
74+
},
75+
"state": {
76+
Type: schema.TypeString,
77+
Computed: true,
78+
Description: "Output only",
79+
},
80+
"total_cpu_core_count": {
81+
Type: schema.TypeInt,
82+
Computed: true,
83+
Description: "Output only",
84+
},
85+
},
86+
},
87+
},
88+
},
89+
},
90+
},
91+
}
92+
return &schema.Resource{
93+
Read: DataSourceOracleDatabaseDbNodesRead,
94+
Schema: dsSchema,
95+
}
96+
}
97+
98+
func DataSourceOracleDatabaseDbNodesRead(d *schema.ResourceData, meta interface{}) error {
99+
config := meta.(*transport_tpg.Config)
100+
userAgent, err := tpgresource.GenerateUserAgentString(d, config.UserAgent)
101+
if err != nil {
102+
return err
103+
}
104+
url, err := tpgresource.ReplaceVars(d, config, "{{OracleDatabaseBasePath}}projects/{{project}}/locations/{{location}}/cloudVmClusters/{{cloud_vm_cluster}}/dbNodes")
105+
if err != nil {
106+
return err
107+
}
108+
billingProject := ""
109+
project, err := tpgresource.GetProject(d, config)
110+
if err != nil {
111+
return fmt.Errorf("Error fetching project for DbNode: %s", err)
112+
}
113+
billingProject = project
114+
// err == nil indicates that the billing_project value was found
115+
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
116+
billingProject = bp
117+
}
118+
res, err := transport_tpg.SendRequest(transport_tpg.SendRequestOptions{
119+
Config: config,
120+
Method: "GET",
121+
Project: billingProject,
122+
RawURL: url,
123+
UserAgent: userAgent,
124+
})
125+
126+
if err != nil {
127+
return fmt.Errorf("Error reading DbNode: %s", err)
128+
}
129+
130+
if err := d.Set("project", project); err != nil {
131+
return fmt.Errorf("Error reading DbNode: %s", err)
132+
}
133+
if err := d.Set("db_nodes", flattenOracleDatabaseDbNodes(res["dbNodes"], d, config)); err != nil {
134+
return fmt.Errorf("Error reading DbNode: %s", err)
135+
}
136+
id, err := tpgresource.ReplaceVars(d, config, "projects/{{project}}/locations/{{location}}/cloudVmClusters/{{cloud_vm_cluster}}/dbNodes")
137+
if err != nil {
138+
return fmt.Errorf("Error constructing id: %s", err)
139+
}
140+
d.SetId(id)
141+
return nil
142+
}
143+
144+
func flattenOracleDatabaseDbNodes(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) []map[string]interface{} {
145+
if v == nil {
146+
return nil
147+
}
148+
l := v.([]interface{})
149+
transformed := make([]map[string]interface{}, 0)
150+
for _, raw := range l {
151+
original := raw.(map[string]interface{})
152+
transformed = append(transformed, map[string]interface{}{
153+
"name": flattenOracleDatabaseDbNodeName(original["name"], d, config),
154+
"properties": flattenOracleDatabaseDbNodeProperties(original["properties"], d, config),
155+
})
156+
}
157+
158+
return transformed
159+
}
160+
161+
func flattenOracleDatabaseDbNodeName(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
162+
return v
163+
}
164+
165+
func flattenOracleDatabaseDbNodeProperties(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
166+
if v == nil {
167+
return nil
168+
}
169+
original := v.(map[string]interface{})
170+
if len(original) == 0 {
171+
return nil
172+
}
173+
transformed := make(map[string]interface{})
174+
transformed["ocid"] = flattenOracleDatabaseDbNodePropertiesOcid(original["ocid"], d, config)
175+
transformed["ocpu_count"] = flattenOracleDatabaseDbNodePropertiesOcpuCount(original["ocpuCount"], d, config)
176+
transformed["memory_size_gb"] = flattenOracleDatabaseDbNodePropertiesMemorySizeGb(original["memorySizeGb"], d, config)
177+
transformed["db_node_storage_size_gb"] = flattenOracleDatabaseDbNodePropertiesDbNodeStorageSizeGb(original["dbNodeStorageSizeGb"], d, config)
178+
transformed["db_server_ocid"] = flattenOracleDatabaseDbNodePropertiesDbServerOcid(original["dbServerOcid"], d, config)
179+
transformed["hostname"] = flattenOracleDatabaseDbNodePropertiesHostname(original["hostname"], d, config)
180+
transformed["state"] = flattenOracleDatabaseDbNodePropertiesState(original["state"], d, config)
181+
transformed["total_cpu_core_count"] = flattenOracleDatabaseDbNodePropertiesTotalCpuCoreCount(original["totalCpuCoreCount"], d, config)
182+
183+
return []interface{}{transformed}
184+
}
185+
186+
func flattenOracleDatabaseDbNodePropertiesOcid(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
187+
return v
188+
}
189+
190+
func flattenOracleDatabaseDbNodePropertiesOcpuCount(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
191+
return v
192+
}
193+
194+
func flattenOracleDatabaseDbNodePropertiesMemorySizeGb(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
195+
return v
196+
}
197+
198+
func flattenOracleDatabaseDbNodePropertiesDbNodeStorageSizeGb(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
199+
return v
200+
}
201+
202+
func flattenOracleDatabaseDbNodePropertiesDbServerOcid(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
203+
return v
204+
}
205+
206+
func flattenOracleDatabaseDbNodePropertiesHostname(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
207+
return v
208+
}
209+
210+
func flattenOracleDatabaseDbNodePropertiesState(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
211+
return v
212+
}
213+
214+
func flattenOracleDatabaseDbNodePropertiesTotalCpuCoreCount(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
215+
return v
216+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
package oracledatabase_test
4+
5+
import (
6+
"fmt"
7+
"testing"
8+
9+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
10+
"github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
11+
)
12+
13+
func TestAccOracleDatabaseDbNodes_basic(t *testing.T) {
14+
t.Parallel()
15+
acctest.VcrTest(t, resource.TestCase{
16+
PreCheck: func() { acctest.AccTestPreCheck(t) },
17+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
18+
Steps: []resource.TestStep{
19+
{
20+
Config: testAccOracleDatabaseDbNodesConfig(),
21+
Check: resource.ComposeTestCheckFunc(
22+
resource.TestCheckResourceAttrSet("data.google_oracle_database_db_nodes.my_db_nodes", "db_nodes.#"),
23+
resource.TestCheckResourceAttrSet("data.google_oracle_database_db_nodes.my_db_nodes", "db_nodes.0.name"),
24+
resource.TestCheckResourceAttrSet("data.google_oracle_database_db_nodes.my_db_nodes", "db_nodes.0.properties.#"),
25+
resource.TestCheckResourceAttrSet("data.google_oracle_database_db_nodes.my_db_nodes", "db_nodes.1.name"),
26+
resource.TestCheckResourceAttrSet("data.google_oracle_database_db_nodes.my_db_nodes", "db_nodes.1.properties.#"),
27+
resource.TestCheckResourceAttr("data.google_oracle_database_db_nodes.my_db_nodes", "db_nodes.0.properties.0.state", "AVAILABLE"),
28+
resource.TestCheckResourceAttr("data.google_oracle_database_db_nodes.my_db_nodes", "db_nodes.1.properties.0.state", "AVAILABLE"),
29+
),
30+
},
31+
},
32+
})
33+
}
34+
35+
func testAccOracleDatabaseDbNodesConfig() string {
36+
return fmt.Sprintf(`
37+
data "google_oracle_database_db_nodes" "my_db_nodes"{
38+
location = "us-east4"
39+
project = "oci-terraform-testing"
40+
cloud_vm_cluster = "ofake-do-not-delete-tf-vmcluster"
41+
}
42+
`)
43+
}
+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
---
2+
subcategory: "Oracle Database"
3+
description: |-
4+
List all database nodes of a Cloud VmCluster.
5+
---
6+
7+
# google_oracle_database_db_nodes
8+
9+
List all DbNodes of a Cloud VmCluster.
10+
11+
For more information see the
12+
[API](https://cloud.google.com/oracle/database/docs/reference/rest/v1/projects.locations.cloudVmClusters.dbNodes).
13+
14+
## Example Usage
15+
16+
```hcl
17+
data "google_oracle_database_db_nodes" "my_db_nodes"{
18+
location = "us-east4"
19+
cloud_vm_cluster = "vmcluster-id"
20+
}
21+
```
22+
23+
## Argument Reference
24+
25+
The following arguments are supported:
26+
27+
* `cloud_vm_cluster` - (Required) The ID of the VM Cluster.
28+
29+
* `location` - (Required) The location of the resource.
30+
31+
* `project` - (Optional) The project in which the resource belongs. If it
32+
is not provided, the provider project is used.
33+
34+
## Attributes reference
35+
36+
The following attributes are exported:
37+
38+
* `db_nodes` - List of dbNodes. Structure is [documented below](#nested_dbnodes).
39+
40+
<a name="nested_dbnodes"></a> The `db_nodes` block supports:
41+
42+
* `name` - The name of the database node resource in the following format: projects/{project}/locations/{location}/cloudVmClusters/{cloudVmCluster}/dbNodes/{db_node}
43+
44+
* `properties` - Various properties of the database node. Structure is [documented below](#nested_properties).
45+
46+
<a name="nested_properties"></a> The `properties` block supports:
47+
48+
* `ocid`- OCID of database node.
49+
50+
* `ocpu_count` - OCPU count per database node.
51+
52+
* `memory_size_gb` - The allocated memory in GBs on the database node.
53+
54+
* `db_node_storage_size_gb` - The allocated local node storage in GBs on the database node.
55+
56+
* `db_server_ocid` - The OCID of the Database server associated with the database node.
57+
58+
* `hostname` - The host name for the database node.
59+
60+
* `state` - State of the database node.
61+
<a name="nested_states"></a>Possible values for `state` are:<br>
62+
`PROVISIONING` - Indicates that the resource is being provisioned.<br>
63+
`AVAILABLE` - Indicates that the resource is available.<br>
64+
`UPDATING` - Indicates that the resource is being updated.<br>
65+
`STOPPING` - Indicates that the resource is being stopped.<br>
66+
`STOPPED` - Indicates that the resource is stopped.<br>
67+
`STARTING` - Indicates that the resource is being started.<br>
68+
`TERMINATING` - Indicates that the resource is being terminated.<br>
69+
`TERMINATED` - Indicates that the resource is terminated.<br>
70+
`FAILED` - Indicates that the resource has failed.<br>
71+
72+
* `total_cpu_core_count` - The total number of CPU cores reserved on the database node.

0 commit comments

Comments
 (0)