Bicep: How to Output Values

This blog post will show you how to output values from a Bicep deployment. This is an important task for anyone who uses Azure Bicep for infrastructure deployments.

To output values, you need to define them in your Bicep file. This is done by adding the Output keyword and then specifying the name of the output. You can then use this name in your templates to return the value.

For example, let’s say that we want to return the name of a deployed storage account.

Output

To output values in Bicep, we use the output function as shown below (see entire code later on this page).

The name storage is the name of the output variable, and it references the name of the resource we are deploying.

output storage string = storageAccount.name

When we use VS Code to deploy Bicep templates, the entire output of the deployment is available to us; however, when we use deployment pipelines, the output is convenient.

If you open the deployment from the Azure portal, you will see the output as well. In our case, we are outputting the storage account name, and I can see it in the Output section in the portal.

Bicep Template

The Bicep template is shown below.

param location string = resourceGroup().location
param utc string = utcNow()
param storageaccountname string = 'ntweekly${uniqueString(utc)}'

resource storageAccount 'Microsoft.Storage/storageAccounts@2019-06-01' = {
  name: storageaccountname
  location: location
  sku: {
    name: 'Standard_LRS'
  }
  kind: 'StorageV2'
  properties: {
    accessTier: 'Hot'
  }
}

output storage string = storageAccount.name
Published
Categorized as Bicep

Leave a comment

Your email address will not be published.

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