From 54b15a5f4dc6ac54713cf1481ae37c093e8c2114 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micka=C3=ABl=20Mottet?= Date: Sat, 12 Dec 2020 11:27:37 +0100 Subject: [PATCH] Add cosmosdb-private-endpoint example --- .../101/cosmosdb-private-endpoint/main.bicep | 75 +++++++++++++ .../101/cosmosdb-private-endpoint/main.json | 106 ++++++++++++++++++ docs/examples/index.json | 4 + 3 files changed, 185 insertions(+) create mode 100644 docs/examples/101/cosmosdb-private-endpoint/main.bicep create mode 100644 docs/examples/101/cosmosdb-private-endpoint/main.json diff --git a/docs/examples/101/cosmosdb-private-endpoint/main.bicep b/docs/examples/101/cosmosdb-private-endpoint/main.bicep new file mode 100644 index 00000000000..4f66aa596ee --- /dev/null +++ b/docs/examples/101/cosmosdb-private-endpoint/main.bicep @@ -0,0 +1,75 @@ +param location string = resourceGroup().location +param virtualNetworkName string = 'Vnet' +param accountName string +param publicNetworkAccess string { + default: 'Enabled' + allowed: [ + 'Enabled' + 'Disabled' + ] +} +param privateEndpointName string + +resource virtualNetwork 'Microsoft.Network/virtualNetworks@2020-06-01' = { + name: virtualNetworkName + location: location + properties: { + addressSpace: { + addressPrefixes: [ + '172.20.0.0/16' + ] + } + } +} + +resource subNet 'Microsoft.Network/virtualNetworks/subnets@2020-06-01' = { + name: '${virtualNetwork.name}/default' + properties: { + addressPrefix: '172.20.0.0/24' + privateEndpointNetworkPolicies: 'Disabled' + } +} + +resource databaseAccount 'Microsoft.DocumentDB/databaseAccounts@2020-06-01-preview' = { + name: accountName + location: location + kind: 'GlobalDocumentDB' + properties: { + createMode: 'Default' + consistencyPolicy: { + defaultConsistencyLevel: 'Session' + } + locations: [ + { + locationName: location + failoverPriority: 0 + isZoneRedundant: false + } + ] + databaseAccountOfferType: 'Standard' + enableAutomaticFailover: false + enableMultipleWriteLocations: false + publicNetworkAccess: publicNetworkAccess + } +} + +resource privateEndpoint 'Microsoft.Network/privateEndpoints@2020-06-01' = { + name: privateEndpointName + location: location + properties: { + subnet: { + id: subNet.id + } + privateLinkServiceConnections: [ + { + name: 'MyConnection' + properties: { + privateLinkServiceId: databaseAccount.id + groupIds: [ + 'Sql' + ] + } + } + ] + } +} diff --git a/docs/examples/101/cosmosdb-private-endpoint/main.json b/docs/examples/101/cosmosdb-private-endpoint/main.json new file mode 100644 index 00000000000..405f5d82de6 --- /dev/null +++ b/docs/examples/101/cosmosdb-private-endpoint/main.json @@ -0,0 +1,106 @@ +{ + "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", + "contentVersion": "1.0.0.0", + "parameters": { + "location": { + "type": "string", + "defaultValue": "[resourceGroup().location]" + }, + "virtualNetworkName": { + "type": "string", + "defaultValue": "Vnet" + }, + "accountName": { + "type": "string" + }, + "publicNetworkAccess": { + "type": "string", + "defaultValue": "Enabled", + "allowedValues": [ + "Enabled", + "Disabled" + ] + }, + "privateEndpointName": { + "type": "string" + } + }, + "functions": [], + "resources": [ + { + "type": "Microsoft.Network/virtualNetworks", + "apiVersion": "2020-06-01", + "name": "[parameters('virtualNetworkName')]", + "location": "[parameters('location')]", + "properties": { + "addressSpace": { + "addressPrefixes": [ + "172.20.0.0/16" + ] + } + } + }, + { + "type": "Microsoft.Network/virtualNetworks/subnets", + "apiVersion": "2020-06-01", + "name": "[format('{0}/default', parameters('virtualNetworkName'))]", + "properties": { + "addressPrefix": "172.20.0.0/24", + "privateEndpointNetworkPolicies": "Disabled" + }, + "dependsOn": [ + "[resourceId('Microsoft.Network/virtualNetworks', parameters('virtualNetworkName'))]" + ] + }, + { + "type": "Microsoft.DocumentDB/databaseAccounts", + "apiVersion": "2020-06-01-preview", + "name": "[parameters('accountName')]", + "location": "[parameters('location')]", + "kind": "GlobalDocumentDB", + "properties": { + "createMode": "Default", + "consistencyPolicy": { + "defaultConsistencyLevel": "Session" + }, + "locations": [ + { + "locationName": "[parameters('location')]", + "failoverPriority": 0, + "isZoneRedundant": false + } + ], + "databaseAccountOfferType": "Standard", + "enableAutomaticFailover": false, + "enableMultipleWriteLocations": false, + "publicNetworkAccess": "[parameters('publicNetworkAccess')]" + } + }, + { + "type": "Microsoft.Network/privateEndpoints", + "apiVersion": "2020-06-01", + "name": "[parameters('privateEndpointName')]", + "location": "[parameters('location')]", + "properties": { + "subnet": { + "id": "[resourceId('Microsoft.Network/virtualNetworks/subnets', split(format('{0}/default', parameters('virtualNetworkName')), '/')[0], split(format('{0}/default', parameters('virtualNetworkName')), '/')[1])]" + }, + "privateLinkServiceConnections": [ + { + "name": "MyConnection", + "properties": { + "privateLinkServiceId": "[resourceId('Microsoft.DocumentDB/databaseAccounts', parameters('accountName'))]", + "groupIds": [ + "Sql" + ] + } + } + ] + }, + "dependsOn": [ + "[resourceId('Microsoft.DocumentDB/databaseAccounts', parameters('accountName'))]", + "[resourceId('Microsoft.Network/virtualNetworks/subnets', split(format('{0}/default', parameters('virtualNetworkName')), '/')[0], split(format('{0}/default', parameters('virtualNetworkName')), '/')[1])]" + ] + } + ] +} \ No newline at end of file diff --git a/docs/examples/index.json b/docs/examples/index.json index 98091bd852c..1850d594767 100644 --- a/docs/examples/index.json +++ b/docs/examples/index.json @@ -51,6 +51,10 @@ "filePath": "101/cosmosdb-free/main.bicep", "description": "101/cosmosdb-free" }, + { + "filePath": "101/cosmosdb-private-endpoint/main.bicep", + "description": "101/cosmosdb-private-endpoint" + }, { "filePath": "101/cosmosdb-webapp/main.bicep", "description": "101/cosmosdb-webapp"