Skip to content

Commit ed78350

Browse files
authored
Merge pull request #80454 from itechedit/resource-manager-tutorial-use-key-vault
edit pass: resource-manager-tutorial-use-key-vault
2 parents edac0ed + 82958da commit ed78350

File tree

1 file changed

+53
-49
lines changed

1 file changed

+53
-49
lines changed
Lines changed: 53 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
---
1+
---
22
title: Integrate Azure Key Vault in Resource Manager template deployment | Microsoft Docs
33
description: Learn how to use Azure Key Vault to pass secure parameter values during Resource Manager template deployment
44
services: azure-resource-manager
@@ -17,19 +17,19 @@ ms.author: jgao
1717
ms.custom: seodec18
1818
---
1919

20-
# Tutorial: Integrate Azure Key Vault in Resource Manager Template deployment
20+
# Tutorial: Integrate Azure Key Vault in your Resource Manager template deployment
2121

22-
Learn how to retrieve secrets from Azure Key Vault and pass the secrets as parameters during Resource Manager deployment. The value is never exposed because you only reference its key vault ID. For more information, see [Use Azure Key Vault to pass secure parameter value during deployment](./resource-manager-keyvault-parameter.md)
22+
Learn how to retrieve secrets from an Azure key vault and pass the secrets as parameters when you deploy Azure Resource Manager. The parameter value is never exposed, because you reference only its key vault ID. For more information, see [Use Azure Key Vault to pass secure parameter value during deployment](./resource-manager-keyvault-parameter.md).
2323

24-
In the [Set resource deployment order](./resource-manager-tutorial-create-templates-with-dependent-resources.md) tutorial, you create a virtual machine. You need to provide the virtual machine administrator username and password. Instead of providing the password, you can pre-store the password in an Azure Key Vault and then customize the template to retrieve the password from the key vault during the deployment.
24+
In the [Set resource deployment order](./resource-manager-tutorial-create-templates-with-dependent-resources.md) tutorial, you create a virtual machine (VM). You need to provide the VM administrator username and password. Instead of providing the password, you can pre-store the password in an Azure key vault and then customize the template to retrieve the password from the key vault during the deployment.
2525

26-
![Resource Manager template Key Vault integration diagram](./media/resource-manager-tutorial-use-key-vault/resource-manager-template-key-vault-diagram.png)
26+
![Diagram displaying the integration of a Resource Manager template with a key vault](./media/resource-manager-tutorial-use-key-vault/resource-manager-template-key-vault-diagram.png)
2727

2828
This tutorial covers the following tasks:
2929

3030
> [!div class="checklist"]
3131
> * Prepare a key vault
32-
> * Open a QuickStart template
32+
> * Open a quickstart template
3333
> * Edit the parameters file
3434
> * Deploy the template
3535
> * Validate the deployment
@@ -43,25 +43,25 @@ If you don't have an Azure subscription, [create a free account](https://azure.m
4343

4444
To complete this article, you need:
4545

46-
* [Visual Studio Code](https://code.visualstudio.com/) with [Resource Manager Tools extension](./resource-manager-quickstart-create-templates-use-visual-studio-code.md#prerequisites).
47-
* To increase security, use a generated password for the virtual machine administrator account. Here is a sample for generating a password:
46+
* [Visual Studio Code](https://code.visualstudio.com/) with the [Resource Manager Tools extension](./resource-manager-quickstart-create-templates-use-visual-studio-code.md#prerequisites).
47+
* To increase security, use a generated password for the VM administrator account. Here's a sample for generating a password:
4848

4949
```azurecli-interactive
5050
openssl rand -base64 32
5151
```
52-
Verify the generated password meets the virtual machine password requirements. Each Azure service has specific password requirements. For the VM password requirements, see [What are the password requirements when creating a VM?](../virtual-machines/windows/faq.md#what-are-the-password-requirements-when-creating-a-vm).
52+
Verify that the generated password meets the VM password requirements. Each Azure service has specific password requirements. For the VM password requirements, see [What are the password requirements when you create a VM?](../virtual-machines/windows/faq.md#what-are-the-password-requirements-when-creating-a-vm).
5353
5454
## Prepare a key vault
5555
56-
In this section, you create a key vault and add a secret to the key vault, so that you can retrieve the secret when you deploy your template. There are many ways to create a key vault. In this tutorial, you use Azure PowerShell to deploy a [Resource Manager template](https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/tutorials-use-key-vault/CreateKeyVault.json). This template does:
56+
In this section, you create a key vault and add a secret to it, so that you can retrieve the secret when you deploy your template. There are many ways to create a key vault. In this tutorial, you use Azure PowerShell to deploy a [Resource Manager template](https://raw.githubusercontent.com/Azure/azure-docs-json-samples/master/tutorials-use-key-vault/CreateKeyVault.json). This template does the following:
5757
58-
* Create a key vault with the `enabledForTemplateDeployment` property enables. This property must be true before the template deployment process can access the secrets defined in this key vault.
59-
* Add a secret to the key vault. The secret stores the virtual machine administrator password.
58+
* Creates a key vault with the `enabledForTemplateDeployment` property enabled. This property must be *true* before the template deployment process can access the secrets that are defined in the key vault.
59+
* Adds a secret to the key vault. The secret stores the VM administrator password.
6060
6161
> [!NOTE]
62-
> If you (as the user to deploy the virtual machine template) are not the owner or the contributor of the key vault, the Owner or a Contributor of the key vault must grant you the access to the Microsoft.KeyVault/vaults/deploy/action permission for the key vault. For more information, see [Use Azure Key Vault to pass secure parameter value during deployment](./resource-manager-keyvault-parameter.md)
62+
> As the user who's deploying the virtual machine template, if you're not the Owner of or a Contributor to the key vault, the Owner or a Contributor must grant you access to the *Microsoft.KeyVault/vaults/deploy/action* permission for the key vault. For more information, see [Use Azure Key Vault to pass a secure parameter value during deployment](./resource-manager-keyvault-parameter.md).
6363
64-
To run the following PowerShell script, select **Try it** to open the Cloud shell. To paste the script, right-click the shell pane, and then select **Paste**.
64+
To run the following Azure PowerShell script, select **Try it** to open Azure Cloud Shell. To paste the script, right-click the shell pane, and then select **Paste**.
6565
6666
```azurepowershell-interactive
6767
$projectName = Read-Host -Prompt "Enter a project name that is used for generating resource names"
@@ -78,51 +78,53 @@ New-AzResourceGroup -Name $resourceGroupName -Location $location
7878
New-AzResourceGroupDeployment -ResourceGroupName $resourceGroupName -TemplateUri $templateUri -keyVaultName $keyVaultName -adUserId $adUserId -secretValue $secretValue
7979
```
8080

81-
A few pieces of important information:
82-
83-
* The resource group name is the project name with **rg** appended. To make it easier to [clean up the resources created in this tutorial](#clean-up-resources), use the same project name and resource group name when you [deploy the next template](#deploy-the-template).
84-
* The default name for the secret name is **vmAdminPassword**. It is hardcoded in the template.
85-
* To be able for the template to retrieve the secret, you must enable an access policy called **Enable access to Azure Resource Manager for template deployment** for the key vault. This policy is enabled in the template. For more information about this access policy, see [Deploy key vaults and secrets](./resource-manager-keyvault-parameter.md#deploy-key-vaults-and-secrets).
81+
> [!IMPORTANT]
82+
> * The resource group name is the project name, but with **rg** appended to it. To make it easier to [clean up the resources that you created in this tutorial](#clean-up-resources), use the same project name and resource group name when you [deploy the next template](#deploy-the-template).
83+
> * The default name for the secret is **vmAdminPassword**. It's hardcoded in the template.
84+
> * To enable the template to retrieve the secret, you must enable an access policy called "Enable access to Azure Resource Manager for template deployment" for the key vault. This policy is enabled in the template. For more information about the access policy, see [Deploy key vaults and secrets](./resource-manager-keyvault-parameter.md#deploy-key-vaults-and-secrets).
8685
87-
The template has one output value called **keyVaultId**. Write down the value. You need this ID when you deploy the virtual machine. The Resource ID format is:
86+
The template has one output value, called *keyVaultId*. Write down the ID value for later use, when you deploy the virtual machine. The resource ID format is:
8887

8988
```json
9089
/subscriptions/<SubscriptionID>/resourceGroups/mykeyvaultdeploymentrg/providers/Microsoft.KeyVault/vaults/<KeyVaultName>
9190
```
9291

93-
When you copy and paste the ID, the ID might be broken into multiple lines. You must merge the lines and trim the extra spaces.
92+
When you copy and paste the ID, it might be broken into multiple lines. Merge the lines and trim the extra spaces.
9493

95-
To validate the deployment, run the following PowerShell command in the same shell pane to retrieve the secret in clear text. The command only works in the same shell session because it uses a variable $keyVaultName defined in the previous PowerShell script.
94+
To validate the deployment, run the following PowerShell command in the same shell pane to retrieve the secret in clear text. The command works only in the same shell session, because it uses the variable *$keyVaultName*, which is defined in the preceding PowerShell script.
9695

9796
```azurepowershell
9897
(Get-AzKeyVaultSecret -vaultName $keyVaultName -name "vmAdminPassword").SecretValueText
9998
```
10099

101-
Now you have prepared a key vault and a secret, the following sections show you how to customize an existing template to retrieve the secret during the deployment.
100+
Now you've prepared a key vault and a secret. The following sections show you how to customize an existing template to retrieve the secret during the deployment.
102101

103-
## Open a Quickstart template
102+
## Open a quickstart template
104103

105-
Azure QuickStart Templates is a repository for Resource Manager templates. Instead of creating a template from scratch, you can find a sample template and customize it. The template used in this tutorial is called [Deploy a simple Windows VM](https://azure.microsoft.com/resources/templates/101-vm-simple-windows/).
104+
Azure Quickstart Templates is a repository for Resource Manager templates. Instead of creating a template from scratch, you can find a sample template and customize it. The template that's used in this tutorial is called [Deploy a simple Windows VM](https://azure.microsoft.com/resources/templates/101-vm-simple-windows/).
106105

107-
1. From Visual Studio Code, select **File**>**Open File**.
108-
2. In **File name**, paste the following URL:
106+
1. In Visual Studio Code, select **File** > **Open File**.
107+
108+
1. In the **File name** box, paste the following URL:
109109

110110
```url
111111
https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-vm-simple-windows/azuredeploy.json
112112
```
113113

114-
3. Select **Open** to open the file. It is the same scenario used in [Tutorial: create Azure Resource Manager templates with dependent resources](./resource-manager-tutorial-create-templates-with-dependent-resources.md).
115-
4. There are five resources defined by the template:
114+
1. Select **Open** to open the file. The scenario is the same as the one that's used in [Tutorial: Create Azure Resource Manager templates with dependent resources](./resource-manager-tutorial-create-templates-with-dependent-resources.md).
115+
The template defines five resources:
116116
117117
* `Microsoft.Storage/storageAccounts`. See the [template reference](https://docs.microsoft.com/azure/templates/Microsoft.Storage/storageAccounts).
118118
* `Microsoft.Network/publicIPAddresses`. See the [template reference](https://docs.microsoft.com/azure/templates/microsoft.network/publicipaddresses).
119119
* `Microsoft.Network/virtualNetworks`. See the [template reference](https://docs.microsoft.com/azure/templates/microsoft.network/virtualnetworks).
120120
* `Microsoft.Network/networkInterfaces`. See the [template reference](https://docs.microsoft.com/azure/templates/microsoft.network/networkinterfaces).
121121
* `Microsoft.Compute/virtualMachines`. See the [template reference](https://docs.microsoft.com/azure/templates/microsoft.compute/virtualmachines).
122122
123-
It is helpful to get some basic understanding of the template before customizing it.
124-
5. Select **File**>**Save As** to save a copy of the file to your local computer with the name **azuredeploy.json**.
125-
6. Repeat steps 1-4 to open the following URL, and then save the file as **azuredeploy.parameters.json**.
123+
It's helpful to have some basic understanding of the template before you customize it.
124+
125+
1. Select **File** > **Save As**, and then save a copy of the file to your local computer with the name *azuredeploy.json*.
126+
127+
1. Repeat steps 1-3 to open the following URL, and then save the file as *azuredeploy.parameters.json*.
126128

127129
```url
128130
https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/101-vm-simple-windows/azuredeploy.parameters.json
@@ -132,8 +134,8 @@ Azure QuickStart Templates is a repository for Resource Manager templates. Inste
132134

133135
You don't need to make any changes to the template file.
134136
135-
1. Open **azuredeploy.parameters.json** in Visual Studio Code if it is not opened.
136-
2. Update the **adminPassword** parameter to:
137+
1. In Visual Studio Code, open *azuredeploy.parameters.json* if it's not already open.
138+
1. Update the `adminPassword` parameter to:
137139

138140
```json
139141
"adminPassword": {
@@ -147,21 +149,22 @@ You don't need to make any changes to the template file.
147149
```
148150

149151
> [!IMPORTANT]
150-
> Replace the value of **id** with the resource ID of your key vault created in the last procedure.
152+
> Replace the value for **id** with the resource ID of the key vault that you created in the previous procedure.
153+
154+
![Integrate key vault and Resource Manager template virtual machine deployment parameters file](./media/resource-manager-tutorial-use-key-vault/resource-manager-tutorial-create-vm-parameters-file.png)
151155

152-
![integrate key vault and Resource Manager template virtual machine deployment parameters file](./media/resource-manager-tutorial-use-key-vault/resource-manager-tutorial-create-vm-parameters-file.png)
153-
3. Give the values to:
156+
1. Update the following values:
154157

155-
* **adminUsername**: name the virtual machine administrator account.
156-
* **dnsLabelPrefix**: name the dnsLabelPrefix.
158+
* **adminUsername**: The name of the virtual machine administrator account.
159+
* **dnsLabelPrefix**: Name the dnsLabelPrefix value.
157160

158-
See an example in the previous screenshot.
161+
For examples of names, see the preceding image.
159162

160-
4. Save the changes.
163+
1. Save the changes.
161164

162165
## Deploy the template
163166

164-
Follow the instructions in [Deploy the template](./resource-manager-tutorial-create-templates-with-dependent-resources.md#deploy-the-template) to deploy the template. You must upload both **azuredeploy.json** and **azuredeploy.parameters.json** to the Cloud shell, and then use the following PowerShell script to deploy the template:
167+
Follow the instructions in [Deploy the template](./resource-manager-tutorial-create-templates-with-dependent-resources.md#deploy-the-template). Upload both *azuredeploy.json* and *azuredeploy.parameters.json* to Cloud Shell, and then use the following PowerShell script to deploy the template:
165168

166169
```azurepowershell
167170
$projectName = Read-Host -Prompt "Enter the same project name that is used for creating the key vault"
@@ -174,20 +177,21 @@ New-AzResourceGroupDeployment `
174177
-TemplateParameterFile "$HOME/azuredeploy.parameters.json"
175178
```
176179

177-
When you deploy the template, use the same resource group as the key vault. It makes easier when you clean up the resources. You only need to delete one resource group instead of two.
180+
When you deploy the template, use the same resource group that you used in the key vault. This approach makes it easier for you to clean up the resources, because you need to delete only one resource group instead of two.
178181

179182
## Validate the deployment
180183

181-
After you have successfully deployed the virtual machine, test the login using the password stored in the key vault.
184+
After you've successfully deployed the virtual machine, test the sign-in credentials by using the password that's stored in the key vault.
182185

183186
1. Open the [Azure portal](https://portal.azure.com).
184-
2. Select **Resource grouips**/**YourResourceGroupName>**/**simpleWinVM**
185-
3. Select **connect** from the top.
186-
4. Select **Download RDP File** and then follow the instructions to sign in into the virtual machine using the password stored in the key vault.
187+
188+
1. Select **Resource groups** > **\<*YourResourceGroupName*>** > **simpleWinVM**.
189+
1. Select **connect** at the top.
190+
1. Select **Download RDP File**, and then follow the instructions to sign in to the virtual machine by using the password that's stored in the key vault.
187191

188192
## Clean up resources
189193

190-
When the Azure resources are no longer needed, clean up the resources you deployed by deleting the resource group.
194+
When you no longer need your Azure resources, clean up the resources that you deployed by deleting the resource group.
191195

192196
```azurepowershell-interactive
193197
$projectName = Read-Host -Prompt "Enter the same project name that is used for creating the key vault"
@@ -198,7 +202,7 @@ Remove-AzResourceGroup -Name $resourceGroupName
198202

199203
## Next steps
200204

201-
In this tutorial, you retrieved a secret from Azure Key Vault, and used the secret in your template deployment. To learn how to create linked templates, see:
205+
In this tutorial, you retrieved a secret from your Azure key vault. You then used the secret in your template deployment. To learn how to create linked templates, see:
202206

203207
> [!div class="nextstepaction"]
204208
> [Create linked templates](./resource-manager-tutorial-create-linked-templates.md)

0 commit comments

Comments
 (0)