|
| 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 | +} |
0 commit comments