Skip to content

Commit e0b15df

Browse files
authored
Merge pull request #293808 from LHL407/how-to-articles-about-providing-parameters
[AQ] edit pass: How-to articles about providing parameters
2 parents ccbcb64 + b258a22 commit e0b15df

File tree

2 files changed

+96
-92
lines changed

2 files changed

+96
-92
lines changed

articles/azure-resource-manager/bicep/key-vault-parameter.md

Lines changed: 36 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,35 @@
11
---
2-
title: Use Azure Key Vault to pass a secret from a key vault as a parameter during Bicep deployment
3-
description: Learn how to to pass a secret from a key vault as a parameter during Bicep deployment.
2+
title: Use Azure Key Vault to Pass a Secret as a Parameter During Bicep Deployment
3+
description: Learn how to pass a secret from a key vault as a parameter during Bicep deployment.
44
ms.topic: conceptual
5-
ms.date: 01/13/2025
5+
ms.date: 01/31/2025
66
ms.custom: devx-track-azurepowershell, devx-track-azurecli, devx-track-bicep
77
---
88

9-
# Use Azure Key Vault to pass a secret from a key vault as a parameter during Bicep deployment
9+
# Use Azure Key Vault to pass a secret as a parameter during Bicep deployment
1010

11-
Instead of entering a secure value like a password directly into your Bicep file or parameters file, you can retrieve the value from an [Azure Key Vault](/azure/key-vault/general/overview) during a deployment. When a [module](./modules.md) expects a `string` parameter with a `secure:true` modifier, you can use the [`getSecret` function](bicep-functions-resource.md#getsecret) to obtain a key vault secret. The value is never exposed because you only reference its key vault ID.
11+
This article explains how to use Azure Key Vault to pass a secret as a parameter during Bicep deployment. Instead of entering a secure value like a password directly into your Bicep file or parameters file, you can retrieve the value from [Azure Key Vault](/azure/key-vault/general/overview) during a deployment.
12+
13+
When a [module](./modules.md) expects a string parameter with a `secure:true` modifier applied, you can use the [`getSecret` function](bicep-functions-resource.md#getsecret) to obtain a key vault secret. You don't expose the value because you reference only its key vault ID.
1214

1315
> [!IMPORTANT]
1416
> This article focuses on how to pass a sensitive value as a template parameter. When the secret is passed as a parameter, the key vault can exist in a different subscription than the resource group to which you're deploying.
15-
>
16-
> This article doesn't cover how to set a virtual-machine property to a certificate's URL in a key vault. For a quickstart template of that scenario, see [WinRM on a Windows VM](https://github.com/Azure/azure-quickstart-templates/tree/master/demos/vm-winrm-keyvault-windows).
17+
18+
This article doesn't cover how to set a virtual machine (VM) property to a certificate's URL in a key vault. For a quickstart template of that scenario, see [WinRM on a Windows VM](https://github.com/Azure/azure-quickstart-templates/tree/master/demos/vm-winrm-keyvault-windows).
1719

1820
## Deploy key vaults and secrets
1921

2022
To access a key vault during Bicep deployment, set `enabledForTemplateDeployment` on the key vault to `true`.
2123

2224
If you already have a key vault, make sure it permits template deployments.
2325

24-
# [Azure CLI](#tab/azure-cli)
26+
### [Azure CLI](#tab/azure-cli)
2527

2628
```azurecli-interactive
2729
az keyvault update --name ExampleVault --enabled-for-template-deployment true
2830
```
2931

30-
# [Azure PowerShell](#tab/azure-powershell)
32+
### [Azure PowerShell](#tab/azure-powershell)
3133

3234
```azurepowershell-interactive
3335
Set-AzKeyVaultAccessPolicy -VaultName ExampleVault -EnabledForTemplateDeployment
@@ -37,7 +39,7 @@ Set-AzKeyVaultAccessPolicy -VaultName ExampleVault -EnabledForTemplateDeployment
3739

3840
To create a new key vault and add a secret, use:
3941

40-
# [Azure CLI](#tab/azure-cli)
42+
### [Azure CLI](#tab/azure-cli)
4143

4244
```azurecli-interactive
4345
az group create --name ExampleGroup --location centralus
@@ -49,7 +51,7 @@ az keyvault create \
4951
az keyvault secret set --vault-name ExampleVault --name "ExamplePassword" --value "hVFkk965BuUv"
5052
```
5153

52-
# [Azure PowerShell](#tab/azure-powershell)
54+
### [Azure PowerShell](#tab/azure-powershell)
5355

5456
```azurepowershell-interactive
5557
New-AzResourceGroup -Name ExampleGroup -Location centralus
@@ -64,9 +66,9 @@ $secret = Set-AzKeyVaultSecret -VaultName ExampleVault -Name 'ExamplePassword' -
6466

6567
---
6668

67-
As the owner of the key vault, you automatically have access to create secrets. If the user working with secrets isn't the owner of the key vault, grant access with:
69+
The owner of the key vault automatically has access to create secrets. If the user who is working with secrets isn't the owner of the key vault, you can grant access with:
6870

69-
# [Azure CLI](#tab/azure-cli)
71+
### [Azure CLI](#tab/azure-cli)
7072

7173
```azurecli-interactive
7274
az keyvault set-policy \
@@ -75,7 +77,7 @@ az keyvault set-policy \
7577
--secret-permissions set delete get list
7678
```
7779

78-
# [Azure PowerShell](#tab/azure-powershell)
80+
### [Azure PowerShell](#tab/azure-powershell)
7981

8082
```azurepowershell-interactive
8183
$userPrincipalName = "<Email Address of the deployment operator>"
@@ -90,8 +92,8 @@ Set-AzKeyVaultAccessPolicy `
9092

9193
For more information about creating key vaults and adding secrets, see:
9294

93-
- [Set and retrieve a secret by using CLI](/azure/key-vault/secrets/quick-create-cli)
94-
- [Set and retrieve a secret by using PowerShell](/azure/key-vault/secrets/quick-create-powershell)
95+
- [Set and retrieve a secret by using the Azure CLI](/azure/key-vault/secrets/quick-create-cli)
96+
- [Set and retrieve a secret by using Azure PowerShell](/azure/key-vault/secrets/quick-create-powershell)
9597
- [Set and retrieve a secret by using the Azure portal](/azure/key-vault/secrets/quick-create-portal)
9698
- [Set and retrieve a secret by using .NET](/azure/key-vault/secrets/quick-create-net)
9799
- [Set and retrieve a secret by using Node.js](/azure/key-vault/secrets/quick-create-node)
@@ -100,7 +102,7 @@ For more information about creating key vaults and adding secrets, see:
100102

101103
The user who deploys the Bicep file must have the `Microsoft.KeyVault/vaults/deploy/action` permission for the scope of the resource group and key vault. The [Owner](../../role-based-access-control/built-in-roles.md#owner) and [Contributor](../../role-based-access-control/built-in-roles.md#contributor) roles both grant this access. If you created the key vault, you're the owner and have the permission.
102104

103-
The following procedure shows how to create a role with the minimum permission and how to assign the user.
105+
The following procedure shows how to create a role with the minimum permission and how to assign the user:
104106

105107
1. Create a custom JSON file with a role definition:
106108

@@ -123,9 +125,9 @@ The following procedure shows how to create a role with the minimum permission a
123125

124126
Replace "00000000-0000-0000-0000-000000000000" with the subscription ID.
125127

126-
2. USe the JSON file to create the new role:
128+
2. Use the JSON file to create the new role:
127129

128-
# [Azure CLI](#tab/azure-cli)
130+
### [Azure CLI](#tab/azure-cli)
129131

130132
```azurecli-interactive
131133
az role definition create --role-definition "<path-to-role-file>"
@@ -135,7 +137,7 @@ The following procedure shows how to create a role with the minimum permission a
135137
--assignee <user-principal-name>
136138
```
137139

138-
# [Azure PowerShell](#tab/azure-powershell)
140+
### [Azure PowerShell](#tab/azure-powershell)
139141

140142
```azurepowershell-interactive
141143
New-AzRoleDefinition -InputFile "<path-to-role-file>"
@@ -147,17 +149,17 @@ The following procedure shows how to create a role with the minimum permission a
147149

148150
---
149151

150-
The samples assign the custom role to the user on the resource-group level.
152+
The preceding examples assign the custom role to the user on the resource-group level.
151153

152-
When using a key vault with the Bicep file for a [Managed Application](../managed-applications/overview.md), you must grant access to the **Appliance Resource Provider** service principal. For more information, see [Access Key Vault secret when deploying Azure Managed Applications](../managed-applications/key-vault-access.md).
154+
If you use a key vault with a Bicep file for a [managed application](../managed-applications/overview.md), you must grant access to the **Appliance Resource Provider** service principal. For more information, see [Access a Key Vault secret when deploying Azure managed applications](../managed-applications/key-vault-access.md).
153155

154-
## Retrieve secrets in Bicep file
156+
## Retrieve secrets in a Bicep file
155157

156-
You can use the [`getSecret` function](./bicep-functions-resource.md#getsecret) in Bicep files to obtain a key vault secret. Note that the `getSecret` function is exclusively applicable to a `Microsoft.KeyVault/vaults` resource. Additionally, it's restricted to usage within the `params` section of a module and can only be used with parameters with the `@secure()` decorator.
158+
You can use the [`getSecret` function](./bicep-functions-resource.md#getsecret) in a Bicep file to obtain a key vault secret. The `getSecret` function can be used only with a `Microsoft.KeyVault/vaults` resource. Additionally, it can be used only within the `params` section of a module and only with parameters that have the `@secure()` decorator.
157159

158-
Another function called `az.getSecret()` function can be used in Bicep parameters files to retrieve key vault secrets. For more information, see [Retrieve secrets in parameters file](#retrieve-secrets-in-parameters-file).
160+
You can use another function called `az.getSecret()` in a Bicep parameters file to retrieve key vault secrets. For more information, see [Retrieve secrets in a parameters file](#retrieve-secrets-in-a-parameters-file).
159161

160-
Since the `getSecret` function can only be used in the `params` section of a module, create a _sql.bicep_ file in the same directory as the _main.bicep_ file with the following content:
162+
Since the `getSecret` function can be used only in the `params` section of a module, create a _sql.bicep_ file in the same directory as the _main.bicep_ file with the following content:
161163

162164
```bicep
163165
param sqlServerName string
@@ -180,7 +182,7 @@ resource sqlServer 'Microsoft.Sql/servers@2023-08-01-preview' = {
180182

181183
The `adminPassword` parameter has a `@secure()` decorator in the preceding file.
182184

183-
The following Bicep file consumes _sql.bicep_ as a module. The Bicep file references an existing key vault, calls the `getSecret` function to retrieve the key vault secret, and then passes the value as a parameter to the module:
185+
The following Bicep file consumes _sql.bicep_ as a module. The Bicep file references an existing key vault, calls the `getSecret` function to retrieve the key vault secret, and then passes the value as a parameter to the module:
184186

185187
```bicep
186188
param sqlServerName string
@@ -205,9 +207,9 @@ module sql './sql.bicep' = {
205207
}
206208
```
207209

208-
## Retrieve secrets in parameters file
210+
## Retrieve secrets in a parameters file
209211

210-
If you don't want to use a module, you can retrieve key vault secrets in a parameters file. However, the approach varies depending on whether you're using a JSON or Bicep parameters file.
212+
If you don't want to use a module, you can retrieve key vault secrets in a parameters file. However, the approach varies depending on whether you use a JSON or Bicep parameters file.
211213

212214
The following Bicep file deploys a SQL server that includes an administrator password. While the password parameter is set to a secure string, Bicep doesn't specify the origin of that value:
213215

@@ -234,7 +236,7 @@ Next, create a parameters file for the preceding Bicep file.
234236

235237
### Bicep parameters file
236238

237-
The [`az.getSecret`](./bicep-functions-parameters-file.md#getsecret) function can be used in a `.bicepparam` file to retrieve the value of a secret from a key vault:
239+
The [`az.getSecret` function](./bicep-functions-parameters-file.md#getsecret) can be used in a `.bicepparam` file to retrieve the value of a secret from a key vault:
238240

239241
```bicep
240242
using './main.bicep'
@@ -246,7 +248,7 @@ param adminPassword = az.getSecret('<subscription-id>', '<rg-name>', '<key-vault
246248

247249
### JSON parameters file
248250

249-
In a JSON parameters file, specify a parameter that matches the name of the parameter in the Bicep file. For the parameter value, reference the secret from the key vault; you do this by passing the resource identifier of the key vault and the name of the secret. In the following parameters file, the key vault secret must already exist, and you provide a static value for its resource ID:
251+
In a JSON parameters file, specify a parameter that matches the name of the parameter in the Bicep file. For the parameter value, reference the secret from the key vault. Pass the resource identifier of the key vault and the name of the secret. In the following parameters file, the key vault secret must already exist. You provide a static value for its resource ID.
250252

251253
```json
252254
{
@@ -278,8 +280,8 @@ If you need to use a version of the secret other than the current one, include a
278280
"secretVersion": "cd91b2b7e10e492ebb870a6ee0591b68"
279281
```
280282

281-
## Next steps
283+
## Related content
282284

283-
- For general information about key vaults, see [About Azure Key Vault](/azure/key-vault/general/overview)
284-
- For complete GitHub examples of how to reference key vault secrets, see [keyvaultexamples](https://github.com/rjmax/ArmExamples/tree/master/keyvaultexamples).
285+
- For general information about key vaults, see [About Azure Key Vault](/azure/key-vault/general/overview).
286+
- For complete GitHub examples that demonstrate how to reference key vault secrets, see [Key vault examples](https://github.com/rjmax/ArmExamples/tree/master/keyvaultexamples).
285287
- For a Learn module that covers how to use a key vault to pass a secure value, see [Manage complex cloud deployments by using advanced JSON ARM template features](/training/modules/manage-deployments-advanced-arm-template-features/).

0 commit comments

Comments
 (0)