Problem
I’d like to create a bicep for use in a Logic App. This would be the boilerplate for it:
resource logicApp 'Microsoft.Logic/workflows@2019-05-01' = {
name: 'lapp-${options.suffix}'
location: options.location
properties: {
definition: {
// here comes the definition
}
}
}
My comment depicts the location where the app’s definition would be posted. If I know what I’m doing, I’ll take a JSON from an existing logic app (I’ve left out certain details for brevity):
{
"definition": {
"$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
"actions": {},
"contentVersion": "1.0.0.0",
"outputs": {},
"parameters": {},
"triggers": {
"manual": {
"inputs": {
},
"kind": "Http",
"type": "Request"
}
}
},
"parameters": {}
}
You’d need to change it to something like this:
{
definition: {
'$schema': "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#"
actions: {}
contentVersion: '1.0.0.0'
outputs: {}
parameters: {}
triggers: {
'manual': {
inputs: {
}
kind: 'Http'
type: 'Request'
}
}
}
parameters: {}
}
That means, for example:
Is there a converter that will convert a JSON structure to a valid bicep? I don’t mean bicep decompile because that requires you already have a working ARM template.
Asked by Alexander Schmidt
Solution #1
Keeping your definition in a separate file and passing the json as an argument is one option.
main.bicep:
// Parameters
param location string = resourceGroup().location
param logicAppName string
param logicAppDefinition object
// Basic logic app
resource logicApp 'Microsoft.Logic/workflows@2019-05-01' = {
name: logicAppName
location: location
properties: {
state: 'Enabled'
definition: logicAppDefinition.definition
parameters: logicAppDefinition.parameters
}
}
Then, using az cli and powershell, you can deploy your template as follows:
$definitionPath="full/path/of/the/logic/app/definition.json"
az deployment group create `
--resource-group "resource group name" `
--template-file "full/path/of/the/main.bicep" `
--parameters logicAppName="logic app name" `
--parameters logicAppDefinition=@$definitionPath
You won’t have to change your “infra-as-code” every time you update the logic app if you use this method.
Answered by Thomas
Solution #2
Including a new strategy. Load the workflow file into the bicep file using loadTextContent(file.json), parse it as JSON with the json() method, and access the definition and arguments directly from the bicep file, rather than giving the workflow file to the CLI.
param location string = resourceGroup().location
param logicAppName string
var logicAppDefinition = json(loadTextContent('LogicApp.workflow.json'))
// Basic logic app
resource logicApp 'Microsoft.Logic/workflows@2019-05-01' = {
name: logicAppName
location: location
properties: {
state: 'Enabled'
definition: logicAppDefinition.definition
parameters: logicAppDefinition.parameters
}
}
Answered by Gopa
Post is based on https://stackoverflow.com/questions/68606269/deploy-logic-app-using-bicep-convert-json-to-valid-bicep