Skip to content

Commit 564563a

Browse files
require cluster for creating private link connection
1 parent b680cf0 commit 564563a

13 files changed

Lines changed: 181 additions & 20 deletions

File tree

docs/data-sources/stream_privatelink_endpoint.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,27 @@ output "dns_domain" {
342342
```
343343

344344
### Azure Blob Storage Privatelink
345+
346+
~> **NOTE:** An Azure cluster must be provisioned in the same region before creating an Azure Blob Storage private endpoint.
347+
345348
```terraform
349+
resource "mongodbatlas_advanced_cluster" "cluster" {
350+
project_id = var.project_id
351+
name = var.cluster_name
352+
cluster_type = "REPLICASET"
353+
replication_specs = [{
354+
region_configs = [{
355+
priority = 7
356+
provider_name = "AZURE"
357+
region_name = "US_EAST_2"
358+
electable_specs = {
359+
instance_size = "M10"
360+
node_count = 3
361+
}
362+
}]
363+
}]
364+
}
365+
346366
resource "mongodbatlas_stream_privatelink_endpoint" "this" {
347367
project_id = var.project_id
348368
vendor = "AZURE_BLOB_STORAGE"
@@ -352,7 +372,7 @@ resource "mongodbatlas_stream_privatelink_endpoint" "this" {
352372
dns_domain = "${var.storage_account_name}.blob.core.windows.net"
353373
# service_endpoint_id follows the format `/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Storage/storageAccounts/{storageAccount}`
354374
service_endpoint_id = "/subscriptions/${data.azurerm_client_config.current.subscription_id}/resourceGroups/${var.azure_resource_group}/providers/Microsoft.Storage/storageAccounts/${var.storage_account_name}"
355-
depends_on = [azurerm_private_endpoint.blob_endpoint]
375+
depends_on = [mongodbatlas_advanced_cluster.cluster, azurerm_private_endpoint.blob_endpoint]
356376
}
357377
358378
output "privatelink_endpoint_id" {
@@ -375,7 +395,9 @@ output "privatelink_endpoint_id" {
375395

376396
* AWS provider with CONFLUENT vendor.
377397

378-
* AZURE provider with EVENTHUB, CONFLUENT, or AZURE_BLOB_STORAGE vendor. For AZURE_BLOB_STORAGE, this should follow the format `{storageAccount}.blob.core.windows.net`.
398+
* AZURE provider with EVENTHUB or CONFLUENT vendor.
399+
400+
* AZURE provider with AZURE_BLOB_STORAGE vendor. This should follow the format `{storageAccount}.blob.core.windows.net`.
379401

380402
* For GCP provider with PUBSUB vendor, the API computes this process.
381403
- `dns_sub_domain` (List of String) Sub-Domain name of Confluent cluster. These are typically your availability zones. Required for AWS Provider and CONFLUENT vendor. If your AWS CONFLUENT cluster doesn't use subdomains, you must set this to the empty array [].

docs/data-sources/stream_privatelink_endpoints.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,7 +342,27 @@ output "dns_domain" {
342342
```
343343

344344
### Azure Blob Storage Privatelink
345+
346+
~> **NOTE:** An Azure cluster must be provisioned in the same region before creating an Azure Blob Storage private endpoint.
347+
345348
```terraform
349+
resource "mongodbatlas_advanced_cluster" "cluster" {
350+
project_id = var.project_id
351+
name = var.cluster_name
352+
cluster_type = "REPLICASET"
353+
replication_specs = [{
354+
region_configs = [{
355+
priority = 7
356+
provider_name = "AZURE"
357+
region_name = "US_EAST_2"
358+
electable_specs = {
359+
instance_size = "M10"
360+
node_count = 3
361+
}
362+
}]
363+
}]
364+
}
365+
346366
resource "mongodbatlas_stream_privatelink_endpoint" "this" {
347367
project_id = var.project_id
348368
vendor = "AZURE_BLOB_STORAGE"
@@ -352,7 +372,7 @@ resource "mongodbatlas_stream_privatelink_endpoint" "this" {
352372
dns_domain = "${var.storage_account_name}.blob.core.windows.net"
353373
# service_endpoint_id follows the format `/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Storage/storageAccounts/{storageAccount}`
354374
service_endpoint_id = "/subscriptions/${data.azurerm_client_config.current.subscription_id}/resourceGroups/${var.azure_resource_group}/providers/Microsoft.Storage/storageAccounts/${var.storage_account_name}"
355-
depends_on = [azurerm_private_endpoint.blob_endpoint]
375+
depends_on = [mongodbatlas_advanced_cluster.cluster, azurerm_private_endpoint.blob_endpoint]
356376
}
357377
358378
output "privatelink_endpoint_id" {
@@ -381,7 +401,9 @@ Read-Only:
381401

382402
* AWS provider with CONFLUENT vendor.
383403

384-
* AZURE provider with EVENTHUB, CONFLUENT, or AZURE_BLOB_STORAGE vendor. For AZURE_BLOB_STORAGE, this should follow the format `{storageAccount}.blob.core.windows.net`.
404+
* AZURE provider with EVENTHUB or CONFLUENT vendor.
405+
406+
* AZURE provider with AZURE_BLOB_STORAGE vendor. This should follow the format `{storageAccount}.blob.core.windows.net`.
385407

386408
* For GCP provider with PUBSUB vendor, the API computes this process.
387409
- `dns_sub_domain` (List of String) Sub-Domain name of Confluent cluster. These are typically your availability zones. Required for AWS Provider and CONFLUENT vendor. If your AWS CONFLUENT cluster doesn't use subdomains, you must set this to the empty array [].

docs/resources/stream_connection.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,30 @@ resource "mongodbatlas_stream_connection" "example_gcp_pubsub_psc" {
210210
}
211211
```
212212

213+
### Example Azure Blob Storage Connection with Private Link
214+
215+
~> **NOTE:** An Azure cluster must be provisioned in the same region before creating an Azure Blob Storage private endpoint.
216+
217+
```terraform
218+
resource "mongodbatlas_stream_connection" "example_azure_blob_private_link" {
219+
project_id = var.project_id
220+
workspace_name = mongodbatlas_stream_workspace.example.workspace_name
221+
connection_name = "AzureBlobStoragePLConnection"
222+
type = "AzureBlobStorage"
223+
azure = {
224+
service_principal_id = "<AZURE_SERVICE_PRINCIPAL_ID>"
225+
storage_account_name = "<AZURE_STORAGE_ACCOUNT_NAME>"
226+
region = "<AZURE_REGION>"
227+
}
228+
networking = {
229+
access = {
230+
type = "PRIVATE_LINK"
231+
connection_id = mongodbatlas_stream_privatelink_endpoint.azure_blob.id
232+
}
233+
}
234+
}
235+
```
236+
213237
### Example Https Connection
214238

215239
```terraform

docs/resources/stream_privatelink_endpoint.md

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -345,17 +345,37 @@ output "dns_domain" {
345345
```
346346

347347
### Azure Blob Storage Privatelink
348+
349+
~> **NOTE:** An Azure cluster must be provisioned in the same region before creating an Azure Blob Storage private endpoint.
350+
348351
```terraform
352+
resource "mongodbatlas_advanced_cluster" "cluster" {
353+
project_id = var.project_id
354+
name = var.cluster_name
355+
cluster_type = "REPLICASET"
356+
replication_specs = [{
357+
region_configs = [{
358+
priority = 7
359+
provider_name = "AZURE"
360+
region_name = "US_EAST_2"
361+
electable_specs = {
362+
instance_size = "M10"
363+
node_count = 3
364+
}
365+
}]
366+
}]
367+
}
368+
349369
resource "mongodbatlas_stream_privatelink_endpoint" "this" {
350370
project_id = var.project_id
351371
vendor = "AZURE_BLOB_STORAGE"
352372
provider_name = "AZURE"
353373
region = var.atlas_region
354-
# dns_domain follows the format `{storageAccount}.blob.core.windows.net`
374+
# dns_domain follows the format '{storageAccount}.blob.core.windows.net'
355375
dns_domain = "${var.storage_account_name}.blob.core.windows.net"
356-
# service_endpoint_id follows the format `/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Storage/storageAccounts/{storageAccount}`
376+
# service_endpoint_id follows the format '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Storage/storageAccounts/{storageAccount}'
357377
service_endpoint_id = "/subscriptions/${data.azurerm_client_config.current.subscription_id}/resourceGroups/${var.azure_resource_group}/providers/Microsoft.Storage/storageAccounts/${var.storage_account_name}"
358-
depends_on = [azurerm_private_endpoint.blob_endpoint]
378+
depends_on = [mongodbatlas_advanced_cluster.cluster, azurerm_private_endpoint.blob_endpoint]
359379
}
360380
361381
output "privatelink_endpoint_id" {
@@ -371,7 +391,7 @@ output "privatelink_endpoint_id" {
371391
- [GCP Confluent PrivateLink](https://github.com/mongodb/terraform-provider-mongodbatlas/tree/v2.11.0/examples/mongodbatlas_stream_privatelink_endpoint/gcp_confluent)
372392
- [GCP Pub/Sub Private Service Connect](https://github.com/mongodb/terraform-provider-mongodbatlas/tree/v2.11.0/examples/mongodbatlas_stream_privatelink_endpoint/gcp_pubsub)
373393
- [Azure PrivateLink](https://github.com/mongodb/terraform-provider-mongodbatlas/tree/v2.11.0/examples/mongodbatlas_stream_privatelink_endpoint/azure)
374-
- [Azure Blob Storage PrivateLink](https://github.com/mongodb/terraform-provider-mongodbatlas/tree/v2.10.0/examples/mongodbatlas_stream_privatelink_endpoint/azure_blob_storage)
394+
- [Azure Blob Storage PrivateLink](https://github.com/mongodb/terraform-provider-mongodbatlas/tree/v2.11.0/examples/mongodbatlas_stream_privatelink_endpoint/azure_blob_storage)
375395

376396
<!-- schema generated by tfplugindocs -->
377397
## Schema
@@ -395,7 +415,9 @@ output "privatelink_endpoint_id" {
395415

396416
* AWS provider with CONFLUENT vendor.
397417

398-
* AZURE provider with EVENTHUB, CONFLUENT, or AZURE_BLOB_STORAGE vendor. For AZURE_BLOB_STORAGE, this should follow the format `{storageAccount}.blob.core.windows.net`.
418+
* AZURE provider with EVENTHUB or CONFLUENT vendor.
419+
420+
* AZURE provider with AZURE_BLOB_STORAGE vendor. This should follow the format `{storageAccount}.blob.core.windows.net`.
399421

400422
* For GCP provider with PUBSUB vendor, the API computes this process.
401423
- `dns_sub_domain` (List of String) Sub-Domain name of Confluent cluster. These are typically your availability zones. Required for AWS Provider and CONFLUENT vendor. If your AWS CONFLUENT cluster doesn't use subdomains, you must set this to the empty array [].

examples/mongodbatlas_stream_privatelink_endpoint/azure_blob_storage/main.tf

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,20 @@
1+
resource "mongodbatlas_advanced_cluster" "cluster" {
2+
project_id = var.project_id
3+
name = var.cluster_name
4+
cluster_type = "REPLICASET"
5+
replication_specs = [{
6+
region_configs = [{
7+
priority = 7
8+
provider_name = "AZURE"
9+
region_name = "US_EAST_2"
10+
electable_specs = {
11+
instance_size = "M10"
12+
node_count = 3
13+
}
14+
}]
15+
}]
16+
}
17+
118
resource "mongodbatlas_stream_privatelink_endpoint" "this" {
219
project_id = var.project_id
320
vendor = "AZURE_BLOB_STORAGE"
@@ -7,7 +24,7 @@ resource "mongodbatlas_stream_privatelink_endpoint" "this" {
724
dns_domain = "${var.storage_account_name}.blob.core.windows.net"
825
# service_endpoint_id follows the format `/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.Storage/storageAccounts/{storageAccount}`
926
service_endpoint_id = "/subscriptions/${data.azurerm_client_config.current.subscription_id}/resourceGroups/${var.azure_resource_group}/providers/Microsoft.Storage/storageAccounts/${var.storage_account_name}"
10-
depends_on = [azurerm_private_endpoint.blob_endpoint]
27+
depends_on = [mongodbatlas_advanced_cluster.cluster, azurerm_private_endpoint.blob_endpoint]
1128
}
1229

1330
output "privatelink_endpoint_id" {

examples/mongodbatlas_stream_privatelink_endpoint/azure_blob_storage/variables.tf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,11 @@ variable "project_id" {
4040
type = string
4141
}
4242

43+
variable "cluster_name" {
44+
description = "Name of the Azure cluster required for private link provisioning."
45+
type = string
46+
}
47+
4348
variable "atlas_region" {
4449
description = "The Atlas region of the Provider's cluster. See [AZURE](https://www.mongodb.com/docs/atlas/reference/microsoft-azure/#stream-processing-instances)"
4550
type = string

internal/service/streamconnection/resource_stream_connection_test.go

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1329,6 +1329,7 @@ func TestAccStreamRSStreamConnection_AzureBlobStorage(t *testing.T) {
13291329
func TestAccStreamRSStreamConnection_AzureBlobStoragePrivateLink(t *testing.T) {
13301330
var (
13311331
projectID, instanceName = acc.ProjectIDExecutionWithStreamInstance(t)
1332+
clusterName = acc.RandomClusterName()
13321333
connectionName = acc.RandomName()
13331334
clientID = os.Getenv("AZURE_CLIENT_ID")
13341335
clientSecret = os.Getenv("AZURE_APP_SECRET")
@@ -1347,7 +1348,7 @@ func TestAccStreamRSStreamConnection_AzureBlobStoragePrivateLink(t *testing.T) {
13471348
CheckDestroy: CheckDestroyStreamConnection,
13481349
Steps: []resource.TestStep{
13491350
{
1350-
Config: dataSourceConfig + configureAzureBlobStoragePrivateLink(projectID, instanceName, connectionName, clientID, clientSecret, subscriptionID, tenantID, atlasAzureAppID, servicePrincipalID, resourceGroupName, storageAccountName, storageContainerName),
1351+
Config: dataSourceConfig + configureAzureBlobStoragePrivateLink(projectID, instanceName, clusterName, connectionName, clientID, clientSecret, subscriptionID, tenantID, atlasAzureAppID, servicePrincipalID, resourceGroupName, storageAccountName, storageContainerName),
13511352
Check: resource.ComposeAggregateTestCheckFunc(
13521353
checkAzureBlobStoragePrivateLinkAttributes(resourceName, instanceName, connectionName, servicePrincipalID, storageAccountName),
13531354
checkAzureBlobStoragePrivateLinkAttributes(dataSourceName, instanceName, connectionName, servicePrincipalID, storageAccountName),
@@ -1412,22 +1413,40 @@ func checkAzureBlobStorageAttributes(resourceNames ...string) resource.TestCheck
14121413
return resource.ComposeAggregateTestCheckFunc(checks...)
14131414
}
14141415

1415-
func configureAzureBlobStoragePrivateLink(projectID, workspaceName, connectionName, clientID, clientSecret, subscriptionID, tenantID, atlasAzureAppID, servicePrincipalID, resourceGroupName, storageAccountName, storageContainerName string) string {
1416+
func configureAzureBlobStoragePrivateLink(projectID, workspaceName, clusterName, connectionName, clientID, clientSecret, subscriptionID, tenantID, atlasAzureAppID, servicePrincipalID, resourceGroupName, storageAccountName, storageContainerName string) string {
14161417
return acc.ConfigAzurermProvider(subscriptionID, clientID, clientSecret, tenantID) +
14171418
acc.ConfigAzureCloudProviderAccess(projectID, atlasAzureAppID, servicePrincipalID, tenantID) +
14181419
acc.ConfigAzureStorageResources("blob", resourceGroupName, storageAccountName, storageContainerName, servicePrincipalID) +
1419-
configAzureBlobStoragePrivateLinkResources(projectID, workspaceName, connectionName)
1420+
configAzureBlobStoragePrivateLinkResources(projectID, workspaceName, clusterName, connectionName)
14201421
}
14211422

1422-
func configAzureBlobStoragePrivateLinkResources(projectID, workspaceName, connectionName string) string {
1423+
func configAzureBlobStoragePrivateLinkResources(projectID, workspaceName, clusterName, connectionName string) string {
14231424
return fmt.Sprintf(`
1425+
resource "mongodbatlas_advanced_cluster" "test" {
1426+
project_id = %[1]q
1427+
name = %[4]q
1428+
cluster_type = "REPLICASET"
1429+
replication_specs = [{
1430+
region_configs = [{
1431+
priority = 7
1432+
provider_name = "AZURE"
1433+
region_name = "US_EAST_2"
1434+
electable_specs = {
1435+
instance_size = "M10"
1436+
node_count = 3
1437+
}
1438+
}]
1439+
}]
1440+
}
1441+
14241442
resource "mongodbatlas_stream_privatelink_endpoint" "test" {
14251443
project_id = %[1]q
14261444
provider_name = "AZURE"
14271445
vendor = "AZURE_BLOB_STORAGE"
14281446
region = azurerm_resource_group.blob_rg.location
14291447
service_endpoint_id = azurerm_storage_account.blob_storage.id
14301448
dns_domain = "${azurerm_storage_account.blob_storage.name}.blob.core.windows.net"
1449+
depends_on = [mongodbatlas_advanced_cluster.test]
14311450
}
14321451
14331452
resource "mongodbatlas_stream_connection" "test" {
@@ -1451,7 +1470,7 @@ func configAzureBlobStoragePrivateLinkResources(projectID, workspaceName, connec
14511470
azurerm_role_assignment.blob_contributor,
14521471
]
14531472
}
1454-
`, projectID, workspaceName, connectionName)
1473+
`, projectID, workspaceName, connectionName, clusterName)
14551474
}
14561475

14571476
func checkAzureBlobStoragePrivateLinkAttributes(resourceName, workspaceName, connectionName, servicePrincipalID, storageAccountName string) resource.TestCheckFunc {

internal/service/streamprivatelinkendpoint/resource_schema.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ func ResourceSchema(ctx context.Context) schema.Schema {
2323
2424
* AWS provider with CONFLUENT vendor.
2525
26-
* AZURE provider with EVENTHUB, CONFLUENT, or AZURE_BLOB_STORAGE vendor. For AZURE_BLOB_STORAGE, this should follow the format '{storageAccount}.blob.core.windows.net'.
26+
* AZURE provider with EVENTHUB or CONFLUENT vendor.
27+
28+
* AZURE provider with AZURE_BLOB_STORAGE vendor. This should follow the format ` + "`{storageAccount}.blob.core.windows.net`" + `.
2729
2830
* For GCP provider with PUBSUB vendor, the API computes this process.`,
2931
},

internal/service/streamprivatelinkendpoint/resource_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,6 +486,7 @@ func basicAzureBlobStorageTestCase(t *testing.T) *resource.TestCase {
486486

487487
var (
488488
projectID = acc.ProjectIDExecution(t)
489+
clusterName = acc.RandomClusterName()
489490
provider = "AZURE"
490491
vendor = "AZURE_BLOB_STORAGE"
491492
subscriptionID = os.Getenv("AZURE_SUBSCRIPTION_ID")
@@ -503,7 +504,7 @@ func basicAzureBlobStorageTestCase(t *testing.T) *resource.TestCase {
503504
ProtoV6ProviderFactories: acc.TestAccProviderV6Factories,
504505
Steps: []resource.TestStep{
505506
{
506-
Config: acc.GetCompleteAzureBlobStorageConfig(projectID, subscriptionID, clientID, clientSecret, tenantID, resourceGroupName, storageAccountName),
507+
Config: acc.GetCompleteAzureBlobStorageConfig(projectID, clusterName, subscriptionID, clientID, clientSecret, tenantID, resourceGroupName, storageAccountName),
507508
Check: checksStreamPrivatelinkEndpointAzureBlobStorage(projectID, provider, vendor),
508509
},
509510
{

internal/testutil/acc/stream_privatelink_endpoint.go

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,10 +157,27 @@ func GetCompleteMskConfig(projectID, clusterArn string) string {
157157
}`, projectID, clusterArn)
158158
}
159159

160-
func GetCompleteAzureBlobStorageConfig(projectID, subscriptionID, clientID, clientSecret, tenantID, resourceGroupName, storageAccountName string) string {
160+
func GetCompleteAzureBlobStorageConfig(projectID, clusterName, subscriptionID, clientID, clientSecret, tenantID, resourceGroupName, storageAccountName string) string {
161161
return fmt.Sprintf(`
162162
%[1]s
163163
164+
resource "mongodbatlas_advanced_cluster" "test" {
165+
project_id = %[2]q
166+
name = %[5]q
167+
cluster_type = "REPLICASET"
168+
replication_specs = [{
169+
region_configs = [{
170+
priority = 7
171+
provider_name = "AZURE"
172+
region_name = "US_EAST_2"
173+
electable_specs = {
174+
instance_size = "M10"
175+
node_count = 3
176+
}
177+
}]
178+
}]
179+
}
180+
164181
resource "azurerm_resource_group" "blob_pl_rg" {
165182
name = %[3]q
166183
location = "East US 2"
@@ -181,6 +198,7 @@ func GetCompleteAzureBlobStorageConfig(projectID, subscriptionID, clientID, clie
181198
region = "eastus2"
182199
service_endpoint_id = azurerm_storage_account.blob_pl_storage.id
183200
dns_domain = "${azurerm_storage_account.blob_pl_storage.name}.blob.core.windows.net"
201+
depends_on = [mongodbatlas_advanced_cluster.test]
184202
}
185203
186204
data "mongodbatlas_stream_privatelink_endpoint" "test" {
@@ -194,7 +212,7 @@ func GetCompleteAzureBlobStorageConfig(projectID, subscriptionID, clientID, clie
194212
mongodbatlas_stream_privatelink_endpoint.test
195213
]
196214
}`, ConfigAzurermProvider(subscriptionID, clientID, clientSecret, tenantID),
197-
projectID, resourceGroupName, storageAccountName)
215+
projectID, resourceGroupName, storageAccountName, clusterName)
198216
}
199217

200218
func GetCompleteS3Config(projectID, region string) string {

0 commit comments

Comments
 (0)