5
5
"github.com/aws/aws-sdk-go/service/directconnect"
6
6
"github.com/hashicorp/aws-sdk-go-base/tfawserr"
7
7
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
8
+ "github.com/terraform-providers/terraform-provider-aws/aws/internal/tfresource"
8
9
)
9
10
10
11
func ConnectionByID (conn * directconnect.DirectConnect , id string ) (* directconnect.Connection , error ) {
@@ -26,14 +27,12 @@ func ConnectionByID(conn *directconnect.DirectConnect, id string) (*directconnec
26
27
}
27
28
28
29
if output == nil || len (output .Connections ) == 0 || output .Connections [0 ] == nil {
29
- return nil , & resource.NotFoundError {
30
- Message : "Empty result" ,
31
- LastRequest : input ,
32
- }
30
+ return nil , tfresource .NewEmptyResultError (input )
33
31
}
34
32
35
- // TODO Check for multiple results.
36
- // TODO https://github.com/hashicorp/terraform-provider-aws/pull/17613.
33
+ if count := len (output .Connections ); count > 1 {
34
+ return nil , tfresource .NewTooManyResultsError (count , input )
35
+ }
37
36
38
37
connection := output .Connections [0 ]
39
38
@@ -59,14 +58,12 @@ func GatewayByID(conn *directconnect.DirectConnect, id string) (*directconnect.G
59
58
}
60
59
61
60
if output == nil || len (output .DirectConnectGateways ) == 0 || output .DirectConnectGateways [0 ] == nil {
62
- return nil , & resource.NotFoundError {
63
- Message : "Empty result" ,
64
- LastRequest : input ,
65
- }
61
+ return nil , tfresource .NewEmptyResultError (input )
66
62
}
67
63
68
- // TODO Check for multiple results.
69
- // TODO https://github.com/hashicorp/terraform-provider-aws/pull/17613.
64
+ if count := len (output .DirectConnectGateways ); count > 1 {
65
+ return nil , tfresource .NewTooManyResultsError (count , input )
66
+ }
70
67
71
68
gateway := output .DirectConnectGateways [0 ]
72
69
@@ -114,14 +111,12 @@ func GatewayAssociation(conn *directconnect.DirectConnect, input *directconnect.
114
111
}
115
112
116
113
if output == nil || len (output .DirectConnectGatewayAssociations ) == 0 || output .DirectConnectGatewayAssociations [0 ] == nil {
117
- return nil , & resource.NotFoundError {
118
- Message : "Empty result" ,
119
- LastRequest : input ,
120
- }
114
+ return nil , tfresource .NewEmptyResultError (input )
121
115
}
122
116
123
- // TODO Check for multiple results.
124
- // TODO https://github.com/hashicorp/terraform-provider-aws/pull/17613.
117
+ if count := len (output .DirectConnectGatewayAssociations ); count > 1 {
118
+ return nil , tfresource .NewTooManyResultsError (count , input )
119
+ }
125
120
126
121
association := output .DirectConnectGatewayAssociations [0 ]
127
122
@@ -154,14 +149,12 @@ func GatewayAssociationProposalByID(conn *directconnect.DirectConnect, id string
154
149
}
155
150
156
151
if output == nil || len (output .DirectConnectGatewayAssociationProposals ) == 0 || output .DirectConnectGatewayAssociationProposals [0 ] == nil {
157
- return nil , & resource.NotFoundError {
158
- Message : "Empty result" ,
159
- LastRequest : input ,
160
- }
152
+ return nil , tfresource .NewEmptyResultError (input )
161
153
}
162
154
163
- // TODO Check for multiple results.
164
- // TODO https://github.com/hashicorp/terraform-provider-aws/pull/17613.
155
+ if count := len (output .DirectConnectGatewayAssociationProposals ); count > 1 {
156
+ return nil , tfresource .NewTooManyResultsError (count , input )
157
+ }
165
158
166
159
proposal := output .DirectConnectGatewayAssociationProposals [0 ]
167
160
@@ -201,14 +194,12 @@ func LagByID(conn *directconnect.DirectConnect, id string) (*directconnect.Lag,
201
194
}
202
195
203
196
if output == nil || len (output .Lags ) == 0 || output .Lags [0 ] == nil {
204
- return nil , & resource.NotFoundError {
205
- Message : "Empty result" ,
206
- LastRequest : input ,
207
- }
197
+ return nil , tfresource .NewEmptyResultError (input )
208
198
}
209
199
210
- // TODO Check for multiple results.
211
- // TODO https://github.com/hashicorp/terraform-provider-aws/pull/17613.
200
+ if count := len (output .Lags ); count > 1 {
201
+ return nil , tfresource .NewTooManyResultsError (count , input )
202
+ }
212
203
213
204
lag := output .Lags [0 ]
214
205
@@ -237,10 +228,7 @@ func LocationByCode(conn *directconnect.DirectConnect, code string) (*directconn
237
228
}
238
229
}
239
230
240
- return nil , & resource.NotFoundError {
241
- Message : "Empty result" ,
242
- LastRequest : input ,
243
- }
231
+ return nil , tfresource .NewEmptyResultError (input )
244
232
}
245
233
246
234
func Locations (conn * directconnect.DirectConnect , input * directconnect.DescribeLocationsInput ) ([]* directconnect.Location , error ) {
@@ -251,10 +239,7 @@ func Locations(conn *directconnect.DirectConnect, input *directconnect.DescribeL
251
239
}
252
240
253
241
if output == nil || len (output .Locations ) == 0 {
254
- return nil , & resource.NotFoundError {
255
- Message : "Empty result" ,
256
- LastRequest : input ,
257
- }
242
+ return nil , tfresource .NewEmptyResultError (input )
258
243
}
259
244
260
245
return output .Locations , nil
0 commit comments