Output Values With Bicep

In this post, we will show how to output values from a Bicep deployment and display them.

Output

We might need to use outputs in a Bicep deployment to retrieve specific information about our deployed resources.

In our case, we have a Bicep template the create a Key Vault.

Define Output

The first step in using outputs with Bicep is to add an output statement to the template, define the variable, define the variable type, and finally, the value we would like to output.

In the example below, I will output the Key Vault ID. To output it, I’m defining the name of the output, the data type and the value that will output.

output keyvaultid string = keyVault.id

View Output

When viewing an output, we can view it on screen post-Azure CLI deployment or use the following command to retrieve it.

The first option might not work in some scenarios. You can also use the Azure portal to view the output. You will find it under the deployment details.

az deployment group show -g biceplab -n vars --query properties.outputs

Below you can see the output after I used the above command.

{
  "type": "String",
  "value": "/subscriptionid/something/resourceGroups/biceplab/providers/Microsoft.KeyVault/vaults/nbiceplab"
}

Processing…
Success! You're on the list.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.