45
loading...
This website collects cookies to deliver better user experience
Bicep is a domain-specific language (DSL) that uses declarative syntax to deploy Azure resources. It provides concise syntax, reliable type safety, and support for code reuse. We believe Bicep offers the best authoring experience for your Azure infrastructure as code solutions.
az cli
install option and all my examples will be using that variant. I also use Visual Studio Code and installed the Bicep VS Code Extension for enhanced editing.azuredeploy.json
file for the template)az bicep decompile --file azuredeploy.json
azuredeploy.bicep
file in the same directory. Depending on your template, you will most likely get a stream of yellow warnings in the console, or potentially some red errors: don't panic! Even a single error will result in all the console output being red (at least on macOS) and at the very least you will get this warning message:WARNING: Decompilation is a best-effort process, as there is no guaranteed mapping from ARM JSON to Bicep.
You may need to fix warnings and errors in the generated bicep file(s), or decompilation may fail entirely if an accurate conversion is not possible.
If you would like to report any issues or inaccurate conversions, please see https://github.com/Azure/bicep/issues.
Error BCPXXX: Description
and the descriptions generally let you get to the root of the problem quickly. E.g. Error BCP037: The property "location" is not allowed on objects of type "Microsoft.EventHub/namespaces/eventhubs". Permissible properties include "dependsOn".v0.4
there is a linter which helps you get your templates into great shape -- these are the warnings with the links at the end. Both kinds of warnings are generally quick to fix and are sensible updates to start getting the benefits from Bicep.Error BCP007: This declaration type is not recognized. Specify a parameter, variable, resource, or output declaration.
Error BCP057: The name "functionName
" does not exist in the current context.
dependsOn
properties in your ARM templates gets weird with Bicep (dependsOn
can often be removed entirely in Bicep). The ARM version would have validated and deployed perfectly fine however you will get the following error when decompiling to Bicep.Error BCP034: The enclosing array expected an item of type "module[] | (resource | module) | resource[]", but the provided item was of type "string".
For Bicep, you can set an explicit dependency but this approach isn't recommended. Instead, rely on implicit dependencies. An implicit dependency is created when one resource declaration references the identifier of another resource.
dependsOn
references entirely)location
or tags
to a resource that doesn't support them and ARM didn't mind this. These will be expressed as Error BCP037
.location
on Microsoft.EventHub/namespaces/eventhubsError BCP037: The property "location" is not allowed on objects of type "Microsoft.EventHub/namespaces/eventhubs". Permissible properties include "dependsOn".
identity
property needed for using Managed Identity with your Logic App:Error BCP037: The property "identity" is not allowed on objects of type "Microsoft.Logic/workflows". Permissible properties include "dependsOn".
Error BCP073: The property "kind" is read-only. Expressions cannot be assigned to read-only properties.
parameters('name')
or variables('name')
etc. In Bicep the syntax is simplified and as such you will get errors if you have used a reserved word as a parameter. We had a couple of templates taking in a parameter called description
resulting in a cryptic error message:Error BCP079: This expression is referencing its own declaration, which is not allowed.
az bicep build --file azuredeploy.bicep
Warning BCP036: The property "kafkaEnabled" expected a value of type "bool | null" but the provided value is of type "'False' | 'True'".
Warning BCP036: The property "order" expected a value of type "'Ascending' | 'Descending' | null" but the provided value is of type "'ascending'".
Warning BCP035: The specified "object" declaration is missing the following required properties: "options".
Warning BCP037: The property "apiVersion" is not allowed on objects of type "Output". No other properties are allowed.
Warning BCP073: The property "status" is read-only. Expressions cannot be assigned to read-only properties.
concat
gets to disappear in Bicep thanks to the lovely string interpolation option. I experienced two variants:Warning prefer-interpolation: Use string interpolation instead of the concat function. [https://aka.ms/bicep/linter/prefer-interpolation]
concat
and replace with the new syntax: 'string-${var}'
.Warning simplify-interpolation: Remove unnecessary string interpolation. [https://aka.ms/bicep/linter/simplify-interpolation]
${}
and reference the variable directly. E.g. '${variable}'
becomes variable
.environment()
function. Caveat here, if you had environment
as a parameter to your ARM template, update this to be something else like env
for example otherwise you won't be able to use the function.Warning no-hardcoded-env-urls: Environment URLs should not be hardcoded. Use the environment() function to ensure compatibility across clouds. Found this disallowed host: "core.windows.net" [https://aka.ms/bicep/linter/no-hardcoded-env-urls]
environment().<property>
. *core.windows.net
had been hard coded, replacing with environment().suffixes.storage
gives the desired result./providers/
syntax (role assignments, diagnostic settings etc). The warning you get looks as follows.Warning BCP174: Type validation is not available for resource types declared containing a "/providers/" segment. Please instead use the "scope" property. [https://aka.ms/BicepScopes]
microsoft.insights/diagnosticSettings@2017-05-01-preview
) instead of the parent resource /providers
/scope
referencing the parent resourcedependsOn
resource functionAppLogAnalytics 'Microsoft.Web/sites/providers/diagnosticSettings@2017-05-01-preview' = {
name: '${functionAppName}/Microsoft.Insights/LogAnalytics'
tags: tagsVar
properties: {
name: 'LogAnalytics'
workspaceId: resourceId(logAnalyticsResourceGroup, 'Microsoft.OperationalInsights/workspaces', logAnalyticsWsName)
logs: [
{
category: 'FunctionAppLogs'
enabled: true
}
]
}
dependsOn: [
functionApp
]
}
resource functionAppLogAnalytics 'microsoft.insights/diagnosticSettings@2017-05-01-preview' = {
name: LogAnalytics
scope: functionApp
properties: {
workspaceId: logAnalyticsResourceId
logs: [
{
category: 'FunctionAppLogs'
enabled: true
}
]
}
}