An Overview of the New Bicep Parameter Files

Microsoft’s Azure platform has introduced a novel and effective way to manage parameters in Bicep files. This new approach involves the creation of Bicep parameters files, a method that promises to bring more flexibility and security to the configuration of Azure resources.

What Are Bicep Parameter Files?

Bicep parameter files are used to store parameter values for a Bicep file. Rather than directly embedding parameter values within your script or using JSON parameter files, you can now place them in a separate parameters file with the extension .bicepparam. This file can then be associated with the relevant Bicep file through a using statement.

Interestingly, you can associate multiple Bicep parameter files with a single Bicep file, but each parameter file is specifically tailored for one Bicep file. This specificity helps to establish a clear connection between the parameter file and its corresponding Bicep file, ensuring smooth configuration management.

Parameter File Format

A Bicep parameter file follows a simple structure. It starts with a using statement that links the parameter file to the relevant Bicep file, and then each parameter is defined using the param keyword, followed by the parameter name and its value. You can also use expressions as default values or even reference environment variables as parameter values.

Here’s an example:

using './main.bicep'

param exampleString = 'test string'
param exampleInt = 2 + 2
param exampleBool = true
param exampleArray = [
  'value 1'
  'value 2'
]
param exampleObject = {
  property1: 'value 1'
  property2: 'value 2'
}

Different parameter types such as string, integer, boolean, array, and object are supported.

Security Considerations

Although Bicep parameter files offer much convenience, it’s important to remember that these files store parameter values as plain text. For this reason, they are not recommended for storing sensitive values like passwords. Instead, sensitive values should be kept in a key vault, and the getSecret function can be used to retrieve these values when needed.

Naming Conventions and Multiple Environments

When it comes to naming Bicep parameter files, it’s a good practice to include the name of the Bicep file in the parameter file’s name. This approach makes it easy to understand the relationship between a Bicep file and its parameter file. For instance, if you have a Bicep file named azuredeploy.bicep, your parameter file could be named azuredeploy.parameters.bicepparam.

What’s more, when deploying resources to different environments, you can create multiple parameter files, each tailored for a specific environment. For example, azuredeploy.parameters-dev.bicepparam could be used for the development environment, and azuredeploy.parameters-prod.bicepparam for the production environment.

Parameter Definition and Types

The parameters in a Bicep parameter file must match those in the corresponding Bicep file. Therefore, to define the parameter names and values, you should first inspect the parameters section of the Bicep file. The parameter types in your parameters file must also align with the types in your Bicep file.

Note that if a parameter has a default value in the Bicep file, you can still provide a value in the parameters file. If you do, the value from the parameters file will override the Bicep file’s default value.

Additionally, when defining parameters, be aware of the restrictions and allowed values as specified in the Bicep file. For instance, a parameter may have a maximum length restriction or must specify an allowed value.

Inline Comments and File Saving

When working with Bicep parameter files, you can use inline comments to clarify or explain certain parts of your code. The comment can be inserted using either // for a single line comment or /* ... */ for multi-line comments.

Bicep parameter file commenting

Conclusion

The introduction of Bicep parameter file marks a significant milestone in Azure’s infrastructure management. These files offer a more efficient, secure, and flexible way to manage parameters, making Bicep even more powerful and user-friendly. Whether you are deploying resources to multiple environments or managing sensitive parameters, Bicep parameter files have got you covered.

For more detailed information and instructions on how to use Bicep parameter files, refer to the official Microsoft documentation.

About the author