@@ -48,7 +48,7 @@ func (r *privateEndpointConnectionResource) Schema(
48
48
_ context.Context , _ resource.SchemaRequest , resp * resource.SchemaResponse ,
49
49
) {
50
50
resp .Schema = schema.Schema {
51
- MarkdownDescription : "AWS PrivateLink Endpoint Connection." ,
51
+ MarkdownDescription : "Private Endpoint Connection." ,
52
52
Attributes : map [string ]schema.Attribute {
53
53
"id" : schema.StringAttribute {
54
54
Computed : true ,
@@ -76,14 +76,14 @@ func (r *privateEndpointConnectionResource) Schema(
76
76
PlanModifiers : []planmodifier.String {
77
77
stringplanmodifier .RequiresReplace (),
78
78
},
79
- Description : "Client side ID of the PrivateLink connection ." ,
79
+ Description : "Client side ID of the Private Endpoint Connection ." ,
80
80
},
81
81
"service_id" : schema.StringAttribute {
82
82
Computed : true ,
83
83
PlanModifiers : []planmodifier.String {
84
84
stringplanmodifier .UseStateForUnknown (),
85
85
},
86
- Description : "Server side ID of the PrivateLink connection ." ,
86
+ Description : "Server side ID of the Private Endpoint Connection ." ,
87
87
},
88
88
"cluster_id" : schema.StringAttribute {
89
89
Required : true ,
@@ -129,7 +129,8 @@ func (r *privateEndpointConnectionResource) Create(
129
129
return
130
130
}
131
131
132
- cluster , _ , err := r .provider .service .GetCluster (ctx , plan .ClusterID .ValueString ())
132
+ svc := r .provider .service
133
+ cluster , _ , err := svc .GetCluster (ctx , plan .ClusterID .ValueString ())
133
134
if err != nil {
134
135
resp .Diagnostics .AddError (
135
136
"Error getting cluster" ,
@@ -138,30 +139,22 @@ func (r *privateEndpointConnectionResource) Create(
138
139
return
139
140
}
140
141
141
- if cluster .CloudProvider != client .CLOUDPROVIDERTYPE_AWS {
142
- resp .Diagnostics .AddError (
143
- "Incompatible cluster cloud provider" ,
144
- "Private endpoint services are only available for AWS clusters" ,
145
- )
146
- return
147
- }
148
-
149
- connectionStateRequest := client.SetAwsEndpointConnectionStateRequest {
150
- Status : client .SETAWSENDPOINTCONNECTIONSTATUSTYPE_AVAILABLE ,
142
+ addRequest := client.AddPrivateEndpointConnectionRequest {
143
+ EndpointId : plan .EndpointID .ValueString (),
151
144
}
152
145
153
- _ , _ , err = r . provider . service . SetAwsEndpointConnectionState (ctx , plan . ClusterID . ValueString (), plan . EndpointID . ValueString (), & connectionStateRequest )
146
+ _ , _ , err = svc . AddPrivateEndpointConnection (ctx , cluster . Id , & addRequest )
154
147
if err != nil {
155
148
resp .Diagnostics .AddError (
156
- "Error establishing AWS Endpoint Connection" ,
157
- fmt .Sprintf ("Could not establish AWS Endpoint Connection: %s" , formatAPIErrorMessage (err )),
149
+ "Error establishing Private Endpoint Connection" ,
150
+ fmt .Sprintf ("Could not establish Private Endpoint Connection: %s" , formatAPIErrorMessage (err )),
158
151
)
159
152
return
160
153
}
161
154
162
- var connection client.AwsEndpointConnection
155
+ var connection client.PrivateEndpointConnection
163
156
err = sdk_resource .RetryContext (ctx , endpointConnectionCreateTimeout ,
164
- waitForEndpointConnectionCreatedFunc (ctx , cluster .Id , plan .EndpointID .ValueString (), r . provider . service , & connection ))
157
+ waitForEndpointConnectionCreatedFunc (ctx , cluster .Id , plan .EndpointID .ValueString (), svc , & connection ))
165
158
if err != nil {
166
159
resp .Diagnostics .AddError (
167
160
"Error accepting private endpoint connection" ,
@@ -192,7 +185,7 @@ func (r *privateEndpointConnectionResource) Read(
192
185
return
193
186
}
194
187
195
- connections , _ , err := r .provider .service .ListAwsEndpointConnections (ctx , state .ClusterID .ValueString ())
188
+ connections , _ , err := r .provider .service .ListPrivateEndpointConnections (ctx , state .ClusterID .ValueString ())
196
189
if err != nil {
197
190
diags .AddError ("Unable to get endpoint connection status" ,
198
191
fmt .Sprintf ("Unexpected error retrieving endpoint status: %s" , formatAPIErrorMessage (err )))
@@ -212,14 +205,14 @@ func (r *privateEndpointConnectionResource) Read(
212
205
}
213
206
214
207
func loadEndpointConnectionIntoTerraformState (
215
- apiConnection * client.AwsEndpointConnection , state * PrivateEndpointConnection ,
208
+ apiConnection * client.PrivateEndpointConnection , state * PrivateEndpointConnection ,
216
209
) {
217
210
state .EndpointID = types .StringValue (apiConnection .GetEndpointId ())
218
211
state .ID = types .StringValue (fmt .Sprintf (
219
212
privateEndpointConnectionIDFmt ,
220
213
state .ClusterID .ValueString (),
221
214
apiConnection .GetEndpointId ()))
222
- state .ServiceID = types .StringValue (apiConnection .GetServiceId ())
215
+ state .ServiceID = types .StringValue (apiConnection .GetEndpointServiceId ())
223
216
state .CloudProvider = types .StringValue (string (apiConnection .GetCloudProvider ()))
224
217
state .RegionName = types .StringValue (apiConnection .GetRegionName ())
225
218
}
@@ -240,13 +233,11 @@ func (r *privateEndpointConnectionResource) Delete(
240
233
return
241
234
}
242
235
243
- _ , httpResp , err := r .provider .service .SetAwsEndpointConnectionState (
236
+ httpResp , err := r .provider .service .DeletePrivateEndpointConnection (
244
237
ctx ,
245
238
state .ClusterID .ValueString (),
246
239
state .EndpointID .ValueString (),
247
- & client.SetAwsEndpointConnectionStateRequest {
248
- Status : client .SETAWSENDPOINTCONNECTIONSTATUSTYPE_REJECTED ,
249
- })
240
+ )
250
241
if err != nil && httpResp != nil && httpResp .StatusCode != http .StatusNotFound {
251
242
diags .AddError ("Couldn't delete connection" ,
252
243
fmt .Sprintf ("Unexpected error occurred while setting connection status: %s" , formatAPIErrorMessage (err )))
@@ -284,10 +275,10 @@ func waitForEndpointConnectionCreatedFunc(
284
275
ctx context.Context ,
285
276
clusterID , endpointID string ,
286
277
cl client.Service ,
287
- connection * client.AwsEndpointConnection ,
278
+ connection * client.PrivateEndpointConnection ,
288
279
) sdk_resource.RetryFunc {
289
280
return func () * sdk_resource.RetryError {
290
- connections , httpResp , err := cl .ListAwsEndpointConnections (ctx , clusterID )
281
+ connections , httpResp , err := cl .ListPrivateEndpointConnections (ctx , clusterID )
291
282
if err != nil {
292
283
if httpResp != nil && httpResp .StatusCode < http .StatusInternalServerError {
293
284
return sdk_resource .NonRetryableError (fmt .Errorf ("error getting endpoint connections: %s" , formatAPIErrorMessage (err )))
@@ -299,10 +290,10 @@ func waitForEndpointConnectionCreatedFunc(
299
290
for _ , * connection = range connections .GetConnections () {
300
291
if connection .GetEndpointId () == endpointID {
301
292
switch status := connection .GetStatus (); status {
302
- case client .AWSENDPOINTCONNECTIONSTATUSTYPE_AVAILABLE :
293
+ case client .PRIVATEENDPOINTCONNECTIONSTATUS_AVAILABLE :
303
294
return nil
304
- case client .AWSENDPOINTCONNECTIONSTATUSTYPE_PENDING ,
305
- client .AWSENDPOINTCONNECTIONSTATUSTYPE_PENDING_ACCEPTANCE :
295
+ case client .PRIVATEENDPOINTCONNECTIONSTATUS_PENDING ,
296
+ client .PRIVATEENDPOINTCONNECTIONSTATUS_PENDING_ACCEPTANCE :
306
297
return sdk_resource .RetryableError (fmt .Errorf ("endpoint connection is not ready yet" ))
307
298
default :
308
299
return sdk_resource .NonRetryableError (fmt .Errorf ("endpoint connection failed with state: %s" , status ))
0 commit comments