Ale*_*idt 2 azure azure-resource-manager azure-logic-apps azure-bicep
我想生成一个二头肌来构建逻辑应用程序。这个的样板是
resource logicApp 'Microsoft.Logic/workflows@2019-05-01' = {
name: 'lapp-${options.suffix}'
location: options.location
properties: {
definition: {
// here comes the definition
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的评论显示了应用程序本身的定义所在的位置。如果我知道从现有逻辑应用程序中获取 JSON(为了简洁起见,我省略了一些内容):
resource logicApp 'Microsoft.Logic/workflows@2019-05-01' = {
name: 'lapp-${options.suffix}'
location: options.location
properties: {
definition: {
// here comes the definition
}
}
}
Run Code Online (Sandbox Code Playgroud)
你必须将其转换为如下所示:
{
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: {}
}
Run Code Online (Sandbox Code Playgroud)
这意味着例如:
schema或自定义操作名称是否有任何转换器可以将 JSON 结构转换为有效的二头肌?我的意思不是bicep decompile因为这假设您已经拥有有效的 ARM 模板。
Tho*_*mas 10
一种方法是将定义保存在单独的文件中,并将 json 作为参数传递。
主要二头肌:
// 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
}
}
Run Code Online (Sandbox Code Playgroud)
然后您可以像这样部署模板(此处使用 az cli 和 powershell):
$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
Run Code Online (Sandbox Code Playgroud)
通过这种方法,您不必每次更新逻辑应用时都修改“基础设施即代码”。
小智 5
添加另一种方法。使用loadTextContent(file.json)加载 bicep 文件内的工作流程文件,并使用json()方法将其解析为 JSON ,并直接访问 bicep 文件内的定义和参数,避免将工作流程文件作为参数传递给 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
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6539 次 |
| 最近记录: |