Skip to content

Commit 6dfb8f1

Browse files
authored
Merge pull request #43792 from oracle-community/db-server-data-source
Db server data source and db servers list data source
2 parents 0f6bd80 + 62a584a commit 6dfb8f1

18 files changed

+1707
-18
lines changed

.changelog/43792.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
```release-note:new-data-source
2+
aws_odb_db_server
3+
```
4+
5+
```release-note:new-data-source
6+
aws_odb_db_servers_list
7+
```
8+
9+
```release-note:new-data-source
10+
aws_odb_db_node
11+
```
12+
13+
```release-note:new-data-source
14+
aws_odb_db_nodes_list
15+
```

internal/service/odb/cloud_autonomous_vm_cluster_data_source_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func (autonomousVMClusterDSTest) avmcBasic() string {
109109
110110
%s
111111
112-
data "aws_odb_db_servers_list" "test" {
112+
data "aws_odb_db_servers" "test" {
113113
cloud_exadata_infrastructure_id = aws_odb_cloud_exadata_infrastructure.test.id
114114
}
115115
@@ -122,7 +122,7 @@ resource "aws_odb_cloud_autonomous_vm_cluster" "test" {
122122
total_container_databases = 1
123123
cpu_core_count_per_node = 40
124124
license_model = "LICENSE_INCLUDED"
125-
db_servers = [for db_server in data.aws_odb_db_servers_list.test.db_servers : db_server.id]
125+
db_servers = [for db_server in data.aws_odb_db_servers.test.db_servers : db_server.id]
126126
scan_listener_port_tls = 8561
127127
scan_listener_port_non_tls = 1024
128128
maintenance_window {

internal/service/odb/cloud_autonomous_vm_cluster_test.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ func (autonomousVMClusterResourceTest) avmcBasic() string {
279279
280280
%s
281281
282-
data "aws_odb_db_servers_list" "test" {
282+
data "aws_odb_db_servers" "test" {
283283
cloud_exadata_infrastructure_id = aws_odb_cloud_exadata_infrastructure.test.id
284284
}
285285
@@ -292,7 +292,7 @@ resource "aws_odb_cloud_autonomous_vm_cluster" "test" {
292292
total_container_databases = 1
293293
cpu_core_count_per_node = 40
294294
license_model = "LICENSE_INCLUDED"
295-
db_servers = [for db_server in data.aws_odb_db_servers_list.test.db_servers : db_server.id]
295+
db_servers = [for db_server in data.aws_odb_db_servers.test.db_servers : db_server.id]
296296
scan_listener_port_tls = 8561
297297
scan_listener_port_non_tls = 1024
298298
maintenance_window {
@@ -322,7 +322,7 @@ func (autonomousVMClusterResourceTest) avmcNoTagWithTag() (string, string) {
322322
323323
%s
324324
325-
data "aws_odb_db_servers_list" "test" {
325+
data "aws_odb_db_servers" "test" {
326326
cloud_exadata_infrastructure_id = aws_odb_cloud_exadata_infrastructure.test.id
327327
}
328328
@@ -335,7 +335,7 @@ resource "aws_odb_cloud_autonomous_vm_cluster" "test" {
335335
total_container_databases = 1
336336
cpu_core_count_per_node = 40
337337
license_model = "LICENSE_INCLUDED"
338-
db_servers = [for db_server in data.aws_odb_db_servers_list.test.db_servers : db_server.id]
338+
db_servers = [for db_server in data.aws_odb_db_servers.test.db_servers : db_server.id]
339339
scan_listener_port_tls = 8561
340340
scan_listener_port_non_tls = 1024
341341
maintenance_window {
@@ -353,7 +353,7 @@ resource "aws_odb_cloud_autonomous_vm_cluster" "test" {
353353
354354
%s
355355
356-
data "aws_odb_db_servers_list" "test" {
356+
data "aws_odb_db_servers" "test" {
357357
cloud_exadata_infrastructure_id = aws_odb_cloud_exadata_infrastructure.test.id
358358
}
359359
@@ -366,7 +366,7 @@ resource "aws_odb_cloud_autonomous_vm_cluster" "test" {
366366
total_container_databases = 1
367367
cpu_core_count_per_node = 40
368368
license_model = "LICENSE_INCLUDED"
369-
db_servers = [for db_server in data.aws_odb_db_servers_list.test.db_servers : db_server.id]
369+
db_servers = [for db_server in data.aws_odb_db_servers.test.db_servers : db_server.id]
370370
scan_listener_port_tls = 8561
371371
scan_listener_port_non_tls = 1024
372372
maintenance_window {
@@ -399,7 +399,7 @@ func (autonomousVMClusterResourceTest) avmcAllParamsConfig() string {
399399
400400
%s
401401
402-
data "aws_odb_db_servers_list" "test" {
402+
data "aws_odb_db_servers" "test" {
403403
cloud_exadata_infrastructure_id = aws_odb_cloud_exadata_infrastructure.test.id
404404
}
405405
@@ -414,7 +414,7 @@ resource "aws_odb_cloud_autonomous_vm_cluster" "test" {
414414
total_container_databases = 1
415415
cpu_core_count_per_node = 40
416416
license_model = "LICENSE_INCLUDED"
417-
db_servers = [for db_server in data.aws_odb_db_servers_list.test.db_servers : db_server.id]
417+
db_servers = [for db_server in data.aws_odb_db_servers.test.db_servers : db_server.id]
418418
scan_listener_port_tls = 8561
419419
scan_listener_port_non_tls = 1024
420420
maintenance_window {

internal/service/odb/cloud_vm_cluster_data_source_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ resource "aws_odb_cloud_exadata_infrastructure" "test" {
150150
}
151151
}
152152
153-
data "aws_odb_db_servers_list" "test" {
153+
data "aws_odb_db_servers" "test" {
154154
cloud_exadata_infrastructure_id = aws_odb_cloud_exadata_infrastructure.test.id
155155
}
156156
@@ -166,7 +166,7 @@ resource "aws_odb_cloud_vm_cluster" "test" {
166166
is_sparse_diskgroup_enabled = true
167167
license_model = "LICENSE_INCLUDED"
168168
data_storage_size_in_tbs = 20.0
169-
db_servers = [for db_server in data.aws_odb_db_servers_list.test.db_servers : db_server.id]
169+
db_servers = [for db_server in data.aws_odb_db_servers.test.db_servers : db_server.id]
170170
db_node_storage_size_in_gbs = 120.0
171171
memory_size_in_gbs = 60
172172
data_collection_options {

internal/service/odb/cloud_vm_cluster_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ func (cloudVmClusterResourceTest) testAccCloudVmClusterConfigBasic(vmClusterDisp
267267
268268
%s
269269
270-
data "aws_odb_db_servers_list" "test" {
270+
data "aws_odb_db_servers" "test" {
271271
cloud_exadata_infrastructure_id = aws_odb_cloud_exadata_infrastructure.test.id
272272
}
273273
@@ -283,7 +283,7 @@ resource "aws_odb_cloud_vm_cluster" "test" {
283283
is_sparse_diskgroup_enabled = true
284284
license_model = "LICENSE_INCLUDED"
285285
data_storage_size_in_tbs = 20.0
286-
db_servers = [for db_server in data.aws_odb_db_servers_list.test.db_servers : db_server.id]
286+
db_servers = [for db_server in data.aws_odb_db_servers.test.db_servers : db_server.id]
287287
db_node_storage_size_in_gbs = 120.0
288288
memory_size_in_gbs = 60
289289
data_collection_options {
@@ -309,7 +309,7 @@ func (cloudVmClusterResourceTest) cloudVmClusterWithAllParameters(vmClusterDispl
309309
%s
310310
311311
312-
data "aws_odb_db_servers_list" "test" {
312+
data "aws_odb_db_servers" "test" {
313313
cloud_exadata_infrastructure_id = aws_odb_cloud_exadata_infrastructure.test.id
314314
}
315315
@@ -325,7 +325,7 @@ resource "aws_odb_cloud_vm_cluster" "test" {
325325
is_sparse_diskgroup_enabled = true
326326
license_model = "LICENSE_INCLUDED"
327327
data_storage_size_in_tbs = 20.0
328-
db_servers = [for db_server in data.aws_odb_db_servers_list.test.db_servers : db_server.id]
328+
db_servers = [for db_server in data.aws_odb_db_servers.test.db_servers : db_server.id]
329329
db_node_storage_size_in_gbs = 120.0
330330
memory_size_in_gbs = 60
331331
cluster_name = "julia-13"
@@ -354,7 +354,7 @@ func (cloudVmClusterResourceTest) testAccCloudVmClusterConfigUpdatedTags(vmClust
354354
355355
%s
356356
357-
data "aws_odb_db_servers_list" "test" {
357+
data "aws_odb_db_servers" "test" {
358358
cloud_exadata_infrastructure_id = aws_odb_cloud_exadata_infrastructure.test.id
359359
}
360360
@@ -370,7 +370,7 @@ resource "aws_odb_cloud_vm_cluster" "test" {
370370
is_sparse_diskgroup_enabled = true
371371
license_model = "LICENSE_INCLUDED"
372372
data_storage_size_in_tbs = 20.0
373-
db_servers = [for db_server in data.aws_odb_db_servers_list.test.db_servers : db_server.id]
373+
db_servers = [for db_server in data.aws_odb_db_servers.test.db_servers : db_server.id]
374374
db_node_storage_size_in_gbs = 120.0
375375
memory_size_in_gbs = 60
376376
data_collection_options {
Lines changed: 213 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,213 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package odb
5+
6+
import (
7+
"context"
8+
9+
"github.com/aws/aws-sdk-go-v2/service/odb"
10+
odbtypes "github.com/aws/aws-sdk-go-v2/service/odb/types"
11+
"github.com/hashicorp/terraform-plugin-framework-timetypes/timetypes"
12+
"github.com/hashicorp/terraform-plugin-framework/datasource"
13+
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
14+
"github.com/hashicorp/terraform-plugin-framework/types"
15+
"github.com/hashicorp/terraform-provider-aws/internal/create"
16+
"github.com/hashicorp/terraform-provider-aws/internal/framework"
17+
"github.com/hashicorp/terraform-provider-aws/internal/framework/flex"
18+
fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types"
19+
"github.com/hashicorp/terraform-provider-aws/names"
20+
)
21+
22+
// @FrameworkDataSource("aws_odb_db_node", name="Db Node")
23+
func newDataSourceDBNode(context.Context) (datasource.DataSourceWithConfigure, error) {
24+
return &dataSourceDbNode{}, nil
25+
}
26+
27+
const (
28+
DSNameDBNode = "DB Node Data Source"
29+
)
30+
31+
type dataSourceDbNode struct {
32+
framework.DataSourceWithModel[dbNodeDataSourceModel]
33+
}
34+
35+
func (d *dataSourceDbNode) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
36+
resp.Schema = schema.Schema{
37+
Attributes: map[string]schema.Attribute{
38+
names.AttrARN: framework.ARNAttributeComputedOnly(),
39+
names.AttrID: schema.StringAttribute{
40+
Required: true,
41+
},
42+
"cloud_vm_cluster_id": schema.StringAttribute{
43+
Required: true,
44+
},
45+
names.AttrStatus: schema.StringAttribute{
46+
Computed: true,
47+
CustomType: fwtypes.StringEnumType[odbtypes.ResourceStatus](),
48+
Description: "The current status of the DB node.",
49+
},
50+
names.AttrStatusReason: schema.StringAttribute{
51+
Computed: true,
52+
Description: "Additional information about the status of the DB node.",
53+
},
54+
"additional_details": schema.StringAttribute{
55+
Computed: true,
56+
Description: "Additional information about the planned maintenance.",
57+
},
58+
"backup_ip_id": schema.StringAttribute{
59+
Computed: true,
60+
Description: "The Oracle Cloud ID (OCID) of the backup IP address that's associated with the DB node.",
61+
},
62+
"backup_vnic2_id": schema.StringAttribute{
63+
Computed: true,
64+
Description: "The OCID of the second backup VNIC.",
65+
},
66+
"backup_vnic_id": schema.StringAttribute{
67+
Computed: true,
68+
Description: "The OCID of the backup VNIC.",
69+
},
70+
"cpu_core_count": schema.Int32Attribute{
71+
Computed: true,
72+
Description: "Number of CPU cores enabled on the DB node.",
73+
},
74+
"db_storage_size_in_gbs": schema.Int32Attribute{
75+
Computed: true,
76+
Description: "The amount of local node storage, in gigabytes (GBs), allocated on the DB node.",
77+
},
78+
"db_server_id": schema.StringAttribute{
79+
Computed: true,
80+
Description: "The unique identifier of the DB server that is associated with the DB node.",
81+
},
82+
"db_system_id": schema.StringAttribute{
83+
Computed: true,
84+
Description: "The OCID of the DB system.",
85+
},
86+
"fault_domain": schema.StringAttribute{
87+
Computed: true,
88+
Description: "The name of the fault domain the instance is contained in.",
89+
},
90+
"host_ip_id": schema.StringAttribute{
91+
Computed: true,
92+
Description: "The OCID of the host IP address that's associated with the DB node.",
93+
},
94+
"hostname": schema.StringAttribute{
95+
Computed: true,
96+
Description: "The host name for the DB node.",
97+
},
98+
"ocid": schema.StringAttribute{
99+
Computed: true,
100+
Description: "The OCID of the DB node.",
101+
},
102+
"oci_resource_anchor_name": schema.StringAttribute{
103+
Computed: true,
104+
Description: "The name of the OCI resource anchor for the DB node.",
105+
},
106+
"maintenance_type": schema.StringAttribute{
107+
Computed: true,
108+
CustomType: fwtypes.StringEnumType[odbtypes.DbNodeMaintenanceType](),
109+
Description: "The type of database node maintenance. Either VMDB_REBOOT_MIGRATION or EXADBXS_REBOOT_MIGRATION.",
110+
},
111+
"memory_size_in_gbs": schema.Int32Attribute{
112+
Computed: true,
113+
Description: "The allocated memory in GBs on the DB node.",
114+
},
115+
"software_storage_size_in_gbs": schema.Int32Attribute{
116+
Computed: true,
117+
Description: "The size (in GB) of the block storage volume allocation for the DB system.",
118+
},
119+
names.AttrCreatedAt: schema.StringAttribute{
120+
CustomType: timetypes.RFC3339Type{},
121+
Computed: true,
122+
Description: "The date and time when the DB node was created.",
123+
},
124+
"time_maintenance_window_end": schema.StringAttribute{
125+
Computed: true,
126+
Description: "End date and time of maintenance window.",
127+
},
128+
"time_maintenance_window_start": schema.StringAttribute{
129+
Computed: true,
130+
Description: "Start date and time of maintenance window.",
131+
},
132+
"total_cpu_core_count": schema.Int32Attribute{
133+
Computed: true,
134+
Description: "The total number of CPU cores reserved on the DB node.",
135+
},
136+
"vnic2_id": schema.StringAttribute{
137+
Computed: true,
138+
Description: "The OCID of the second VNIC.",
139+
},
140+
"vnic_id": schema.StringAttribute{
141+
Computed: true,
142+
Description: "The OCID of the VNIC.",
143+
},
144+
"private_ip_address": schema.StringAttribute{
145+
Computed: true,
146+
Description: "The private IP address assigned to the DB node.",
147+
},
148+
"floating_ip_address": schema.StringAttribute{
149+
Computed: true,
150+
Description: "The floating IP address assigned to the DB node.",
151+
},
152+
},
153+
}
154+
}
155+
156+
func (d *dataSourceDbNode) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
157+
conn := d.Meta().ODBClient(ctx)
158+
var data dbNodeDataSourceModel
159+
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
160+
if resp.Diagnostics.HasError() {
161+
return
162+
}
163+
input := odb.GetDbNodeInput{
164+
DbNodeId: data.DbNodeId.ValueStringPointer(),
165+
CloudVmClusterId: data.CloudVmClusterId.ValueStringPointer(),
166+
}
167+
out, err := conn.GetDbNode(ctx, &input)
168+
if err != nil {
169+
resp.Diagnostics.AddError(
170+
create.ProblemStandardMessage(names.ODB, create.ErrActionReading, DSNameDBNode, data.DbNodeId.ValueString(), err),
171+
err.Error(),
172+
)
173+
return
174+
}
175+
resp.Diagnostics.Append(flex.Flatten(ctx, out.DbNode, &data)...)
176+
if resp.Diagnostics.HasError() {
177+
return
178+
}
179+
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
180+
}
181+
182+
type dbNodeDataSourceModel struct {
183+
framework.WithRegionModel
184+
CloudVmClusterId types.String `tfsdk:"cloud_vm_cluster_id"`
185+
DbNodeId types.String `tfsdk:"id"`
186+
DbNodeArn types.String `tfsdk:"arn"`
187+
Status fwtypes.StringEnum[odbtypes.ResourceStatus] `tfsdk:"status"`
188+
StatusReason types.String `tfsdk:"status_reason"`
189+
AdditionalDetails types.String `tfsdk:"additional_details"`
190+
BackupIpId types.String `tfsdk:"backup_ip_id"`
191+
BackupVnic2Id types.String `tfsdk:"backup_vnic2_id"`
192+
BackupVnicId types.String `tfsdk:"backup_vnic_id"`
193+
CpuCoreCount types.Int32 `tfsdk:"cpu_core_count"`
194+
DbNodeStorageSizeInGBs types.Int32 `tfsdk:"db_storage_size_in_gbs"`
195+
DbServerId types.String `tfsdk:"db_server_id"`
196+
DbSystemId types.String `tfsdk:"db_system_id"`
197+
FaultDomain types.String `tfsdk:"fault_domain"`
198+
HostIpId types.String `tfsdk:"host_ip_id"`
199+
Hostname types.String `tfsdk:"hostname"`
200+
Ocid types.String `tfsdk:"ocid"`
201+
OciResourceAnchorName types.String `tfsdk:"oci_resource_anchor_name"`
202+
MaintenanceType fwtypes.StringEnum[odbtypes.DbNodeMaintenanceType] `tfsdk:"maintenance_type"`
203+
MemorySizeInGBs types.Int32 `tfsdk:"memory_size_in_gbs"`
204+
SoftwareStorageSizeInGB types.Int32 `tfsdk:"software_storage_size_in_gbs"`
205+
CreatedAt timetypes.RFC3339 `tfsdk:"created_at"`
206+
TimeMaintenanceWindowEnd types.String `tfsdk:"time_maintenance_window_end"`
207+
TimeMaintenanceWindowStart types.String `tfsdk:"time_maintenance_window_start"`
208+
TotalCpuCoreCount types.Int32 `tfsdk:"total_cpu_core_count"`
209+
Vnic2Id types.String `tfsdk:"vnic2_id"`
210+
VnicId types.String `tfsdk:"vnic_id"`
211+
PrivateIpAddress types.String `tfsdk:"private_ip_address"`
212+
FloatingIpAddress types.String `tfsdk:"floating_ip_address"`
213+
}

0 commit comments

Comments
 (0)