You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For more information, see [Deploy resources with Resource Manager templates and Azure PowerShell](../azure-resource-manager/resource-group-template-deploy.md) and [Deploy private Resource Manager template with SAS token and Azure PowerShell](../azure-resource-manager/secure-template-with-sas-token.md).
For more information, see [Deploy resources with Resource Manager templates and Azure CLI](../azure-resource-manager/resource-group-template-deploy-cli.md) and [Deploy private Resource Manager template with SAS token and Azure CLI](../azure-resource-manager/secure-template-with-sas-token.md).
@@ -251,8 +115,90 @@ To avoid this problem, we recommend one of the following approaches:
251
115
252
116
* Do not deploy the template more than once for the same parameters. Or delete the existing resources before using the template to recreate them.
253
117
254
-
* Examine the Key Vault access policies and then use these policies to set the accessPolicies property of the template.
255
-
* Check if the Key Vault resource already exists. If it does, do not recreate it through the template. For example, add a parameter that allows you to disable the creation of the Key Vault resource if it already exists.
118
+
* Examine the Key Vault access policies and then use these policies to set the `accessPolicies` property of the template. To view the access policies, use the following Azure CLI command:
119
+
120
+
```azurecli-interactive
121
+
az keyvault show --name mykeyvault --resource-group myresourcegroup --query properties.accessPolicies
122
+
```
123
+
124
+
For more information on using the `accessPolicies` section of the template, see the [AccessPolicyEntry object reference](https://docs.microsoft.com/azure/templates/Microsoft.KeyVault/2018-02-14/vaults#AccessPolicyEntry).
125
+
126
+
* Check if the Key Vault resource already exists. If it does, do not recreate it through the template. For example, to use the existing Key Vault instead of creating a new one, make the following changes to the template:
127
+
128
+
* **Add** a parameter that accepts the ID of an existing Key Vault resource:
129
+
130
+
```json
131
+
"keyVaultId":{
132
+
"type": "string",
133
+
"metadata": {
134
+
"description": "Specify the existing Key Vault ID."
135
+
}
136
+
}
137
+
```
138
+
139
+
* **Remove** the section that creates a Key Vault resource:
140
+
141
+
```json
142
+
{
143
+
"type": "Microsoft.KeyVault/vaults",
144
+
"apiVersion": "2018-02-14",
145
+
"name": "[variables('keyVaultName')]",
146
+
"location": "[parameters('location')]",
147
+
"properties": {
148
+
"tenantId": "[variables('tenantId')]",
149
+
"sku": {
150
+
"name": "standard",
151
+
"family": "A"
152
+
},
153
+
"accessPolicies": [
154
+
]
155
+
}
156
+
},
157
+
```
158
+
159
+
* **Remove** the `"[resourceId('Microsoft.KeyVault/vaults', variables('keyVaultName'))]",` line from the `dependsOn` section of the workspace. Also **Change** the `keyVault` entry in the `properties` section of the workspace to reference the `keyVaultId` parameter:
After these changes, you can specify the ID of the existing Key Vault resource when running the template. The template will then re-use the Key Vault by setting the `keyVault` property of the workspace to its ID.
188
+
189
+
To get the ID of the Key Vault, you can reference the output of the original template run or use the Azure CLI. The following command is an example of using the Azure CLI to get the Key Vault resource ID:
190
+
191
+
```azurecli-interactive
192
+
az keyvault show --name mykeyvault --resource-group myresourcegroup --query id
193
+
```
194
+
195
+
This command returns a value similar to the following text:
0 commit comments