使用二头肌部署逻辑应用 - 将 JSON 转换为有效的二头肌

问题描述

我想生成一个用于构建逻辑应用程序的二头肌。这个的样板是

resource logicApp 'Microsoft.Logic/workflows@2019-05-01' = {
  name: 'lapp-${options.suffix}'
  location: options.location
  properties: {
    deFinition: {
      // here comes the deFinition
    }
  }
}

我的评论显示了应用程序本身定义的位置。如果我知道从现有的逻辑应用程序中获取 JSON(为简洁起见,我省略了一些内容):

{
    "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": {}
}

你必须把它转换成这样:

{
    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: {}
}

这意味着例如:

是否有任何转换器可以将 JSON 结构转换为有效的二头肌?我的意思不是 bicep decompile,因为这里假设您已经拥有一个有效的 ARM 模板。

解决方法

一种方法是将您的定义保存在一个单独的文件中,并将 json 作为参数传递。

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
  }
}

然后你可以像这样部署你的模板(在这里使用 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
  

使用这种方法,您不必每次更新逻辑应用时都修改“基础设施即代码”。