Skip to content

Commit 424e7e1

Browse files
committed
list exa added with documentation
1 parent 0d34321 commit 424e7e1

File tree

3 files changed

+217
-0
lines changed

3 files changed

+217
-0
lines changed
Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package odb
5+
6+
import (
7+
"context"
8+
"github.com/aws/aws-sdk-go-v2/service/odb"
9+
"github.com/hashicorp/terraform-plugin-framework/attr"
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_list", name="Cloud Exadata Infrastructures List")
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 (OCID, ID, ARN and OCI URL)",
39+
CustomType: fwtypes.NewListNestedObjectTypeOf[cloudExadataInfrastructureDataSourceListSummary](ctx),
40+
ElementType: types.ObjectType{
41+
AttrTypes: map[string]attr.Type{
42+
"arn": types.StringType,
43+
"id": types.StringType,
44+
"oci_url": types.StringType,
45+
"ocid": types.StringType,
46+
},
47+
},
48+
},
49+
},
50+
}
51+
52+
}
53+
54+
func (d *dataSourceCloudExadataInfrastructuresList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
55+
56+
conn := d.Meta().ODBClient(ctx)
57+
58+
var data cloudExadataInfrastructuresListDataSourceModel
59+
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
60+
if resp.Diagnostics.HasError() {
61+
return
62+
}
63+
64+
out, err := conn.ListCloudExadataInfrastructures(ctx, &odb.ListCloudExadataInfrastructuresInput{})
65+
if err != nil {
66+
resp.Diagnostics.AddError(
67+
create.ProblemStandardMessage(names.ODB, create.ErrActionReading, DSNameCloudExadataInfrastructuresList, "", err),
68+
err.Error(),
69+
)
70+
return
71+
}
72+
73+
resp.Diagnostics.Append(flex.Flatten(ctx, out, &data)...)
74+
if resp.Diagnostics.HasError() {
75+
return
76+
}
77+
78+
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
79+
}
80+
81+
type cloudExadataInfrastructuresListDataSourceModel struct {
82+
framework.WithRegionModel
83+
CloudExadataInfrastructures fwtypes.ListNestedObjectValueOf[cloudExadataInfrastructureDataSourceListSummary] `tfsdk:"cloud_exadata_infrastructures"`
84+
}
85+
86+
type cloudExadataInfrastructureDataSourceListSummary struct {
87+
CloudExadataInfrastructureArn types.String `tfsdk:"arn"`
88+
CloudExadataInfrastructureId types.String `tfsdk:"id"`
89+
OciUrl types.String `tfsdk:"oci_url"`
90+
Ocid types.String `tfsdk:"ocid"`
91+
}
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
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+
"fmt"
10+
"github.com/hashicorp/terraform-plugin-testing/terraform"
11+
"github.com/hashicorp/terraform-provider-aws/internal/create"
12+
tfodb "github.com/hashicorp/terraform-provider-aws/internal/service/odb"
13+
"strconv"
14+
"testing"
15+
16+
"github.com/aws/aws-sdk-go-v2/service/odb"
17+
18+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
19+
20+
"github.com/hashicorp/terraform-provider-aws/internal/acctest"
21+
"github.com/hashicorp/terraform-provider-aws/internal/conns"
22+
23+
"github.com/hashicorp/terraform-provider-aws/names"
24+
)
25+
26+
type listExaInfraTest struct {
27+
}
28+
29+
func TestAccODBCloudExadataInfrastructuresListDataSource_basic(t *testing.T) {
30+
ctx := acctest.Context(t)
31+
var listExaInfraDSTest = listExaInfraTest{}
32+
var infraList odb.ListCloudExadataInfrastructuresOutput
33+
34+
dataSourceName := "data.aws_odb_cloud_exadata_infrastructures_list.test"
35+
resource.Test(t, resource.TestCase{
36+
PreCheck: func() {
37+
acctest.PreCheck(ctx, t)
38+
listExaInfraDSTest.testAccPreCheck(ctx, t)
39+
},
40+
ErrorCheck: acctest.ErrorCheck(t, names.ODBServiceID),
41+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
42+
Steps: []resource.TestStep{
43+
{
44+
Config: listExaInfraDSTest.basic(),
45+
Check: resource.ComposeAggregateTestCheckFunc(
46+
47+
resource.ComposeTestCheckFunc(func(s *terraform.State) error {
48+
listExaInfraDSTest.countExaInfrastructures(ctx, dataSourceName, &infraList)
49+
resource.TestCheckResourceAttr(dataSourceName, "cloud_exadata_infrastructures.#", strconv.Itoa(len(infraList.CloudExadataInfrastructures)))
50+
return nil
51+
},
52+
),
53+
),
54+
},
55+
},
56+
})
57+
}
58+
59+
func (listExaInfraTest) basic() string {
60+
config := fmt.Sprintf(`
61+
62+
63+
data "aws_odb_cloud_exadata_infrastructures_list" "test" {
64+
65+
}
66+
`)
67+
return config
68+
}
69+
70+
/*func (listExaInfraTest) countExaInfrastructures(ctx context.Context, t *testing.T, exaInfraDatalistTest *listExaInfraTest) int {
71+
conn := acctest.Provider.Meta().(*conns.AWSClient).ODBClient(ctx)
72+
73+
input := &odb.ListCloudExadataInfrastructuresInput{}
74+
75+
out, err := conn.ListCloudExadataInfrastructures(ctx, input)
76+
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+
exaInfraDatalistTest.count = len(out.CloudExadataInfrastructures)
84+
fmt.Println("----------", exaInfraDatalistTest.count)
85+
return len(out.CloudExadataInfrastructures)
86+
}*/
87+
88+
func (listExaInfraTest) countExaInfrastructures(ctx context.Context, name string, listOfInfra *odb.ListCloudExadataInfrastructuresOutput) resource.TestCheckFunc {
89+
return func(s *terraform.State) error {
90+
rs, ok := s.RootModule().Resources[name]
91+
if !ok {
92+
return create.Error(names.ODB, create.ErrActionCheckingExistence, tfodb.ResNameCloudVmCluster, name, errors.New("not found"))
93+
}
94+
95+
conn := acctest.Provider.Meta().(*conns.AWSClient).ODBClient(ctx)
96+
97+
resp, err := conn.ListCloudExadataInfrastructures(ctx, &odb.ListCloudExadataInfrastructuresInput{})
98+
if err != nil {
99+
return create.Error(names.ODB, create.ErrActionCheckingExistence, tfodb.ResNameCloudVmCluster, rs.Primary.ID, err)
100+
}
101+
102+
listOfInfra.CloudExadataInfrastructures = resp.CloudExadataInfrastructures
103+
104+
return nil
105+
}
106+
}
107+
func (listExaInfraTest) testAccPreCheck(ctx context.Context, t *testing.T) {
108+
conn := acctest.Provider.Meta().(*conns.AWSClient).ODBClient(ctx)
109+
110+
input := &odb.ListCloudAutonomousVmClustersInput{}
111+
112+
_, err := conn.ListCloudAutonomousVmClusters(ctx, input)
113+
114+
if acctest.PreCheckSkipError(err) {
115+
t.Skipf("skipping acceptance testing: %s", err)
116+
}
117+
if err != nil {
118+
t.Fatalf("unexpected PreCheck error: %s", err)
119+
}
120+
}

internal/service/odb/service_package_gen.go

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)