Course contentsShow
← Cloud and Infrastructure
Lesson 926 of 2,98917. Azure ARM Templates and BicepFree lesson

Variables and Expressions

Creating variables and using expressions with string interpolation and built-in functions in Bicep.

Variables and Expressions in Bicep

You'll learn how to simplify and reuse values in your Bicep templates using variables and powerful built-in expressions.

What Are Variables in Bicep?

While parameters accept input from users at deployment time, variables are values you calculate or define inside your template. Think of them as internal shortcuts—they help you avoid repeating complex expressions and make your templates cleaner and more maintainable.

Variables are defined once, can reference parameters or other variables, and can perform calculations or string manipulations using Bicep's built-in functions and expressions.

Defining Variables

Variables use simple assignment syntax:

param environmentName string
param location string

var storageAccountName = 'st${environmentName}${uniqueString(resourceGroup().id)}'
var tags = {
  Environment: environmentName
  ManagedBy: 'Bicep'
}

String Interpolation

Notice the ${} syntax? That's string interpolation—Bicep's elegant way to embed expressions directly into strings. Instead of concatenating with functions, you simply wrap expressions in ${}:

var greeting = 'Hello, ${environmentName}!'
var fullPath = '/subscriptions/${subscription().subscriptionId}/resourceGroups/${resourceGroup().name}'

Built-in Functions

Bicep includes functions like uniqueString(), resourceGroup(), and subscription() to generate values or access deployment context. These work seamlessly in variable expressions to create dynamic, environment-aware configurations.

Key Takeaway: Variables in Bicep store calculated values using expressions, string interpolation with ${}, and built-in functions to keep templates DRY (Don't Repeat Yourself) and readable.