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
# Use Azure Key Vault to pass secure parameter value during Bicep deployment
@@ -151,22 +151,25 @@ The following procedure shows how to create a role with the minimum permission,
151
151
152
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).
153
153
154
-
## Use getSecret function
154
+
## Retrieve secrets in Bicep file
155
155
156
-
You can use the [getSecret function](./bicep-functions-resource.md#getsecret) to obtain a key vault secret and pass the value to a `string` parameter of a module. The `getSecret` function can only be called on a `Microsoft.KeyVault/vaults` resourceand can be used only with parameter with `@secure()` decorator.
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.
157
157
158
-
The following Bicep file creates an Azure SQL server. The `adminPassword` parameter has a `@secure()` decorator.
158
+
Another function called `az.getSecret()` function can be used in Bicep parameter files to retrieve key vault secrets. For more information, see [Retrieve secrets in parameters file](#retrieve-secrets-in-parameters-file).
159
+
160
+
Because the `getSecret` function can only be used in the `params` section of a module. Let's create a *sql.bicep* in the same directory as the *main.bicep* file with the following content:
Let's use the preceding Bicep file as a module given the file name is *sql.bicep* in the same directory as the main Bicep file.
181
+
Notice in the preceding Bicep file, the `adminPassword` parameter has a `@secure()` decorator.
179
182
180
-
The following Bicep file consumes the sql.bicep as a module. The Bicep file references an existing key vault, and calls the `getSecret` function to retrieve the key vault secret, and then passes the value as a parameter to the module.
183
+
The following Bicep file consumes the *sql.bicep* as a module. The Bicep file references an existing key vault, and calls the `getSecret` function to retrieve the key vault secret, and then passes the value as a parameter to the module.
Also, `getSecret` function (or with the namespace qualifier `az.getSecret`) can be used in a `.bicepparam` file to retrieve the value of a secret from a key vault.
If you don't want to use a module, you can reference the key vault directly in the parameters file. The following image shows how the parameters file references the secret and passes that value to the Bicep file.
> Currently you can only reference the key vault in JSON parameters files. You can't reference key vault in Bicep parameters file.
210
+
If you don't want to use a module, you can retrieve key vault secrets in parameters file. However, the approach varies depending on whether you're using a JSON parameter file or a Bicep parameter file.
222
211
223
212
The following Bicep file deploys a SQL server that includes an administrator password. The password parameter is set to a secure string. But the Bicep doesn't specify where that value comes from.
Now, create a parameters file for the preceding Bicep file.
234
+
235
+
### Bicep parameter file
236
+
237
+
[`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.
Now, create a parameters file for the preceding Bicep file. In the 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 reference the secret by passing the resource identifier of the key vault and the name of the secret:
249
+
In the 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 reference the secret by passing the resource identifier of the key vault and the name of the secret:
248
250
249
251
In the following parameters file, the key vault secret must already exist, and you provide a static value for its resource ID.
250
252
@@ -254,12 +256,12 @@ In the following parameters file, the key vault secret must already exist, and y
0 commit comments