|
| 1 | +--- |
| 2 | +title: 'Quickstart: Create a private endpoint using Bicep' |
| 3 | +description: In this quickstart, you'll learn how to create a private endpoint using Bicep. |
| 4 | +services: private-link |
| 5 | +author: schaffererin |
| 6 | +ms.service: private-link |
| 7 | +ms.topic: quickstart |
| 8 | +ms.custom: subject-armqs, devx-track-azurepowershell, mode-arm |
| 9 | +ms.date: 05/02/2022 |
| 10 | +ms.author: v-eschaffer |
| 11 | +#Customer intent: As someone who has a basic network background but is new to Azure, I want to create a private endpoint using Bicep. |
| 12 | +--- |
| 13 | + |
| 14 | +# Quickstart: Create a private endpoint using Bicep |
| 15 | + |
| 16 | +In this quickstart, you'll use Bicep to create a private endpoint. |
| 17 | + |
| 18 | +[!INCLUDE [About Bicep](../../includes/resource-manager-quickstart-bicep-introduction.md)] |
| 19 | + |
| 20 | +You can also create a private endpoint by using the [Azure portal](create-private-endpoint-portal.md), [Azure PowerShell](create-private-endpoint-powershell.md), the [Azure CLI](create-private-endpoint-cli.md), or an [Azure Resource Manager Template](create-private-endpoint-template.md). |
| 21 | + |
| 22 | +## Prerequisites |
| 23 | + |
| 24 | +You need an Azure account with an active subscription. If you don't already have an Azure account, [create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F). |
| 25 | + |
| 26 | +## Review the Bicep file |
| 27 | + |
| 28 | +This Bicep file creates a private endpoint for an instance of Azure SQL Database. |
| 29 | + |
| 30 | +The Bicep file that this quickstart uses is from [Azure Quickstart Templates](https://azure.microsoft.com/resources/templates/private-endpoint-sql/). |
| 31 | + |
| 32 | +:::code language="bicep" source="~/quickstart-templates/quickstarts/microsoft.sql/private-endpoint-sql/azuredeploy.json"::: |
| 33 | + |
| 34 | +The Bicep file defines multiple Azure resources: |
| 35 | + |
| 36 | +- [**Microsoft.Sql/servers**](/azure/templates/microsoft.sql/servers): The instance of SQL Database with the sample database. |
| 37 | +- [**Microsoft.Sql/servers/databases**](/azure/templates/microsoft.sql/servers/databases): The sample database. |
| 38 | +- [**Microsoft.Network/virtualNetworks**](/azure/templates/microsoft.network/virtualnetworks): The virtual network where the private endpoint is deployed. |
| 39 | +- [**Microsoft.Network/privateEndpoints**](/azure/templates/microsoft.network/privateendpoints): The private endpoint that you use to access the instance of SQL Database. |
| 40 | +- [**Microsoft.Network/privateDnsZones**](/azure/templates/microsoft.network/privatednszones): The zone that you use to resolve the private endpoint IP address. |
| 41 | +- [**Microsoft.Network/privateDnsZones/virtualNetworkLinks**](/azure/templates/microsoft.network/privatednszones/virtualnetworklinks) |
| 42 | +- [**Microsoft.Network/privateEndpoints/privateDnsZoneGroups**](/azure/templates/microsoft.network/privateendpoints/privateDnsZoneGroups): The zone group that you use to associate the private endpoint with a private DNS zone. |
| 43 | +- [**Microsoft.Network/publicIpAddresses**](/azure/templates/microsoft.network/publicIpAddresses): The public IP address that you use to access the virtual machine. |
| 44 | +- [**Microsoft.Network/networkInterfaces**](/azure/templates/microsoft.network/networkinterfaces): The network interface for the virtual machine. |
| 45 | +- [**Microsoft.Compute/virtualMachines**](/azure/templates/microsoft.compute/virtualmachines): The virtual machine that you use to test the connection of the private endpoint to the instance of SQL Database. |
| 46 | + |
| 47 | +## Deploy the Bicep file |
| 48 | + |
| 49 | +1. Save the Bicep file as **main.bicep** to your local computer. |
| 50 | +1. Deploy the Bicep file using either Azure CLI or Azure PowerShell. |
| 51 | + |
| 52 | + # [CLI](#tab/CLI) |
| 53 | + |
| 54 | + ```azurecli |
| 55 | + az group create --name exampleRG --location eastus |
| 56 | + az deployment group create --resource-group exampleRG --template-file main.bicep --parameters sqlAdministratorLogin=<admin-login> vmAdminUsername=<vm-login> |
| 57 | + ``` |
| 58 | +
|
| 59 | + # [PowerShell](#tab/PowerShell) |
| 60 | +
|
| 61 | + ```azurepowershell |
| 62 | + New-AzResourceGroup -Name exampleRG -Location eastus |
| 63 | + New-AzResourceGroupDeployment -ResourceGroupName exampleRG -TemplateFile ./main.bicep -sqlAdministratorLogin "<admin-login>" -vmAdminUsername "<vm-login>" |
| 64 | + ``` |
| 65 | +
|
| 66 | + --- |
| 67 | +
|
| 68 | + > [!NOTE] |
| 69 | + > Replace **\<admin-login\>** with the username for the SQL logical server. Replace **\<vm-login\>** with the username for the virtual machine. You'll be prompted to enter **sqlAdministratorLoginPassword**. You'll also be prompted to enter **vmAdminPassword**, which must be at least 12 characters long and contain at least one lowercase and uppercase character and one special character. |
| 70 | +
|
| 71 | + When the deployment finishes, you should see a message indicating the deployment succeeded. |
| 72 | +
|
| 73 | +## Validate the deployment |
| 74 | +
|
| 75 | +> [!NOTE] |
| 76 | +> The Bicep file generates a unique name for the virtual machine myVm<b>{uniqueid}</b> resource, and for the SQL Database sqlserver<b>{uniqueid}</b> resource. Substitute your generated value for **{uniqueid}**. |
| 77 | +
|
| 78 | +### Connect to a VM from the internet |
| 79 | +
|
| 80 | +Connect to the VM _myVm{uniqueid}_ from the internet by doing the following: |
| 81 | +
|
| 82 | +1. In the Azure portal search bar, enter _myVm{uniqueid}_. |
| 83 | +
|
| 84 | +1. Select **Connect**. **Connect to virtual machine** opens. |
| 85 | +
|
| 86 | +1. Select **Download RDP File**. Azure creates a Remote Desktop Protocol (RDP) file and downloads it to your computer. |
| 87 | +
|
| 88 | +1. Open the downloaded RDP file. |
| 89 | +
|
| 90 | + a. If you're prompted, select **Connect**. |
| 91 | + b. Enter the username and password that you specified when you created the VM. |
| 92 | +
|
| 93 | + > [!NOTE] |
| 94 | + > You might need to select **More choices** > **Use a different account** to specify the credentials you entered when you created the VM. |
| 95 | +
|
| 96 | +1. Select **OK**. |
| 97 | +
|
| 98 | + You might receive a certificate warning during the sign-in process. If you do, select **Yes** or **Continue**. |
| 99 | +
|
| 100 | +1. After the VM desktop appears, minimize it to go back to your local desktop. |
| 101 | +
|
| 102 | +### Access the SQL Database server privately from the VM |
| 103 | +
|
| 104 | +To connect to the SQL Database server from the VM by using the private endpoint, do the following: |
| 105 | +
|
| 106 | +1. On the Remote Desktop of _myVM{uniqueid}_, open PowerShell. |
| 107 | +1. Run the following command: |
| 108 | +
|
| 109 | + `nslookup sqlserver{uniqueid}.database.windows.net` |
| 110 | +
|
| 111 | + You'll receive a message that's similar to this one: |
| 112 | +
|
| 113 | + ``` |
| 114 | + Server: UnKnown |
| 115 | + Address: 168.63.129.16 |
| 116 | + Non-authoritative answer: |
| 117 | + Name: sqlserver.privatelink.database.windows.net |
| 118 | + Address: 10.0.0.5 |
| 119 | + Aliases: sqlserver.database.windows.net |
| 120 | + ``` |
| 121 | +
|
| 122 | +1. Install SQL Server Management Studio. |
| 123 | +
|
| 124 | +1. On the **Connect to server** pane, do the following: |
| 125 | + - For **Server type**, select **Database Engine**. |
| 126 | + - For **Server name**, select **sqlserver{uniqueid}.database.windows.net**. |
| 127 | + - For **Username**, enter the username that was provided earlier. |
| 128 | + - For **Password**, enter the password that was provided earlier. |
| 129 | + - For **Remember password**, select **Yes**. |
| 130 | +
|
| 131 | +1. Select **Connect**. |
| 132 | +1. On the left pane, select **Databases**. Optionally, you can create or query information from _sample-db_. |
| 133 | +1. Close the Remote Desktop connection to _myVm{uniqueid}_. |
| 134 | +
|
| 135 | +## Clean up resources |
| 136 | +
|
| 137 | +When you no longer need the resources that you created with the private link service, delete the resource group. This removes the private link service and all the related resources. |
| 138 | +
|
| 139 | +# [CLI](#tab/CLI) |
| 140 | +
|
| 141 | +```azurecli-interactive |
| 142 | +az group delete --name exampleRG |
| 143 | +``` |
| 144 | + |
| 145 | +# [PowerShell](#tab/PowerShell) |
| 146 | + |
| 147 | +```azurepowershell-interactive |
| 148 | +Remove-AzResourceGroup -Name exampleRG |
| 149 | +``` |
| 150 | + |
| 151 | +--- |
| 152 | + |
| 153 | +## Next steps |
| 154 | + |
| 155 | +For more information about the services that support private endpoints, see: |
| 156 | + |
| 157 | +> [!div class="nextstepaction"] |
| 158 | +> [What is Azure Private Link?](private-link-overview.md#availability) |
0 commit comments