How to safely test your IaC functions and types with Bicep console
Learn how to safely validate your Bicep functions and types using the Bicep console

How do you really understand a language? You play with it.
Bicep has a rich set of functions that are automatically available in your Bicep files. But you can also define your own user-defined functions and types. Since the launch of the new bicep console
command, this possibility even got better.
You can now test and explore Bicep functions and types in real time without deploying anything to Azure. You don't have to guess what a function returns or how a type will behave, thanks to the latest update from Anthony Martin.
In my previous post, I already shed some light on it. In this blog post, you will learn how to safely test this new functionality and validate the behavior without leaving your terminal.
Prerequisites
Assuming you want to follow along, you're going to need:
- Bicep v0.38.63 or higher
Getting started with the Bicep console
Before you start testing functions or types, you'll need to know how to launch the console. Once you've the prerequisite in place, open your terminal and type:
bicep console
This command will simply start an interactive shell where you can write and evaluate Bicep expressions on the spot. Think of it as your safe playground for your infrastructure code.
When you first run the console, you'll see a prompt like this:

From here, you can start typing any valid Bicep expression. Try something basic first:
1 + 2
The console immediately returns the evaluated result:
3
As you can see, no deployment to a resource group or subscription. Just instant feedback returned.
This quick feedback loop makes it easier to explore how Bicep handles expressions and logic. Once you get used to it, you'll jump into the console to validate syntax or experiment with ideas before you actually use it in a real Bicep file.
Testing (User-Defined) Functions and Types
One of the most powerful new additions to the Bicep console is the ability to test how your own functions and types behave. This is especially handy when you're not sure how a particular function handles input or what type it's going to return.
Let's start with a simple example. Suppose you're building a deployment that needs to format a string dynamically. In the console, you can use the built-in format()
function before using it in your template:

If the output isn't what you desired, you can tweak it and test it with multiple inputs till you get it right—no need to deploy anything.
Now, what if you want to know, for instance, what the length of an array is, or if it contains a particular region? You can also play around using both length()
and contains()
functions:

This quick test illustrates how easy it is to use the bicep console
command to verify the behavior, again, without actually deploying it.
Once you're comfortable, it's time to explore user-defined functions. These let you encapsulate logic that you can reuse across your Bicep files, which is especially useful for things like naming conventions or tag generation.
For example, imagine you want to standardize storage account names according to Azure rules:
- The name should be in lowercase.
- Maximum of 24 characters.
- Prefixed with
st
.
Instead of repeating this logic in every template, you can make it easy by defining a small function in the console and testing it:

Another real-world scenario is validating tags or metadata objects. Suppose you want a function that merges a base set of tags with environment-specific tags and adds a standard managedBy
tag:

This allows you to confirm that your function behaves as expected, catching errors early and saving time. You can even take it one step further and define a type, so you're certain when you're adding it as a parameter, it will work as expected:

By explicitly declaring the return type, the console will immediately flag any attempt to return a value that isn't an object.
Conclusion
The Bicep console gives you the confidence to test your user-defined functions and declared types. You can experiment freely and ensure everything behaves exactly as you expected.
Whether you're working on naming conventions, tag policies, or complex transformations, now you don't have to leave your terminal or deploy anything.
In short: the bicep console
is your friendly console to faster and safely test your Bicep code before you actually use it in a template.