Skip to content

Commit 3a27b3c

Browse files
committed
odb peering list added
1 parent 424e7e1 commit 3a27b3c

File tree

3 files changed

+253
-0
lines changed

3 files changed

+253
-0
lines changed
Lines changed: 145 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,145 @@
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+
odbtypes "github.com/aws/aws-sdk-go-v2/service/odb/types"
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/framework"
14+
"github.com/hashicorp/terraform-provider-aws/internal/framework/flex"
15+
fwtypes "github.com/hashicorp/terraform-provider-aws/internal/framework/types"
16+
"github.com/hashicorp/terraform-provider-aws/names"
17+
)
18+
19+
// Function annotations are used for datasource registration to the Provider. DO NOT EDIT.
20+
// @FrameworkDataSource("aws_odb_network_peering_connections_list", name="Network Peering Connections List")
21+
func newDataSourceNetworkPeeringConnectionsList(context.Context) (datasource.DataSourceWithConfigure, error) {
22+
return &dataSourceNetworkPeeringConnectionsList{}, nil
23+
}
24+
25+
const (
26+
DSNameNetworkPeeringConnectionsList = "Network Peering Connections List Data Source"
27+
)
28+
29+
type dataSourceNetworkPeeringConnectionsList struct {
30+
framework.DataSourceWithModel[odbNetworkPeeringConnectionsListDataSourceModel]
31+
}
32+
33+
func (d *dataSourceNetworkPeeringConnectionsList) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
34+
resp.Schema = schema.Schema{
35+
Attributes: map[string]schema.Attribute{},
36+
Blocks: map[string]schema.Block{
37+
"odb_peering_connections": schema.ListNestedBlock{
38+
Description: " The list of ODB peering connections. A summary of an ODB peering connection.",
39+
CustomType: fwtypes.NewListNestedObjectTypeOf[odbNetworkPeeringConnectionSummaryDataSourceModel](ctx),
40+
NestedObject: schema.NestedBlockObject{
41+
Attributes: map[string]schema.Attribute{
42+
names.AttrID: schema.StringAttribute{
43+
Computed: true,
44+
Description: "ID of the network peering connection.",
45+
},
46+
47+
"display_name": schema.StringAttribute{
48+
Computed: true,
49+
Description: "Display name for the network peering connection.",
50+
},
51+
"status": schema.StringAttribute{
52+
Computed: true,
53+
CustomType: fwtypes.StringEnumType[odbtypes.ResourceStatus](),
54+
Description: "Status of this network peering connection.",
55+
},
56+
"status_reason": schema.StringAttribute{
57+
Computed: true,
58+
Description: "Status reason of this network peering connection.",
59+
},
60+
names.AttrARN: framework.ARNAttributeComputedOnly(),
61+
"odb_network_arn": schema.StringAttribute{
62+
Computed: true,
63+
Description: "The ARN of the ODB network peering connection.",
64+
},
65+
"odb_peering_connection_type": schema.StringAttribute{
66+
Computed: true,
67+
Description: "The type of the ODB peering connection.",
68+
},
69+
"percent_progress": schema.Float32Attribute{
70+
Computed: true,
71+
Description: "The percentage of progress made in network peering .",
72+
},
73+
},
74+
},
75+
},
76+
},
77+
}
78+
}
79+
80+
func (d *dataSourceNetworkPeeringConnectionsList) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
81+
82+
conn := d.Meta().ODBClient(ctx)
83+
84+
var data odbNetworkPeeringConnectionsListDataSourceModel
85+
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
86+
if resp.Diagnostics.HasError() {
87+
return
88+
}
89+
90+
out, err := conn.ListOdbPeeringConnections(ctx, &odb.ListOdbPeeringConnectionsInput{})
91+
listOfPeerConnections := make([]peeringConnectionSummaryRead, 0)
92+
if err == nil && out.OdbPeeringConnections != nil {
93+
for _, peerConn := range out.OdbPeeringConnections {
94+
peerConnSummary := peeringConnectionSummaryRead{
95+
OdbPeeringConnectionId: peerConn.OdbPeeringConnectionId,
96+
DisplayName: peerConn.DisplayName,
97+
OdbNetworkArn: peerConn.OdbNetworkArn,
98+
OdbPeeringConnectionArn: peerConn.OdbPeeringConnectionArn,
99+
OdbPeeringConnectionType: peerConn.OdbPeeringConnectionType,
100+
PeerNetworkArn: peerConn.PeerNetworkArn,
101+
PercentProgress: peerConn.PercentProgress,
102+
Status: peerConn.Status,
103+
StatusReason: peerConn.StatusReason,
104+
}
105+
listOfPeerConnections = append(listOfPeerConnections, peerConnSummary)
106+
}
107+
resp.Diagnostics.Append(flex.Flatten(ctx, listOdbPeeringConnectionsOutputRead{
108+
OdbPeeringConnections: listOfPeerConnections,
109+
}, &data)...)
110+
if resp.Diagnostics.HasError() {
111+
return
112+
113+
}
114+
}
115+
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
116+
}
117+
118+
type odbNetworkPeeringConnectionsListDataSourceModel struct {
119+
framework.WithRegionModel
120+
OdbPeeringConnections fwtypes.ListNestedObjectValueOf[odbNetworkPeeringConnectionSummaryDataSourceModel] `tfsdk:"odb_peering_connections"`
121+
}
122+
type odbNetworkPeeringConnectionSummaryDataSourceModel struct {
123+
OdbPeeringConnectionId types.String `tfsdk:"id"`
124+
DisplayName types.String `tfsdk:"display_name"`
125+
Status fwtypes.StringEnum[odbtypes.ResourceStatus] `tfsdk:"status"`
126+
StatusReason types.String `tfsdk:"status_reason"`
127+
OdbPeeringConnectionArn types.String `tfsdk:"arn"`
128+
OdbNetworkArn types.String `tfsdk:"odb_network_arn"`
129+
OdbPeeringConnectionType types.String `tfsdk:"odb_peering_connection_type"`
130+
PercentProgress types.Float32 `tfsdk:"percent_progress"`
131+
}
132+
type peeringConnectionSummaryRead struct {
133+
OdbPeeringConnectionId *string
134+
DisplayName *string
135+
OdbNetworkArn *string
136+
OdbPeeringConnectionArn *string
137+
OdbPeeringConnectionType *string
138+
PeerNetworkArn *string
139+
PercentProgress *float32
140+
Status odbtypes.ResourceStatus
141+
StatusReason *string
142+
}
143+
type listOdbPeeringConnectionsOutputRead struct {
144+
OdbPeeringConnections []peeringConnectionSummaryRead
145+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
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 listOdbNetworkPeering struct {
27+
}
28+
29+
func TestAccODBNetworkPeeringBasic(t *testing.T) {
30+
ctx := acctest.Context(t)
31+
var listOfPeeredNwks = listOdbNetworkPeering{}
32+
var output odb.ListOdbPeeringConnectionsOutput
33+
34+
dataSourceName := "data.aws_odb_network_peering_connections_list.test"
35+
resource.Test(t, resource.TestCase{
36+
PreCheck: func() {
37+
acctest.PreCheck(ctx, t)
38+
listOfPeeredNwks.testAccPreCheck(ctx, t)
39+
},
40+
ErrorCheck: acctest.ErrorCheck(t, names.ODBServiceID),
41+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
42+
Steps: []resource.TestStep{
43+
{
44+
Config: listOfPeeredNwks.basic(),
45+
Check: resource.ComposeAggregateTestCheckFunc(
46+
47+
resource.ComposeTestCheckFunc(func(s *terraform.State) error {
48+
listOfPeeredNwks.count(ctx, dataSourceName, &output)
49+
resource.TestCheckResourceAttr(dataSourceName, "odb_peering_connections.#", strconv.Itoa(len(output.OdbPeeringConnections)))
50+
return nil
51+
},
52+
),
53+
),
54+
},
55+
},
56+
})
57+
}
58+
59+
func (listOdbNetworkPeering) basic() string {
60+
config := fmt.Sprintf(`
61+
62+
63+
data "aws_odb_network_peering_connections_list" "test" {
64+
65+
}
66+
`)
67+
return config
68+
}
69+
70+
func (listOdbNetworkPeering) count(ctx context.Context, name string, list *odb.ListOdbPeeringConnectionsOutput) resource.TestCheckFunc {
71+
return func(s *terraform.State) error {
72+
rs, ok := s.RootModule().Resources[name]
73+
if !ok {
74+
return create.Error(names.ODB, create.ErrActionCheckingExistence, tfodb.ResNameCloudVmCluster, name, errors.New("not found"))
75+
}
76+
77+
conn := acctest.Provider.Meta().(*conns.AWSClient).ODBClient(ctx)
78+
79+
resp, err := conn.ListOdbPeeringConnections(ctx, &odb.ListOdbPeeringConnectionsInput{})
80+
if err != nil {
81+
return create.Error(names.ODB, create.ErrActionCheckingExistence, tfodb.ResNameCloudVmCluster, rs.Primary.ID, err)
82+
}
83+
84+
list.OdbPeeringConnections = resp.OdbPeeringConnections
85+
86+
return nil
87+
}
88+
}
89+
func (listOdbNetworkPeering) testAccPreCheck(ctx context.Context, t *testing.T) {
90+
conn := acctest.Provider.Meta().(*conns.AWSClient).ODBClient(ctx)
91+
92+
input := &odb.ListOdbPeeringConnectionsInput{}
93+
94+
_, err := conn.ListOdbPeeringConnections(ctx, input)
95+
96+
if acctest.PreCheckSkipError(err) {
97+
t.Skipf("skipping acceptance testing: %s", err)
98+
}
99+
if err != nil {
100+
t.Fatalf("unexpected PreCheck error: %s", err)
101+
}
102+
}

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)