Challenge 02 - Bicep Expressions and Referencing Resources

< Previous Challenge - Home - Next Challenge >

Introduction

In this challenge you will edit the Bicep file created in Challenge 1. The goals for this challenge include:

Description

Bicep Functions

Bicep supports powerful functions we can use. Functions return information that can be set as the value of a parameter or a variable. Some functions take input parameters. Other functions can return information about an object or its properties.

In the previous challenge, you defined and accepted two parameters for your Bicep template:

Instead of requiring users of your Bicep template to provide these values, we can use Bicep functions to provide these values dynamically when the template is run.

Bicep has two functions that can help here:

Using functions, ensure the location and storageAccountName properties can be set dynamically as follows:

Bicep Operators

Like other programming languages, Bicep supports the use of Operators. Operators are used to calculate values, compare values, or evaluate conditions.

Bicep’s ternary operator is a clever way to simplify the syntax needed to do comparisons. Use it manage the redundancy of the storage account as specified:

Reference Existing Bicep Resources

When authoring a Bicep template, it is common that you will need to get a reference to another Azure resource so that you can either modify it, or retreive properties from it.

For example, when defining Virtual Network (VNET), you may want to configure a Network Security Group (NSG) to apply to a subnet. In this scenario, the VNET resource will need a reference to the NSG resource.

In ARM Templates with JSON, this was a complicated task. Bicep makes referencing an existing resource SO much easier!

And now you will need to figure it out by doing the following:

Bicep Parameter Files

In the previous challenge, you observed that parameter values need to be passed in via the command line or you will be prompted for their values each time you deploy the template.

HINT: Bicep uses the same parameter file format as ARM Templates with JSON.

Success Criteria

  1. Verify you can pass parameter values to the template via a parameter file
  2. Demonstrate that you can deploy Azure Storage Account without hard-coding inputs
  3. Verify you can create a container within the storage account
  4. Verify you can output the storage account name and blob primary endpoint url

Learning Resources