1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Azure Logic Apps で自分がよく使う式関数

Last updated at Posted at 2023-05-06

自分は、Azure Logic Apps を、ノーコード・ローコードで決まった処理を繰り返し実行させるプログラムが作成できる、統合プラットフォーム ( iPaaS : Integration Platform as a Service ) だと思っています。コードが書けるなら CI/CD 基盤が枯れている Azure Functions も選択肢になりますが、組織やチームで Azure Logic Apps を使う選択をされることもあるかと思います。そこで今回は、Azure Logic Apps で自分がよく使う式関数を紹介します。

HTTP トリガーで受け取る値を取得

JSON スキーマで指定した param の値を取得する。

triggerBody()?['param']

HTTP レスポンスの値を取得

TOKEN という名前の HTTP リクエストのレスポンスにある access_token の値を取得する。

body('TOKEN')?['access_token']

Foreach ループ内で値を取得

Foreach という名前のループ内で id の値を取得する。

items('Foreach')?['id']

配列の個数を取得

例えば、ネットワークセキュリティグループの複数あるルールを Foreach でループしながら、あるルールで destinationPortRanges 配列の個数が 0 だったら destinationPortRange を取得する処理の場合の条件分岐に使用する。

length(items('Foreach')?['properties']?['destinationPortRanges'])

数値の配列を作成

例えば、60-63 のようなポート番号を意味する文字列があったとして、split でハイフン区切りの前と後ろの文字列を取り出し、 int で数値に変換しつつ、sub で引き算、add で足し算をして、range で数値の配列 [60,61,62,63] を作成する。

range(int(split(triggerBody()?['port'], '-')?[0]), add(sub(int(split(triggerBody()?['port'], '-')?[1]), int(split(triggerBody()?['port'], '-')?[0])), 1))

HTTP レスポンスの JSON 内にキーがあるかを確認

例えば、get-nic という名前の HTTP リクエストの JSON レスポンス内に networkSecurityGroup というキーが存在するかを確認する。

contains(body('get-nic')?['properties'], 'networkSecurityGroup')

値が null だったらデフォルト値を設定

HTTP トリガーで受け取る値が無かったらデフォルト値として json という文字列を返します。

coalesce(triggerBody()?['type'], 'json')

(おまけ) Azure REST API の nextLink を Until ループで処理

例えば、最初に、変数 nextLink に下記の値を設定しておく。

https://management.azure.com/subscriptions/[sid]/resources?$top=3&api-version=2021-04-01

Until ループで nextLink に値が無かったら終了するよう条件を設定する。

HTTP リクエストの URI に nextLink を入れて実行する。

HTTP レスポンス内の例えば以下のような nextLink の値を nextLink 変数にセットする。

https://management.azure.com/subscriptions/[sid]/resources?$top=3&api-version=2021-04-01&$skiptoken=*****

HTTP レスポンス内に nextLink が無ければ Until ループは終了する。

参考

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?