Skip to content

Commit bc32e54

Browse files
authored
Merge pull request #44336 from oracle-community/odb-aws-lists
list data source
2 parents 20eda8a + e2945b8 commit bc32e54

22 files changed

+1196
-15
lines changed

.changelog/44336.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
```release-note:new-data-source
2+
aws_odb_cloud_autonomous_vm_clusters
3+
```
4+
5+
```release-note:new-data-source
6+
aws_odb_cloud_exadata_infrastructures
7+
```
8+
9+
```release-note:new-data-source
10+
aws_odb_cloud_vm_clusters
11+
```
12+
13+
```release-note:new-data-source
14+
aws_odb_networks
15+
```
16+
17+
```release-note:new-data-source
18+
aws_odb_network_peering_connections
19+
```
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
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+
"github.com/hashicorp/terraform-plugin-framework/datasource"
11+
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
12+
"github.com/hashicorp/terraform-plugin-framework/types"
13+
"github.com/hashicorp/terraform-provider-aws/internal/create"
14+
"github.com/hashicorp/terraform-provider-aws/internal/framework"
15+
"github.com/hashicorp/terraform-provider-aws/internal/framework/flex"
16+
fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types"
17+
"github.com/hashicorp/terraform-provider-aws/names"
18+
)
19+
20+
// Function annotations are used for datasource registration to the Provider. DO NOT EDIT.
21+
// @FrameworkDataSource("aws_odb_cloud_autonomous_vm_clusters", name="Cloud Autonomous Vm Clusters")
22+
func newDataSourceCloudAutonomousVmClustersList(context.Context) (datasource.DataSourceWithConfigure, error) {
23+
return &dataSourceCloudAutonomousVmClustersList{}, nil
24+
}
25+
26+
const (
27+
DSNameCloudAutonomousVmClustersList = "Cloud Autonomous Vm Clusters List Data Source"
28+
)
29+
30+
type dataSourceCloudAutonomousVmClustersList struct {
31+
framework.DataSourceWithModel[cloudAutonomousVmClusterListModel]
32+
}
33+
34+
func (d *dataSourceCloudAutonomousVmClustersList) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
35+
resp.Schema = schema.Schema{
36+
Attributes: map[string]schema.Attribute{
37+
"cloud_autonomous_vm_clusters": schema.ListAttribute{
38+
Computed: true,
39+
Description: "List of Cloud Autonomous VM Clusters. The list going to contain basic information about the cloud autonomous VM clusters.",
40+
CustomType: fwtypes.NewListNestedObjectTypeOf[cloudAutonomousVmClusterSummary](ctx),
41+
},
42+
},
43+
}
44+
}
45+
46+
// Data sources only have a read method.
47+
func (d *dataSourceCloudAutonomousVmClustersList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
48+
conn := d.Meta().ODBClient(ctx)
49+
var data cloudAutonomousVmClusterListModel
50+
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
51+
if resp.Diagnostics.HasError() {
52+
return
53+
}
54+
out, err := ListCloudAutonomousVmClusters(ctx, conn)
55+
if err != nil {
56+
resp.Diagnostics.AddError(
57+
create.ProblemStandardMessage(names.ODB, create.ErrActionReading, DSNameCloudAutonomousVmClustersList, "", err),
58+
err.Error(),
59+
)
60+
return
61+
}
62+
resp.Diagnostics.Append(flex.Flatten(ctx, out, &data)...)
63+
if resp.Diagnostics.HasError() {
64+
return
65+
}
66+
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
67+
}
68+
69+
func ListCloudAutonomousVmClusters(ctx context.Context, conn *odb.Client) (*odb.ListCloudAutonomousVmClustersOutput, error) {
70+
out := odb.ListCloudAutonomousVmClustersOutput{}
71+
paginator := odb.NewListCloudAutonomousVmClustersPaginator(conn, &odb.ListCloudAutonomousVmClustersInput{})
72+
for paginator.HasMorePages() {
73+
page, err := paginator.NextPage(ctx)
74+
if err != nil {
75+
return nil, err
76+
}
77+
out.CloudAutonomousVmClusters = append(out.CloudAutonomousVmClusters, page.CloudAutonomousVmClusters...)
78+
}
79+
return &out, nil
80+
}
81+
82+
type cloudAutonomousVmClusterListModel struct {
83+
framework.WithRegionModel
84+
CloudAutonomousVmClusters fwtypes.ListNestedObjectValueOf[cloudAutonomousVmClusterSummary] `tfsdk:"cloud_autonomous_vm_clusters"`
85+
}
86+
87+
type cloudAutonomousVmClusterSummary struct {
88+
CloudAutonomousVmClusterArn types.String `tfsdk:"arn"`
89+
CloudAutonomousVmClusterId types.String `tfsdk:"id"`
90+
CloudExadataInfrastructureId types.String `tfsdk:"cloud_exadata_infrastructure_id"`
91+
OdbNetworkId types.String `tfsdk:"odb_network_id"`
92+
OciResourceAnchorName types.String `tfsdk:"oci_resource_anchor_name"`
93+
OciUrl types.String `tfsdk:"oci_url"`
94+
Ocid types.String `tfsdk:"ocid"`
95+
DisplayName types.String `tfsdk:"display_name"`
96+
}
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package odb_test
5+
6+
import (
7+
"context"
8+
"errors"
9+
"strconv"
10+
"testing"
11+
12+
"github.com/aws/aws-sdk-go-v2/service/odb"
13+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
14+
"github.com/hashicorp/terraform-plugin-testing/terraform"
15+
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
16+
"github.com/hashicorp/terraform-provider-aws/internal/conns"
17+
"github.com/hashicorp/terraform-provider-aws/internal/create"
18+
tfodb "github.com/hashicorp/terraform-provider-aws/internal/service/odb"
19+
"github.com/hashicorp/terraform-provider-aws/names"
20+
)
21+
22+
type listAVMCListDSTest struct {
23+
}
24+
25+
func TestAccODBListAutonomousVmClustersDataSource_basic(t *testing.T) {
26+
ctx := acctest.Context(t)
27+
var avmcListTest = listAVMCListDSTest{}
28+
var output odb.ListCloudAutonomousVmClustersOutput
29+
30+
dataSourceName := "data.aws_odb_cloud_autonomous_vm_clusters.test"
31+
resource.Test(t, resource.TestCase{
32+
PreCheck: func() {
33+
acctest.PreCheck(ctx, t)
34+
avmcListTest.testAccPreCheck(ctx, t)
35+
},
36+
ErrorCheck: acctest.ErrorCheck(t, names.ODBServiceID),
37+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
38+
Steps: []resource.TestStep{
39+
{
40+
Config: avmcListTest.basic(),
41+
Check: resource.ComposeAggregateTestCheckFunc(
42+
resource.ComposeTestCheckFunc(func(s *terraform.State) error {
43+
avmcListTest.count(ctx, dataSourceName, &output)
44+
resource.TestCheckResourceAttr(dataSourceName, "cloud_autonomous_vm_clusters.#", strconv.Itoa(len(output.CloudAutonomousVmClusters)))
45+
return nil
46+
},
47+
),
48+
),
49+
},
50+
},
51+
})
52+
}
53+
54+
func (listAVMCListDSTest) basic() string {
55+
return `data "aws_odb_cloud_autonomous_vm_clusters" "test" {}`
56+
}
57+
58+
func (listAVMCListDSTest) count(ctx context.Context, name string, list *odb.ListCloudAutonomousVmClustersOutput) resource.TestCheckFunc {
59+
return func(s *terraform.State) error {
60+
rs, ok := s.RootModule().Resources[name]
61+
if !ok {
62+
return create.Error(names.ODB, create.ErrActionCheckingExistence, tfodb.DSNameCloudAutonomousVmClustersList, name, errors.New("not found"))
63+
}
64+
conn := acctest.Provider.Meta().(*conns.AWSClient).ODBClient(ctx)
65+
resp, err := tfodb.ListCloudAutonomousVmClusters(ctx, conn)
66+
if err != nil {
67+
return create.Error(names.ODB, create.ErrActionCheckingExistence, tfodb.DSNameCloudAutonomousVmClustersList, rs.Primary.ID, err)
68+
}
69+
list.CloudAutonomousVmClusters = resp.CloudAutonomousVmClusters
70+
return nil
71+
}
72+
}
73+
func (listAVMCListDSTest) testAccPreCheck(ctx context.Context, t *testing.T) {
74+
conn := acctest.Provider.Meta().(*conns.AWSClient).ODBClient(ctx)
75+
input := odb.ListCloudAutonomousVmClustersInput{}
76+
_, err := conn.ListCloudAutonomousVmClusters(ctx, &input)
77+
if acctest.PreCheckSkipError(err) {
78+
t.Skipf("skipping acceptance testing: %s", err)
79+
}
80+
if err != nil {
81+
t.Fatalf("unexpected PreCheck error: %s", err)
82+
}
83+
}
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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+
"github.com/hashicorp/terraform-plugin-framework/datasource"
11+
"github.com/hashicorp/terraform-plugin-framework/datasource/schema"
12+
"github.com/hashicorp/terraform-plugin-framework/types"
13+
"github.com/hashicorp/terraform-provider-aws/internal/create"
14+
"github.com/hashicorp/terraform-provider-aws/internal/framework"
15+
"github.com/hashicorp/terraform-provider-aws/internal/framework/flex"
16+
fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types"
17+
"github.com/hashicorp/terraform-provider-aws/names"
18+
)
19+
20+
// @FrameworkDataSource("aws_odb_cloud_exadata_infrastructures", name="Cloud Exadata Infrastructures")
21+
func newDataSourceCloudExadataInfrastructuresList(context.Context) (datasource.DataSourceWithConfigure, error) {
22+
return &dataSourceCloudExadataInfrastructuresList{}, nil
23+
}
24+
25+
const (
26+
DSNameCloudExadataInfrastructuresList = "Cloud Exadata Infrastructures List Data Source"
27+
)
28+
29+
type dataSourceCloudExadataInfrastructuresList struct {
30+
framework.DataSourceWithModel[cloudExadataInfrastructuresListDataSourceModel]
31+
}
32+
33+
func (d *dataSourceCloudExadataInfrastructuresList) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
34+
resp.Schema = schema.Schema{
35+
Attributes: map[string]schema.Attribute{
36+
"cloud_exadata_infrastructures": schema.ListAttribute{
37+
Computed: true,
38+
Description: "List of Cloud Exadata Infrastructures. Returns basic information about the Cloud Exadata Infrastructures.",
39+
CustomType: fwtypes.NewListNestedObjectTypeOf[cloudExadataInfrastructureDataSourceListSummary](ctx),
40+
},
41+
},
42+
}
43+
}
44+
45+
func (d *dataSourceCloudExadataInfrastructuresList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
46+
conn := d.Meta().ODBClient(ctx)
47+
var data cloudExadataInfrastructuresListDataSourceModel
48+
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
49+
if resp.Diagnostics.HasError() {
50+
return
51+
}
52+
out, err := ListCloudExadataInfrastructures(ctx, conn)
53+
if err != nil {
54+
resp.Diagnostics.AddError(
55+
create.ProblemStandardMessage(names.ODB, create.ErrActionReading, DSNameCloudExadataInfrastructuresList, "", err),
56+
err.Error(),
57+
)
58+
return
59+
}
60+
resp.Diagnostics.Append(flex.Flatten(ctx, out, &data)...)
61+
if resp.Diagnostics.HasError() {
62+
return
63+
}
64+
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
65+
}
66+
67+
func ListCloudExadataInfrastructures(ctx context.Context, conn *odb.Client) (*odb.ListCloudExadataInfrastructuresOutput, error) {
68+
var out odb.ListCloudExadataInfrastructuresOutput
69+
paginator := odb.NewListCloudExadataInfrastructuresPaginator(conn, &odb.ListCloudExadataInfrastructuresInput{})
70+
for paginator.HasMorePages() {
71+
page, err := paginator.NextPage(ctx)
72+
if err != nil {
73+
return nil, err
74+
}
75+
out.CloudExadataInfrastructures = append(out.CloudExadataInfrastructures, page.CloudExadataInfrastructures...)
76+
}
77+
return &out, nil
78+
}
79+
80+
type cloudExadataInfrastructuresListDataSourceModel struct {
81+
framework.WithRegionModel
82+
CloudExadataInfrastructures fwtypes.ListNestedObjectValueOf[cloudExadataInfrastructureDataSourceListSummary] `tfsdk:"cloud_exadata_infrastructures"`
83+
}
84+
85+
type cloudExadataInfrastructureDataSourceListSummary struct {
86+
CloudExadataInfrastructureArn types.String `tfsdk:"arn"`
87+
CloudExadataInfrastructureId types.String `tfsdk:"id"`
88+
OciResourceAnchorName types.String `tfsdk:"oci_resource_anchor_name"`
89+
OciUrl types.String `tfsdk:"oci_url"`
90+
Ocid types.String `tfsdk:"ocid"`
91+
DisplayName types.String `tfsdk:"display_name"`
92+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package odb_test
5+
6+
import (
7+
"context"
8+
"errors"
9+
"strconv"
10+
"testing"
11+
12+
"github.com/aws/aws-sdk-go-v2/service/odb"
13+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
14+
"github.com/hashicorp/terraform-plugin-testing/terraform"
15+
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
16+
"github.com/hashicorp/terraform-provider-aws/internal/conns"
17+
"github.com/hashicorp/terraform-provider-aws/internal/create"
18+
tfodb "github.com/hashicorp/terraform-provider-aws/internal/service/odb"
19+
"github.com/hashicorp/terraform-provider-aws/names"
20+
)
21+
22+
type listExaInfraTest struct {
23+
}
24+
25+
func TestAccODBListCloudExadataInfrastructuresDataSource_basic(t *testing.T) {
26+
ctx := acctest.Context(t)
27+
var listExaInfraDSTest = listExaInfraTest{}
28+
var infraList odb.ListCloudExadataInfrastructuresOutput
29+
dataSourceName := "data.aws_odb_cloud_exadata_infrastructures.test"
30+
resource.Test(t, resource.TestCase{
31+
PreCheck: func() {
32+
acctest.PreCheck(ctx, t)
33+
listExaInfraDSTest.testAccPreCheck(ctx, t)
34+
},
35+
ErrorCheck: acctest.ErrorCheck(t, names.ODBServiceID),
36+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
37+
Steps: []resource.TestStep{
38+
{
39+
Config: listExaInfraDSTest.basic(),
40+
Check: resource.ComposeAggregateTestCheckFunc(
41+
resource.ComposeTestCheckFunc(func(s *terraform.State) error {
42+
listExaInfraDSTest.countExaInfrastructures(ctx, dataSourceName, &infraList)
43+
resource.TestCheckResourceAttr(dataSourceName, "cloud_exadata_infrastructures.#", strconv.Itoa(len(infraList.CloudExadataInfrastructures)))
44+
return nil
45+
},
46+
),
47+
),
48+
},
49+
},
50+
})
51+
}
52+
53+
func (listExaInfraTest) basic() string {
54+
return `data "aws_odb_cloud_exadata_infrastructures" "test" {}`
55+
}
56+
57+
func (listExaInfraTest) countExaInfrastructures(ctx context.Context, name string, listOfInfra *odb.ListCloudExadataInfrastructuresOutput) resource.TestCheckFunc {
58+
return func(s *terraform.State) error {
59+
rs, ok := s.RootModule().Resources[name]
60+
if !ok {
61+
return create.Error(names.ODB, create.ErrActionCheckingExistence, tfodb.DSNameCloudExadataInfrastructuresList, name, errors.New("not found"))
62+
}
63+
conn := acctest.Provider.Meta().(*conns.AWSClient).ODBClient(ctx)
64+
resp, err := tfodb.ListCloudExadataInfrastructures(ctx, conn)
65+
if err != nil {
66+
return create.Error(names.ODB, create.ErrActionCheckingExistence, tfodb.DSNameCloudExadataInfrastructuresList, rs.Primary.ID, err)
67+
}
68+
listOfInfra.CloudExadataInfrastructures = resp.CloudExadataInfrastructures
69+
return nil
70+
}
71+
}
72+
func (listExaInfraTest) testAccPreCheck(ctx context.Context, t *testing.T) {
73+
conn := acctest.Provider.Meta().(*conns.AWSClient).ODBClient(ctx)
74+
input := odb.ListCloudExadataInfrastructuresInput{}
75+
_, err := conn.ListCloudExadataInfrastructures(ctx, &input)
76+
if acctest.PreCheckSkipError(err) {
77+
t.Skipf("skipping acceptance testing: %s", err)
78+
}
79+
if err != nil {
80+
t.Fatalf("unexpected PreCheck error: %s", err)
81+
}
82+
}

0 commit comments

Comments
 (0)