Skip to content

Commit 191d3f3

Browse files
[AV-129295] Revert [AV-125341] Add private endpoint DNS (#568)
1 parent 29e58d9 commit 191d3f3

8 files changed

Lines changed: 47 additions & 107 deletions

File tree

.factory/skills/tf-examples-gen/SKILL.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,4 @@ If there is no datasource to get a specific resource then skip this step.
114114

115115
Fix errors until terraform validate passes.
116116

117-
Do not run terraform init as tests will run against a dev build.
117+
Do not run terraform init as tests will run against a dev build.

internal/api/private_endpoints.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,13 @@ package api
44
type GetPrivateEndpointResponse struct {
55
// Id is the endpoint id.
66
Id string `json:"id"`
7-
8-
// Status is the endpoint status. Possible values are failed, linked, pending, pendingAcceptance, rejected and unrecognized
7+
// Status is the endpoint status. Possible values are failed, linked, pending, pendingAcceptance, rejected and unrecognized.
98
Status string `json:"status"`
10-
119
// ServiceName is the name of the endpoint service.
1210
ServiceName string `json:"serviceName"`
1311
}
1412

1513
// GetPrivateEndpointsResponse is a list of private endpoints.
1614
type GetPrivateEndpointsResponse struct {
17-
PrivateEndpointDNS string `json:"privateEndpointDNS"`
18-
Endpoints []GetPrivateEndpointResponse `json:"endpoints"`
15+
Endpoints []GetPrivateEndpointResponse `json:"endpoints"`
1916
}

internal/datasources/private_endpoints.go

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,11 @@ func (p *PrivateEndpoints) Read(ctx context.Context, req datasource.ReadRequest,
9191
return
9292
}
9393

94-
state.PrivateEndpointDNS = types.StringValue(privateEndpointsResp.PrivateEndpointDNS)
95-
9694
for _, e := range privateEndpointsResp.Endpoints {
97-
endpointData := providerschema.PrivateEndpointData{
98-
Id: types.StringValue(e.Id),
99-
OrganizationId: types.StringValue(organizationId),
100-
ProjectId: types.StringValue(projectId),
101-
ClusterId: types.StringValue(clusterId),
102-
Status: types.StringValue(e.Status),
103-
ServiceName: types.StringValue(e.ServiceName),
104-
}
95+
endpointData := providerschema.PrivateEndpointData{}
96+
endpointData.Id = types.StringValue(e.Id)
97+
endpointData.Status = types.StringValue(e.Status)
98+
endpointData.ServiceName = types.StringValue(e.ServiceName)
10599
state.Data = append(state.Data, endpointData)
106100
}
107101

internal/datasources/private_endpoints_schema.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,14 @@ func PrivateEndpointsSchema() schema.Schema {
1515
capellaschema.AddAttr(attrs, "organization_id", privateEndpointsBuilder, requiredString())
1616
capellaschema.AddAttr(attrs, "project_id", privateEndpointsBuilder, requiredString())
1717
capellaschema.AddAttr(attrs, "cluster_id", privateEndpointsBuilder, requiredString())
18-
capellaschema.AddAttr(attrs, "private_endpoint_dns", privateEndpointsBuilder, computedString())
1918

2019
dataAttrs := make(map[string]schema.Attribute)
2120
capellaschema.AddAttr(dataAttrs, "id", privateEndpointsBuilder, computedString())
2221
capellaschema.AddAttr(dataAttrs, "organization_id", privateEndpointsBuilder, computedString())
2322
capellaschema.AddAttr(dataAttrs, "project_id", privateEndpointsBuilder, computedString())
2423
capellaschema.AddAttr(dataAttrs, "cluster_id", privateEndpointsBuilder, computedString())
24+
capellaschema.AddAttr(dataAttrs, "cloud_provider", privateEndpointsBuilder, computedString())
2525
capellaschema.AddAttr(dataAttrs, "status", privateEndpointsBuilder, computedString())
26-
capellaschema.AddAttr(dataAttrs, "service_name", privateEndpointsBuilder, computedString())
2726

2827
capellaschema.AddAttr(attrs, "data", privateEndpointsBuilder, &schema.ListNestedAttribute{
2928
Computed: true,

internal/errors/errors.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,4 @@ var (
273273
" the state from remote, unexpected error: ")
274274

275275
ErrCannotSetIopsForGcp = errors.New("iops cannot be set for GCP clusters.")
276-
277-
// ErrPrivateEndpointTimeout is returned when private endpoint does not reach linked status or DNS is not populated.
278-
ErrPrivateEndpointTimeout = errors.New("private endpoint linking timed out: status not linked or DNS not populated")
279276
)

internal/resources/private_endpoints.go

Lines changed: 29 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@ import (
55
"encoding/json"
66
"fmt"
77
"net/http"
8-
"time"
98

109
"github.com/hashicorp/terraform-plugin-framework/path"
1110
"github.com/hashicorp/terraform-plugin-framework/resource"
1211
"github.com/hashicorp/terraform-plugin-framework/types"
13-
"github.com/hashicorp/terraform-plugin-log/tflog"
1412

1513
"github.com/couchbasecloud/terraform-provider-couchbase-capella/internal/api"
1614
"github.com/couchbasecloud/terraform-provider-couchbase-capella/internal/errors"
@@ -24,10 +22,6 @@ var (
2422
_ resource.ResourceWithImportState = &PrivateEndpoint{}
2523
)
2624

27-
const (
28-
privateEndpointLinkedStatus = "linked"
29-
)
30-
3125
// PrivateEndpoint is the private endpoint resource implementation.
3226
type PrivateEndpoint struct {
3327
*providerschema.Data
@@ -98,28 +92,27 @@ func (p *PrivateEndpoint) Create(ctx context.Context, req resource.CreateRequest
9892
return
9993
}
10094

101-
plan.Status = types.StringNull()
102-
plan.ServiceName = types.StringNull()
103-
plan.PrivateEndpointDNS = types.StringNull()
104-
105-
diags = resp.State.Set(ctx, plan)
95+
diags = resp.State.Set(ctx, initializePrivateEndpointPlan(plan))
10696
resp.Diagnostics.Append(diags...)
10797
if resp.Diagnostics.HasError() {
10898
return
10999
}
110100

111-
err = p.waitUntilLinked(ctx, &plan)
101+
refreshedState, err := p.getPrivateEndpointState(ctx, organizationId, projectId, clusterId, endpointId)
112102
if err != nil {
113103
resp.Diagnostics.AddError(
114-
"Error waiting for private endpoint to be linked",
115-
"Error waiting for private endpoint to be linked, unexpected error: "+err.Error(),
104+
"Error reading private endpoint service status",
105+
"Error reading private endpoint service status, unexpected error: "+err.Error(),
116106
)
117107

118108
return
119109
}
120110

121-
diags = resp.State.Set(ctx, plan)
111+
diags = resp.State.Set(ctx, refreshedState)
122112
resp.Diagnostics.Append(diags...)
113+
if resp.Diagnostics.HasError() {
114+
return
115+
}
123116
}
124117

125118
// Read reads the private endpoint status.
@@ -264,29 +257,37 @@ func validateAcceptPrivateEndpoint(plan providerschema.PrivateEndpoint) error {
264257
return nil
265258
}
266259

260+
// initializePrivateEndpointPlan initializes an instance of providerschema.PrivateEndpoint
261+
// with the specified plan. It marks all computed fields as null.
262+
func initializePrivateEndpointPlan(plan providerschema.PrivateEndpoint) providerschema.PrivateEndpoint {
263+
if plan.Status.IsNull() || plan.Status.IsUnknown() {
264+
plan.Status = types.StringNull()
265+
}
266+
return plan
267+
}
268+
267269
// getPrivateEndpointState morphs private endpoint status to terraform schema.
268270
func (p *PrivateEndpoint) getPrivateEndpointState(ctx context.Context, organizationId, projectId, clusterId, endpointId string) (*providerschema.PrivateEndpoint, error) {
269-
status, serviceName, dns, err := p.getPrivateEndpointStatus(ctx, organizationId, projectId, clusterId, endpointId)
271+
status, serviceName, err := p.getPrivateEndpointStatus(ctx, organizationId, projectId, clusterId, endpointId)
270272
if err != nil {
271273
return nil, err
272274
}
273275

274276
state := providerschema.PrivateEndpoint{
275-
EndpointId: types.StringValue(endpointId),
276-
Status: types.StringValue(status),
277-
ClusterId: types.StringValue(clusterId),
278-
ProjectId: types.StringValue(projectId),
279-
OrganizationId: types.StringValue(organizationId),
280-
ServiceName: types.StringValue(serviceName),
281-
PrivateEndpointDNS: types.StringValue(dns),
277+
EndpointId: types.StringValue(endpointId),
278+
Status: types.StringValue(status),
279+
ClusterId: types.StringValue(clusterId),
280+
ProjectId: types.StringValue(projectId),
281+
OrganizationId: types.StringValue(organizationId),
282+
ServiceName: types.StringValue(serviceName),
282283
}
283284

284285
return &state, nil
285286
}
286287

287288
// There is currently no V4 endpoint to get a single private endpoint. We have to loop through the entire list to find
288289
// the desired private endpoint.
289-
func (p *PrivateEndpoint) getPrivateEndpointStatus(ctx context.Context, organizationId, projectId, clusterId, endpointId string) (string, string, string, error) {
290+
func (p *PrivateEndpoint) getPrivateEndpointStatus(ctx context.Context, organizationId, projectId, clusterId, endpointId string) (string, string, error) {
290291
url := fmt.Sprintf("%s/v4/organizations/%s/projects/%s/clusters/%s/privateEndpointService/endpoints", p.HostURL, organizationId, projectId, clusterId)
291292
cfg := api.EndpointCfg{Url: url, Method: http.MethodGet, SuccessStatus: http.StatusOK}
292293
response, err := p.ClientV1.ExecuteWithRetry(
@@ -297,63 +298,20 @@ func (p *PrivateEndpoint) getPrivateEndpointStatus(ctx context.Context, organiza
297298
nil,
298299
)
299300
if err != nil {
300-
return "", "", "", err
301+
return "", "", err
301302
}
302303

303304
privateEndpointsResp := api.GetPrivateEndpointsResponse{}
304305
err = json.Unmarshal(response.Body, &privateEndpointsResp)
305306
if err != nil {
306-
return "", "", "", err
307+
return "", "", err
307308
}
308309

309310
for _, e := range privateEndpointsResp.Endpoints {
310311
if e.Id == endpointId {
311-
return e.Status, e.ServiceName, privateEndpointsResp.PrivateEndpointDNS, nil
312+
return e.Status, e.ServiceName, nil
312313
}
313314
}
314315

315-
return "", "", "", errors.ErrNotFound
316-
}
317-
318-
// waitUntilLinked polls the private endpoint until it reaches linked status and DNS is populated.
319-
func (p *PrivateEndpoint) waitUntilLinked(ctx context.Context, plan *providerschema.PrivateEndpoint) error {
320-
var cancel context.CancelFunc
321-
ctx, cancel = context.WithTimeout(ctx, time.Minute*5)
322-
defer cancel()
323-
324-
timer := time.NewTimer(time.Second * 1)
325-
defer timer.Stop()
326-
327-
for {
328-
select {
329-
case <-ctx.Done():
330-
return errors.ErrPrivateEndpointTimeout
331-
332-
case <-timer.C:
333-
status, serviceName, dns, err := p.getPrivateEndpointStatus(
334-
ctx,
335-
plan.OrganizationId.ValueString(),
336-
plan.ProjectId.ValueString(),
337-
plan.ClusterId.ValueString(),
338-
plan.EndpointId.ValueString(),
339-
)
340-
if err != nil {
341-
return err
342-
}
343-
344-
if status == privateEndpointLinkedStatus {
345-
if dns == "" {
346-
tflog.Info(ctx, "Private endpoint is linked but DNS is not populated.")
347-
timer.Reset(time.Minute * 1)
348-
continue
349-
}
350-
plan.ServiceName = types.StringValue(serviceName)
351-
plan.Status = types.StringValue(status)
352-
plan.PrivateEndpointDNS = types.StringValue(dns)
353-
return nil
354-
}
355-
tflog.Info(ctx, "Private endpoint is not linked.")
356-
timer.Reset(time.Minute * 1)
357-
}
358-
}
316+
return "", "", errors.ErrNotFound
359317
}

internal/resources/private_endpoints_schema.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ func PrivateEndpointsSchema() schema.Schema {
1717
capellaschema.AddAttr(attrs, "endpoint_id", privateEndpointsBuilder, stringAttribute([]string{required, requiresReplace}))
1818
capellaschema.AddAttr(attrs, "status", privateEndpointsBuilder, stringAttribute([]string{computed}))
1919
capellaschema.AddAttr(attrs, "service_name", privateEndpointsBuilder, stringAttribute([]string{computed}))
20-
capellaschema.AddAttr(attrs, "private_endpoint_dns", privateEndpointsBuilder, stringAttribute([]string{computed}))
2120

2221
return schema.Schema{
2322
MarkdownDescription: "This resource allows you to manage private endpoints for an operational cluster. Private endpoints allow you to securely connect your Cloud Service Provider's private network (VPC/VNET) to your operational cluster without exposing traffic to the public internet.",

internal/schema/private_endpoints.go

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,28 +28,24 @@ type PrivateEndpoint struct {
2828

2929
// ServiceName is the name of the private endpoint service.
3030
ServiceName types.String `tfsdk:"service_name"`
31-
32-
// PrivateEndpointDNS is the DNS of the private endpoint.
33-
PrivateEndpointDNS types.String `tfsdk:"private_endpoint_dns"`
3431
}
3532

3633
// PrivateEndpoints defines a structure used by the LIST endpoint for private endpoints.
3734
type PrivateEndpoints struct {
38-
ClusterId types.String `tfsdk:"cluster_id"`
39-
ProjectId types.String `tfsdk:"project_id"`
40-
OrganizationId types.String `tfsdk:"organization_id"`
41-
PrivateEndpointDNS types.String `tfsdk:"private_endpoint_dns"`
42-
Data []PrivateEndpointData `tfsdk:"data"`
35+
ClusterId types.String `tfsdk:"cluster_id"`
36+
ProjectId types.String `tfsdk:"project_id"`
37+
OrganizationId types.String `tfsdk:"organization_id"`
38+
Data []PrivateEndpointData `tfsdk:"data"`
4339
}
4440

4541
// PrivateEndpointData defines a single private endpoint.
4642
type PrivateEndpointData struct {
47-
Id types.String `tfsdk:"id"`
48-
OrganizationId types.String `tfsdk:"organization_id"`
49-
ProjectId types.String `tfsdk:"project_id"`
50-
ClusterId types.String `tfsdk:"cluster_id"`
51-
Status types.String `tfsdk:"status"`
52-
ServiceName types.String `tfsdk:"service_name"`
43+
// Id is the endpoint id.
44+
Id types.String `tfsdk:"id"`
45+
// Status is the endpoint status. Possible values are failed, linked, pending, pendingAcceptance, rejected and unrecognized.
46+
Status types.String `tfsdk:"status"`
47+
// ServiceName is the name of the endpoint service.
48+
ServiceName types.String `tfsdk:"service_name"`
5349
}
5450

5551
// Validate is used to verify that IDs have been properly imported.

0 commit comments

Comments
 (0)