😀

Azure Logic Apps を Bicep でデプロイしてみた

に公開

Azure Logic Apps は Azure ポータル上の GUI でローコード開発ができて便利です。便利な反面、ソースコード管理がやり辛かったり、開発環境で開発した Azure Logic Apps を検証環境や本番環境にきちんとデプロイするのが面倒だったりします。そこで今回は Bicep を使って、インフラとしての Azure Logic Apps と Azure Logic Apps コードの開発環境へのデプロイを試してみました。

これらの動作が確認できれば、後は環境ごとのパラメーターを Bicep に持たせ、Git リポジトリのブランチやタグで環境へのデプロイ時にパラメーターを自動付与する Azure Pipelines を作成するなどして、各環境へ簡単にデプロイする事も可能になります。

検証用の Bicep ファイルを準備

https://learn.microsoft.com/ja-jp/azure/logic-apps/quickstart-create-deploy-bicep?toc=%2Fazure%2Fazure-resource-manager%2Fbicep%2Ftoc.json&tabs=CLI

こちらを参考に下記の Bicep ファイルをローカルに保存します。

logicapps.bicep
@description('The name of the logic app to create.')
param logicAppName string

@description('A test URI')
param testUri string = 'https://azure.status.microsoft/status/'

@description('Location for all resources.')
param location string = resourceGroup().location

var frequency = 'Hour'
var interval = '1'
var type = 'Recurrence'
var actionType = 'Http'
var method = 'GET'
var workflowSchema = 'https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#'

resource stg 'Microsoft.Logic/workflows@2019-05-01' = {
  name: logicAppName
  location: location
  tags: {
    displayName: logicAppName
  }
  properties: {
    state: 'Enabled'
    definition: {
      '$schema': workflowSchema
      contentVersion: '1.0.0.0'
      parameters: {
        testUri: {
          type: 'String'
          defaultValue: testUri
        }
      }
      triggers: {
        recurrence: {
          type: type
          recurrence: {
            frequency: frequency
            interval: interval
          }
          evaluatedRecurrence: {
            frequency: frequency
            interval: interval
          }
        }
      }
      actions: {
        actionType: {
          type: actionType
          inputs: {
            method: method
            uri: testUri
          }
        }
      }
    }
  }
}

開発環境でデプロイ検証

bash
# リソースグループを作成します
az group create \
  --name mnrlga-rg \
  --location japaneast

# デプロイをすると何が変わるのかを確認します
az deployment group what-if \
  --resource-group mnrlga-rg \
  --template-file logicapps.bicep \
  --parameters logicAppName=mnrlga-app

# デプロイします
az deployment group create \
  --resource-group mnrlga-rg \
  --template-file logicapps.bicep \
  --parameters logicAppName=mnrlga-app

# 変更箇所が無い事を確認します
az deployment group what-if \
  --resource-group mnrlga-rg \
  --template-file logicapps.bicep \
  --parameters logicAppName=mnrlga-app

# 検証が終わったらリソースグループを削除して後片付けをします
az group delete \
  --name mnrlga-rg \
  --yes

参考

https://learn.microsoft.com/ja-jp/cli/azure/deployment/group?view=azure-cli-latest#az-deployment-group-what-if

https://learn.microsoft.com/ja-jp/training/paths/fundamentals-bicep/

Discussion