Skip to content

Commit fea51f6

Browse files
coderGo93Edgar López
andauthored
INTMDB-158: Added private endpoint in connection strings (#392)
* chore: updated client mongodb * feat: added parameter private endpoint in connection strings schema * test: modified using privatelink endpoint instead of deprecated ones * docs: updated docs for private endpoint in connection strings * docs: updated deprecated markdown * chore: updated client mongodb with recent release * refactor: added func for connection strings cluster schema to fix lint errors Co-authored-by: Edgar López <[email protected]>
1 parent 785dee1 commit fea51f6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+1139
-86
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@ require (
1111
github.com/spf13/cast v1.3.1
1212
github.com/terraform-providers/terraform-provider-aws v1.60.1-0.20200518153306-40099de47e37
1313
github.com/terraform-providers/terraform-provider-google v1.20.1-0.20200518165017-1dd21651c496
14-
go.mongodb.org/atlas v0.7.0
14+
go.mongodb.org/atlas v0.7.1
1515
)

go.sum

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,10 @@ go.mongodb.org/atlas v0.6.1-0.20210106014125-8dd299fe028a h1:5gYtQbQA6MCmHkOe7nA
609609
go.mongodb.org/atlas v0.6.1-0.20210106014125-8dd299fe028a/go.mod h1:CIaBeO8GLHhtYLw7xSSXsw7N90Z4MFY87Oy9qcPyuEs=
610610
go.mongodb.org/atlas v0.7.0 h1:nBur5go1JSCFCi1VaQ7Ry6du2uHjMFY0w8rI64KQ+b0=
611611
go.mongodb.org/atlas v0.7.0/go.mod h1:CIaBeO8GLHhtYLw7xSSXsw7N90Z4MFY87Oy9qcPyuEs=
612+
go.mongodb.org/atlas v0.7.1-0.20210125210709-d3fc89f33ab2 h1:MDNdtE3XPOOpyoFFOo0a8BbodicG6DQMgNS5FPag9/g=
613+
go.mongodb.org/atlas v0.7.1-0.20210125210709-d3fc89f33ab2/go.mod h1:CIaBeO8GLHhtYLw7xSSXsw7N90Z4MFY87Oy9qcPyuEs=
614+
go.mongodb.org/atlas v0.7.1 h1:hNBtwtKgmhB9vmSX/JyN/cArmhzyy4ihKpmXSMIc4mw=
615+
go.mongodb.org/atlas v0.7.1/go.mod h1:CIaBeO8GLHhtYLw7xSSXsw7N90Z4MFY87Oy9qcPyuEs=
612616
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
613617
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
614618
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=

mongodbatlas/data_source_mongodbatlas_cluster.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,46 @@ func dataSourceMongoDBAtlasCluster() *schema.Resource {
8989
Type: schema.TypeString,
9090
Computed: true,
9191
},
92+
"private_endpoint": {
93+
Type: schema.TypeList,
94+
Computed: true,
95+
Elem: &schema.Resource{
96+
Schema: map[string]*schema.Schema{
97+
"connection_string": {
98+
Type: schema.TypeString,
99+
Computed: true,
100+
},
101+
"endpoints": {
102+
Type: schema.TypeList,
103+
Computed: true,
104+
Elem: &schema.Resource{
105+
Schema: map[string]*schema.Schema{
106+
"endpoint_id": {
107+
Type: schema.TypeString,
108+
Computed: true,
109+
},
110+
"provider_name": {
111+
Type: schema.TypeString,
112+
Computed: true,
113+
},
114+
"region": {
115+
Type: schema.TypeString,
116+
Computed: true,
117+
},
118+
},
119+
},
120+
},
121+
"srv_connection_string": {
122+
Type: schema.TypeString,
123+
Computed: true,
124+
},
125+
"type": {
126+
Type: schema.TypeString,
127+
Computed: true,
128+
},
129+
},
130+
},
131+
},
92132
},
93133
},
94134
},

mongodbatlas/data_source_mongodbatlas_clusters.go

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,46 @@ func dataSourceMongoDBAtlasClusters() *schema.Resource {
9696
Type: schema.TypeString,
9797
Computed: true,
9898
},
99+
"private_endpoint": {
100+
Type: schema.TypeList,
101+
Computed: true,
102+
Elem: &schema.Resource{
103+
Schema: map[string]*schema.Schema{
104+
"connection_string": {
105+
Type: schema.TypeString,
106+
Computed: true,
107+
},
108+
"endpoints": {
109+
Type: schema.TypeList,
110+
Computed: true,
111+
Elem: &schema.Resource{
112+
Schema: map[string]*schema.Schema{
113+
"endpoint_id": {
114+
Type: schema.TypeString,
115+
Computed: true,
116+
},
117+
"provider_name": {
118+
Type: schema.TypeString,
119+
Computed: true,
120+
},
121+
"region": {
122+
Type: schema.TypeString,
123+
Computed: true,
124+
},
125+
},
126+
},
127+
},
128+
"srv_connection_string": {
129+
Type: schema.TypeString,
130+
Computed: true,
131+
},
132+
"type": {
133+
Type: schema.TypeString,
134+
Computed: true,
135+
},
136+
},
137+
},
138+
},
99139
},
100140
},
101141
},

mongodbatlas/resource_mongodbatlas_cluster.go

Lines changed: 106 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -107,40 +107,7 @@ func resourceMongoDBAtlasCluster() *schema.Resource {
107107
Optional: true,
108108
Computed: true,
109109
},
110-
"connection_strings": {
111-
Type: schema.TypeList,
112-
MinItems: 1,
113-
MaxItems: 1,
114-
Computed: true,
115-
Elem: &schema.Resource{
116-
Schema: map[string]*schema.Schema{
117-
"standard": {
118-
Type: schema.TypeString,
119-
Computed: true,
120-
},
121-
"standard_srv": {
122-
Type: schema.TypeString,
123-
Computed: true,
124-
},
125-
"aws_private_link": {
126-
Type: schema.TypeMap,
127-
Computed: true,
128-
},
129-
"aws_private_link_srv": {
130-
Type: schema.TypeMap,
131-
Computed: true,
132-
},
133-
"private": {
134-
Type: schema.TypeString,
135-
Computed: true,
136-
},
137-
"private_srv": {
138-
Type: schema.TypeString,
139-
Computed: true,
140-
},
141-
},
142-
},
143-
},
110+
"connection_strings": clusterConnectionStringsSchema(),
144111
"disk_size_gb": {
145112
Type: schema.TypeFloat,
146113
Optional: true,
@@ -1303,11 +1270,37 @@ func flattenConnectionStrings(connectionStrings *matlas.ConnectionStrings) []map
13031270
"aws_private_link_srv": connectionStrings.AwsPrivateLinkSrv,
13041271
"private": connectionStrings.Private,
13051272
"private_srv": connectionStrings.PrivateSrv,
1273+
"private_endpoint": flattenPrivateEndpoint(connectionStrings.PrivateEndpoint),
13061274
})
13071275

13081276
return connections
13091277
}
13101278

1279+
func flattenPrivateEndpoint(privateEndpoints []matlas.PrivateEndpoint) []map[string]interface{} {
1280+
endpoints := make([]map[string]interface{}, 0)
1281+
for _, endpoint := range privateEndpoints {
1282+
endpoints = append(endpoints, map[string]interface{}{
1283+
"connection_string": endpoint.ConnectionString,
1284+
"srv_connection_string": endpoint.SRVConnectionString,
1285+
"endpoints": flattenEndpoints(endpoint.Endpoints),
1286+
"type": endpoint.Type,
1287+
})
1288+
}
1289+
return endpoints
1290+
}
1291+
1292+
func flattenEndpoints(listEndpoints []matlas.Endpoint) []map[string]interface{} {
1293+
endpoints := make([]map[string]interface{}, 0)
1294+
for _, endpoint := range listEndpoints {
1295+
endpoints = append(endpoints, map[string]interface{}{
1296+
"region": endpoint.Region,
1297+
"provider_name": endpoint.ProviderName,
1298+
"endpoint_id": endpoint.EndpointID,
1299+
})
1300+
}
1301+
return endpoints
1302+
}
1303+
13111304
func getContainerID(containers []matlas.Container, cluster *matlas.Cluster) string {
13121305
if len(containers) != 0 {
13131306
for i := range containers {
@@ -1325,3 +1318,82 @@ func getContainerID(containers []matlas.Container, cluster *matlas.Cluster) stri
13251318

13261319
return ""
13271320
}
1321+
1322+
func clusterConnectionStringsSchema() *schema.Schema {
1323+
return &schema.Schema{
1324+
Type: schema.TypeList,
1325+
MinItems: 1,
1326+
MaxItems: 1,
1327+
Computed: true,
1328+
Elem: &schema.Resource{
1329+
Schema: map[string]*schema.Schema{
1330+
"standard": {
1331+
Type: schema.TypeString,
1332+
Computed: true,
1333+
},
1334+
"standard_srv": {
1335+
Type: schema.TypeString,
1336+
Computed: true,
1337+
},
1338+
"aws_private_link": {
1339+
Type: schema.TypeMap,
1340+
Computed: true,
1341+
Deprecated: "This field is deprecated. Use connection_strings.private_endpoint[n].connection_string instead",
1342+
},
1343+
"aws_private_link_srv": {
1344+
Type: schema.TypeMap,
1345+
Computed: true,
1346+
Deprecated: "This field is deprecated. Use connection_strings.private_endpoint[n].srv_connection_string instead",
1347+
},
1348+
"private": {
1349+
Type: schema.TypeString,
1350+
Computed: true,
1351+
},
1352+
"private_srv": {
1353+
Type: schema.TypeString,
1354+
Computed: true,
1355+
},
1356+
"private_endpoint": {
1357+
Type: schema.TypeList,
1358+
Computed: true,
1359+
Elem: &schema.Resource{
1360+
Schema: map[string]*schema.Schema{
1361+
"connection_string": {
1362+
Type: schema.TypeString,
1363+
Computed: true,
1364+
},
1365+
"endpoints": {
1366+
Type: schema.TypeList,
1367+
Computed: true,
1368+
Elem: &schema.Resource{
1369+
Schema: map[string]*schema.Schema{
1370+
"endpoint_id": {
1371+
Type: schema.TypeString,
1372+
Computed: true,
1373+
},
1374+
"provider_name": {
1375+
Type: schema.TypeString,
1376+
Computed: true,
1377+
},
1378+
"region": {
1379+
Type: schema.TypeString,
1380+
Computed: true,
1381+
},
1382+
},
1383+
},
1384+
},
1385+
"srv_connection_string": {
1386+
Type: schema.TypeString,
1387+
Computed: true,
1388+
},
1389+
"type": {
1390+
Type: schema.TypeString,
1391+
Computed: true,
1392+
},
1393+
},
1394+
},
1395+
},
1396+
},
1397+
},
1398+
}
1399+
}

mongodbatlas/resource_mongodbatlas_cluster_test.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1225,24 +1225,25 @@ func testAccMongoDBAtlasClusterConfigWithPrivateEndpointLink(awsAccessKey, awsSe
12251225
secret_key = "%[2]s"
12261226
}
12271227
1228-
resource "mongodbatlas_private_endpoint" "test" {
1228+
resource "mongodbatlas_privatelink_endpoint" "test" {
12291229
project_id = "%[3]s"
12301230
provider_name = "%[4]s"
12311231
region = "%[5]s"
12321232
}
12331233
12341234
resource "aws_vpc_endpoint" "ptfe_service" {
12351235
vpc_id = "%[6]s"
1236-
service_name = "${mongodbatlas_private_endpoint.test.endpoint_service_name}"
1236+
service_name = mongodbatlas_privatelink_endpoint.test.endpoint_service_name
12371237
vpc_endpoint_type = "Interface"
12381238
subnet_ids = ["%[7]s"]
12391239
security_group_ids = ["%[8]s"]
12401240
}
12411241
1242-
resource "mongodbatlas_private_endpoint_interface_link" "test" {
1243-
project_id = "${mongodbatlas_private_endpoint.test.project_id}"
1244-
private_link_id = "${mongodbatlas_private_endpoint.test.private_link_id}"
1245-
interface_endpoint_id = "${aws_vpc_endpoint.ptfe_service.id}"
1242+
resource "mongodbatlas_privatelink_endpoint_service" "test" {
1243+
project_id = mongodbatlas_privatelink_endpoint.test.project_id
1244+
private_link_id = mongodbatlas_privatelink_endpoint.test.private_link_id
1245+
endpoint_service_id = aws_vpc_endpoint.ptfe_service.id
1246+
provider_name = "%[4]s"
12461247
}
12471248
12481249
resource "mongodbatlas_cluster" "with_endpoint_link" {
@@ -1256,8 +1257,8 @@ func testAccMongoDBAtlasClusterConfigWithPrivateEndpointLink(awsAccessKey, awsSe
12561257
provider_instance_size_name = "M10"
12571258
provider_backup_enabled = true // enable cloud provider snapshots
12581259
provider_disk_iops = 100
1259-
provider_encrypt_ebs_volume = false
1260-
depends_on = ["mongodbatlas_private_endpoint_interface_link.test"]
1260+
provider_encrypt_ebs_volume = true
1261+
depends_on = ["mongodbatlas_privatelink_endpoint_service.test"]
12611262
}
12621263
`, awsAccessKey, awsSecretKey, projectID, providerName, region, vpcID, subnetID, securityGroupID, clusterName)
12631264
}

vendor/go.mongodb.org/atlas/mongodbatlas/accesslist_api_keys.go

Lines changed: 15 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/go.mongodb.org/atlas/mongodbatlas/alert_configurations.go

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

vendor/go.mongodb.org/atlas/mongodbatlas/alerts.go

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

vendor/go.mongodb.org/atlas/mongodbatlas/api_keys.go

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

0 commit comments

Comments
 (0)