Skip to content

Commit fd02f20

Browse files
author
sivaram-mongodb
committed
feat: update private-endpoint-aws resource
1 parent b00a7ab commit fd02f20

6 files changed

Lines changed: 219 additions & 51 deletions

File tree

cfn-resources/private-endpoint-aws/cmd/resource/model.go

Lines changed: 11 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cfn-resources/private-endpoint-aws/cmd/resource/resource.go

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import (
2121
"net/http"
2222
"strings"
2323

24-
admin20231115014 "go.mongodb.org/atlas-sdk/v20231115014/admin"
24+
"go.mongodb.org/atlas-sdk/v20250312012/admin"
2525

2626
"github.com/aws-cloudformation/cloudformation-cli-go-plugin/cfn/handler"
2727
"github.com/aws/aws-sdk-go-v2/aws"
@@ -92,11 +92,13 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler
9292
*privateEndpoint.ConnectionStatus == Rejected {
9393
return handler.ProgressEvent{
9494
OperationStatus: handler.Failed,
95-
Message: fmt.Sprintf("Connection was Rejected : %s", *privateEndpoint.ErrorMessage),
95+
Message: fmt.Sprintf("Connection was Rejected: %s", *privateEndpoint.ErrorMessage),
9696
ResourceModel: currentModel,
9797
}, nil
9898
}
9999

100+
currentModel.completeByAtlasModel(*privateEndpoint)
101+
100102
return handler.ProgressEvent{
101103
OperationStatus: handler.Success,
102104
Message: "Create Success",
@@ -115,11 +117,11 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler
115117
}}, nil
116118
}
117119

118-
endpointRequest := admin20231115014.CreateEndpointRequest{
120+
endpointRequest := admin.CreateEndpointRequest{
119121
Id: currentModel.Id,
120122
}
121123

122-
privateEndpointRequest := client.Atlas20231115014.PrivateEndpointServicesApi.CreatePrivateEndpoint(context.Background(), *currentModel.ProjectId,
124+
privateEndpointRequest := client.AtlasSDK.PrivateEndpointServicesApi.CreatePrivateEndpoint(context.Background(), *currentModel.ProjectId,
123125
CloudProvider, *currentModel.EndpointServiceId, &endpointRequest)
124126

125127
_, response, err := privateEndpointRequest.Execute()
@@ -146,8 +148,8 @@ func Create(req handler.Request, prevModel *Model, currentModel *Model) (handler
146148
}}, nil
147149
}
148150

149-
func getPrivateEndpoint(client *util.MongoDBClient, model *Model) (*admin20231115014.PrivateLinkEndpoint, *http.Response, error) {
150-
privateEndpointRequest := client.Atlas20231115014.PrivateEndpointServicesApi.GetPrivateEndpoint(context.Background(), *model.ProjectId,
151+
func getPrivateEndpoint(client *util.MongoDBClient, model *Model) (*admin.PrivateLinkEndpoint, *http.Response, error) {
152+
privateEndpointRequest := client.AtlasSDK.PrivateEndpointServicesApi.GetPrivateEndpoint(context.Background(), *model.ProjectId,
151153
CloudProvider, *model.Id, *model.EndpointServiceId)
152154
privateEndpoint, response, err := privateEndpointRequest.Execute()
153155

@@ -184,9 +186,13 @@ func Read(req handler.Request, prevModel *Model, currentModel *Model) (handler.P
184186
}, nil
185187
}
186188

187-
func (m *Model) completeByAtlasModel(privateEndpoint admin20231115014.PrivateLinkEndpoint) {
188-
m.ErrorMessage = privateEndpoint.ErrorMessage
189+
func (m *Model) completeByAtlasModel(privateEndpoint admin.PrivateLinkEndpoint) {
190+
m.InterfaceEndpointId = privateEndpoint.InterfaceEndpointId
191+
m.PrivateEndpointConnectionName = privateEndpoint.PrivateEndpointConnectionName
192+
m.PrivateEndpointResourceId = privateEndpoint.PrivateEndpointResourceId
193+
m.DeleteRequested = privateEndpoint.DeleteRequested
189194
m.ConnectionStatus = privateEndpoint.ConnectionStatus
195+
m.ErrorMessage = privateEndpoint.ErrorMessage
190196
}
191197

192198
// Update handles the Update event from the Cloudformation service.
@@ -218,34 +224,36 @@ func Delete(req handler.Request, prevModel *Model, currentModel *Model) (handler
218224
if response.StatusCode == http.StatusNotFound {
219225
return handler.ProgressEvent{
220226
OperationStatus: handler.Success,
221-
Message: "Create Success",
227+
Message: "Delete Success",
222228
}, nil
223229
}
224230
return progress_events.GetFailedEventByResponse("Error validating Private Endpoint deletion progress", response), nil
225231
}
226232

227233
return handler.ProgressEvent{
228234
OperationStatus: handler.InProgress,
229-
Message: "Create in progress",
235+
Message: "Delete in progress",
230236
CallbackDelaySeconds: 20,
231237
CallbackContext: map[string]interface{}{
232238
"state": "deleting",
233239
}}, nil
234240
}
235241

236-
privateEndpointRequest := client.Atlas20231115014.PrivateEndpointServicesApi.DeletePrivateEndpoint(context.Background(), *currentModel.ProjectId,
242+
privateEndpointRequest := client.AtlasSDK.PrivateEndpointServicesApi.DeletePrivateEndpoint(context.Background(), *currentModel.ProjectId,
237243
CloudProvider, *currentModel.Id, *currentModel.EndpointServiceId)
238-
_, response, err := privateEndpointRequest.Execute()
239-
defer response.Body.Close()
244+
response, err := privateEndpointRequest.Execute()
245+
if response != nil && response.Body != nil {
246+
defer response.Body.Close()
247+
}
240248
if err != nil {
241-
return progress_events.GetFailedEventByResponse(fmt.Sprintf("error creating Serverless Private Endpoint %s",
249+
return progress_events.GetFailedEventByResponse(fmt.Sprintf("error deleting Private Endpoint: %s",
242250
err.Error()), response),
243251
nil
244252
}
245253

246254
return handler.ProgressEvent{
247255
OperationStatus: handler.InProgress,
248-
Message: "Create in progress",
256+
Message: "Delete in progress",
249257
CallbackDelaySeconds: 20,
250258
ResourceModel: currentModel,
251259
CallbackContext: map[string]interface{}{

cfn-resources/private-endpoint-aws/docs/README.md

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# MongoDB::Atlas::PrivateEndpointAWS
22

3-
Creates one private endpoint for the specified cloud service provider. At this current version only AWS is supported
3+
Creates one private endpoint connection for AWS PrivateLink. This resource links an AWS VPC endpoint to a MongoDB Atlas private endpoint service.
44

55
## Syntax
66

@@ -17,8 +17,6 @@ To declare this entity in your AWS CloudFormation template, use the following sy
1717
"<a href="#endpointserviceid" title="EndpointServiceId">EndpointServiceId</a>" : <i>String</i>,
1818
"<a href="#id" title="Id">Id</a>" : <i>String</i>,
1919
"<a href="#enforceconnectionsuccess" title="EnforceConnectionSuccess">EnforceConnectionSuccess</a>" : <i>Boolean</i>,
20-
"<a href="#connectionstatus" title="ConnectionStatus">ConnectionStatus</a>" : <i>String</i>,
21-
"<a href="#errormessage" title="ErrorMessage">ErrorMessage</a>" : <i>String</i>
2220
}
2321
}
2422
</pre>
@@ -33,8 +31,6 @@ Properties:
3331
<a href="#endpointserviceid" title="EndpointServiceId">EndpointServiceId</a>: <i>String</i>
3432
<a href="#id" title="Id">Id</a>: <i>String</i>
3533
<a href="#enforceconnectionsuccess" title="EnforceConnectionSuccess">EnforceConnectionSuccess</a>: <i>Boolean</i>
36-
<a href="#connectionstatus" title="ConnectionStatus">ConnectionStatus</a>: <i>String</i>
37-
<a href="#errormessage" title="ErrorMessage">ErrorMessage</a>: <i>String</i>
3834
</pre>
3935

4036
## Properties
@@ -57,55 +53,71 @@ _Required_: Yes
5753

5854
_Type_: String
5955

56+
_Pattern_: <code>^([a-f0-9]{24})$</code>
57+
6058
_Update requires_: [Replacement](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-replacement)
6159

6260
#### EndpointServiceId
6361

64-
Unique 24-hexadecimal digit string that identifies the private endpoint service for which you want to create a private endpoint.
62+
Unique 24-hexadecimal digit string that identifies the Atlas private endpoint service (created with MongoDB::Atlas::PrivateEndpointService) to which you want to connect this VPC endpoint.
6563

6664
_Required_: Yes
6765

6866
_Type_: String
6967

68+
_Pattern_: <code>^([a-f0-9]{24})$</code>
69+
7070
_Update requires_: [Replacement](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-replacement)
7171

7272
#### Id
7373

74-
Unique string that identifies the private endpoint. for AWS is the VPC endpoint ID, example: vpce-xxxxxxxx
74+
Unique string that identifies the AWS VPC endpoint (interface endpoint) that you created in your VPC. Example: vpce-0d00c26273372c6ef
7575

76-
_Required_: No
76+
_Required_: Yes
7777

7878
_Type_: String
7979

8080
_Update requires_: [Replacement](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-replacement)
8181

8282
#### EnforceConnectionSuccess
8383

84-
If this proper is set to TRUE, the cloud formation resource will return success Only if the private connection is Succeeded
84+
If set to true, CloudFormation will only return success when the private endpoint connection status is AVAILABLE. If set to false, it returns success once the connection is created regardless of status.
8585

8686
_Required_: No
8787

8888
_Type_: Boolean
8989

9090
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
9191

92-
#### ConnectionStatus
92+
## Return Values
9393

94-
State of the Amazon Web Service PrivateLink connection when MongoDB Cloud received this request.
94+
### Fn::GetAtt
9595

96-
_Required_: No
96+
The `Fn::GetAtt` intrinsic function returns a value for a specified attribute of this type. The following are the available attributes and sample return values.
9797

98-
_Type_: String
98+
For more information about using the `Fn::GetAtt` intrinsic function, see [Fn::GetAtt](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/intrinsic-function-reference-getatt.html).
9999

100-
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
100+
#### InterfaceEndpointId
101101

102-
#### ErrorMessage
102+
Unique identifier of the interface endpoint.
103103

104-
Error message returned when requesting private connection resource. The resource returns null if the request succeeded.
104+
#### PrivateEndpointConnectionName
105105

106-
_Required_: No
106+
Name of the connection for this private endpoint that Atlas generates.
107107

108-
_Type_: String
108+
#### PrivateEndpointResourceId
109109

110-
_Update requires_: [No interruption](https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/using-cfn-updating-stacks-update-behaviors.html#update-no-interrupt)
110+
Unique identifier of the private endpoint resource.
111+
112+
#### DeleteRequested
113+
114+
Indicates if Atlas received a request to remove the interface endpoint from the private endpoint connection.
115+
116+
#### ConnectionStatus
117+
118+
Status of the AWS PrivateLink connection. Returns one of: NONE, PENDING_ACCEPTANCE, PENDING, AVAILABLE, REJECTED, DELETING.
119+
120+
#### ErrorMessage
121+
122+
Error message pertaining to the interface endpoint. Returns null if there are no errors.
111123

cfn-resources/private-endpoint-aws/mongodb-atlas-privateendpointaws.json

Lines changed: 45 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
{
22
"typeName": "MongoDB::Atlas::PrivateEndpointAWS",
3-
"description": "Creates one private endpoint for the specified cloud service provider. At this current version only AWS is supported",
3+
"description": "Creates one private endpoint connection for AWS PrivateLink. This resource links an AWS VPC endpoint to a MongoDB Atlas private endpoint service.",
44
"sourceUrl": "https://github.com/mongodb/mongodbatlas-cloudformation-resources/tree/master/cfn-resources/private-endpoint-aws",
55
"documentationUrl": "https://github.com/mongodb/mongodbatlas-cloudformation-resources/blob/master/cfn-resources/private-endpoint-aws/README.md",
66
"tagging": {
77
"taggable": false
88
},
99
"required": [
1010
"ProjectId",
11-
"EndpointServiceId"
11+
"EndpointServiceId",
12+
"Id"
1213
],
1314
"properties": {
1415
"Profile": {
@@ -18,26 +19,52 @@
1819
},
1920
"ProjectId": {
2021
"description": "Unique 24-hexadecimal digit string that identifies your project.",
21-
"type": "string"
22+
"type": "string",
23+
"pattern": "^([a-f0-9]{24})$"
2224
},
2325
"EndpointServiceId": {
24-
"description": "Unique 24-hexadecimal digit string that identifies the private endpoint service for which you want to create a private endpoint.",
25-
"type": "string"
26+
"description": "Unique 24-hexadecimal digit string that identifies the Atlas private endpoint service (created with MongoDB::Atlas::PrivateEndpointService) to which you want to connect this VPC endpoint.",
27+
"type": "string",
28+
"pattern": "^([a-f0-9]{24})$"
2629
},
2730
"Id": {
28-
"description": "Unique string that identifies the private endpoint. for AWS is the VPC endpoint ID, example: vpce-xxxxxxxx",
31+
"description": "Unique string that identifies the AWS VPC endpoint (interface endpoint) that you created in your VPC. Example: vpce-0d00c26273372c6ef",
2932
"type": "string"
3033
},
3134
"EnforceConnectionSuccess": {
32-
"description": "If this proper is set to TRUE, the cloud formation resource will return success Only if the private connection is Succeeded",
35+
"description": "If set to true, CloudFormation will only return success when the private endpoint connection status is AVAILABLE. If set to false, it returns success once the connection is created regardless of status.",
3336
"type": "boolean"
3437
},
35-
"ConnectionStatus": {
36-
"description": "State of the Amazon Web Service PrivateLink connection when MongoDB Cloud received this request.",
38+
"InterfaceEndpointId": {
39+
"description": "Unique identifier of the interface endpoint.",
40+
"type": "string"
41+
},
42+
"PrivateEndpointConnectionName": {
43+
"description": "Name of the connection for this private endpoint that Atlas generates.",
44+
"type": "string"
45+
},
46+
"PrivateEndpointResourceId": {
47+
"description": "Unique identifier of the private endpoint resource.",
3748
"type": "string"
3849
},
50+
"DeleteRequested": {
51+
"description": "Indicates if Atlas received a request to remove the interface endpoint from the private endpoint connection.",
52+
"type": "boolean"
53+
},
54+
"ConnectionStatus": {
55+
"description": "Status of the AWS PrivateLink connection. Returns one of: NONE, PENDING_ACCEPTANCE, PENDING, AVAILABLE, REJECTED, DELETING.",
56+
"type": "string",
57+
"enum": [
58+
"NONE",
59+
"PENDING_ACCEPTANCE",
60+
"PENDING",
61+
"AVAILABLE",
62+
"REJECTED",
63+
"DELETING"
64+
]
65+
},
3966
"ErrorMessage": {
40-
"description": "Error message returned when requesting private connection resource. The resource returns null if the request succeeded.",
67+
"description": "Error message pertaining to the interface endpoint. Returns null if there are no errors.",
4168
"type": "string"
4269
}
4370
},
@@ -54,6 +81,14 @@
5481
"/properties/Profile",
5582
"/properties/Id"
5683
],
84+
"readOnlyProperties": [
85+
"/properties/InterfaceEndpointId",
86+
"/properties/PrivateEndpointConnectionName",
87+
"/properties/PrivateEndpointResourceId",
88+
"/properties/DeleteRequested",
89+
"/properties/ConnectionStatus",
90+
"/properties/ErrorMessage"
91+
],
5792
"handlers": {
5893
"create": {
5994
"permissions": [
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# How to create a MongoDB::Atlas::PrivateEndpointAWS
2+
3+
## Step 1: Activate the PrivateEndpointAWS resource in CloudFormation
4+
Step a: Create Role using [execution-role.yaml](https://github.com/mongodb/mongodbatlas-cloudformation-resources/blob/master/examples/execution-role.yaml) in CFN resources folder.
5+
6+
Step b: Search for MongoDB::Atlas::PrivateEndpointAWS resource.
7+
8+
(CloudFormation > Public extensions > choose 'Third party' > Search with " Execution name prefix = MongoDB " )
9+
10+
Step c: Select and activate
11+
Enter the RoleArn that is created in step 1.
12+
13+
Your PrivateEndpointAWS Resource is ready to use.
14+
15+
## Step 2: Create template using [private-endpoint-aws.json](private-endpoint-aws.json)
16+
Note: Make sure you are providing appropriate values for:
17+
1. MongoDBAtlasProjectId
18+
2. AtlasPrivateEndpointServiceId (get from: `atlas privateEndpoints aws list --projectId <PROJECT_ID>`)
19+
3. AWSVPCEndpointId (format: vpce-xxxxxxxxx)
20+
4. Profile (optional)
21+
5. EnforceConnectionSuccess (optional)
22+

0 commit comments

Comments
 (0)