0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

TerraformでLogic Apps Standardを作るために必要なこと

0
Last updated at Posted at 2026-11-13

はじめに

TerraformでLogic Apps Standardのワークフロープランを作成する必要があり、実際に作ってみたのですが、その際、いくつか問題があり、思ったように作成できませんでした。

ここでは、うまくいかなかった問題点と、その解決方法を説明し、Logic AppsのStandardプランを作るために必要なことを解説します。

問題点

問題点 1

Logic Apps自体は作れるのに、その後、ワークフロー(実際にロジックを記述する部分)、パラメータ(ワークフローから参照できる固定値の値)、接続(ほかのリソースに接続するときの接続情報)を作ることができませんでした。

Logic Apps自体は azurerm_logic_app_standard で定義して作ることができますが、上記3つを作る方法が見当たりませんでした。

問題点 2

Logic Appsを作成すると以下のように「Functions ランタイムエラー」というエラーが表示され、Logic Appsが正しく動作しませんでした。

Logic Appsエラー

解決方法

問題点 1

ワークフロー、パラメーター、接続の各設定は、実際はJSONファイルとして保存されています。Logic Appsを作る際に、ストレージアカウントも指定する必要があると思いますが、そのストレージアカウントにファイル共有が作成され、その中に各設定のJSONファイルが保存されます。

そのため、各設定を記述したJSONファイルを azurerm_storage_share_file を使って所定の場所にアップロードすればよいということになります。

各設定を記述するJSONファイルは以下の通りになります。

設定 JSONファイル名
ワークフロー workflow.json
パラメーター parameters.json
接続 connections.json

格納場所は以下の通りになっています。AzureポータルからLogic Appsを作成した場合は、ファイル共有の名前は適当なものが付けられます。

フォルダ構造

問題点 2

Logic Appsは、上記パラメーターの設定以外に、環境変数の設定で値を保持しているものがあります。このうち、Azureポータルから作成した場合に、既定でセットされる環境変数の一部が、Terraformで作成するとセットされない状態で作成されてしまいます。

そのため、azurerm_logic_app_standard 内の app_settings という項目で、必要な環境変数をセットしてあげればよいということになります。

今回の検証でAzureポータルから作成した場合と比較して不足していた環境変数は以下の通りになります(2026年4月現在でAzureポータルから作成した場合の最新の値)。不足分を追加する形になります。

変数名 値
FUNCTIONS_INPROC_NET8_ENABLED 1
FUNCTIONS_WORKER_RUNTIME dotnet
LOGIC_APPS_POWERSHELL_VERSION 7.4
WEBSITE_NODE_DEFAULT_VERSION ~20

実装

Terraformでの実装方法を説明します。ここから、main.tf に各リソースを記述していきます。

StandardのLogic Appsでは、App Serviceプランが必要なので、初めにこちらから作成していきます。Azureポータルでの作成に準拠するのであれば、os_type は Windows で、sku_name は WS1、WS2、WS3 のどれかになります。ここではasp-exampleという名前のApp Serviceプランを作成します。

main.tf
resource "azurerm_service_plan" "this" {
  name                = "asp-example"
  location            = "japaneast"
  resource_group_name = "rg-logicapp"
  sku_name            = "WS1"
  os_type             = "Windows"
}

次に、ストレージアカウントを作成します。ここではstlogicappexample0001という名前のストレージアカウントを作成します。

main.tf
resource "azurerm_storage_account" "this" {
  name                     = "stlogicappexample0001"
  resource_group_name      = "rg-logicapp"
  location                 = "japaneast"
  account_kind             = "StorageV2"
  account_tier             = "Standard"
  account_replication_type = "LRS"
}

次に、ファイル共有を作成します。Azureポータルから作成した場合は、自動的に適当な名前のファイル共有が作成されますが、Terraformでは、Logic Appsを作成する際に任意のファイル共有を指定できます。

名前はなんでもよいのですが、Azureポータルから作成すると"<Logic Appsの名前><ランダム文字列>"となるので、Logic Appsの名前と同じ名前などとするのがよいでしょう。ここではlogicapp-exampleとします。

main.tf
resource "azurerm_storage_share" "this" {
  name               = "logicapp-example"
  storage_account_id = azurerm_storage_account.this.id
  quota              = 50
}

次に、Logic Apps本体を作ります。storage_account_share_name の箇所に、先ほど作成したファイル共有を指定します。また、app_settings の箇所に不足分の環境変数を指定します。ここでは、logicapp-exampleという名前のLogic Appsを作ります。

main.tf
resource "azurerm_logic_app_standard" "this" {
  name                       = "logicapp-example"
  location                   = "japaneast"
  resource_group_name        = "rg-logicapp"
  app_service_plan_id        = azurerm_service_plan.this.id
  storage_account_name       = azurerm_storage_account.this.name
  # 検証ではストレージアクセスキーを使っていますが、本番環境等ではEntra ID認証やKey Vault経由のキー取得などを検討したほうがよいと思われます。
  storage_account_access_key = azurerm_storage_account.this.primary_access_key
  # ここで、ファイル共有の名前を指定することができる
  storage_account_share_name = azurerm_storage_share.this.name
  # app_settings で環境変数を設定できる
  # 不足分の環境変数をここで指定する
  app_settings = {
    FUNCTIONS_INPROC_NET8_ENABLED = "1"
    FUNCTIONS_WORKER_RUNTIME      = "dotnet"
    LOGIC_APPS_POWERSHELL_VERSION = "7.4"
    WEBSITE_NODE_DEFAULT_VERSION  = "~20"
  }
  #
  identity {
    type = "SystemAssigned"
  }
}

ここから、ワークフロー、パラメーター、接続の各設定を作成していきます。今回、Terraformのみで構成する方法として以下の方式を採用しました。

まずは、それら設定が記述されたJSONファイルを用意します。サンプルとして以下のJSONを用意しました。これを、main.tf があるフォルダと同じフォルダに格納します。

workflow.json
workflow.json
{
  "definition": {
    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
    "contentVersion": "1.0.0.0",
    "actions": {
      "List_all_containers": {
        "type": "ServiceProvider",
        "inputs": {
          "serviceProviderConfiguration": {
            "connectionName": "AzureBlob",
            "operationId": "listContainers",
            "serviceProviderId": "/serviceProviders/AzureBlob"
          }
        },
        "runAfter": {}
      }
    },
    "outputs": {},
    "triggers": {
      "Recurrence": {
        "type": "Recurrence",
        "recurrence": {
          "interval": 1,
          "frequency": "Day",
          "timeZone": "Tokyo Standard Time",
          "schedule": {
            "hours": [
              0
            ],
            "minutes": [
              0
            ]
          }
        }
      }
    }
  },
  "kind": "Stateful"
}
parameters.json
parameters.json
{
  "blob_endpoint": {
    "type": "string",
    "value": "https://stlogicappexample0001.blob.core.windows.net"
  }
}
connections.json
connections.json
{
  "managedApiConnections": {},
  "serviceProviderConnections": {
    "AzureBlob": {
      "displayName": "conn_blob",
      "parameterSetName": "ManagedServiceIdentity",
      "parameterValues": {
        "authProvider": {
          "Type": "ManagedServiceIdentity"
        },
        "blobStorageEndpoint": "@parameters('blob_endpoint')"
      },
      "serviceProvider": {
        "id": "/serviceProviders/AzureBlob"
      }
    }
  }
}

次に、ファイル共有の中にフォルダを作成します。site/wwwroot までは、Logic Appsを作成すると自動作成されるようです。wwwroot の下にフォルダを作成しますが、このフォルダの名前がワークフローの名前になります。複数ワークフローを作成する場合は、その分だけフォルダを作成する必要があります。今回はworkflow-exampleという名前のフォルダを作成します。

main.tf
resource "azurerm_storage_share_directory" "this" {
  name              = "site/wwwroot/workflow-example"
  storage_share_url = azurerm_storage_share.this.url
}

次に、各JSONファイルを所定の場所にアップロードします。${path.module} で mainf.tf があるフォルダパスを参照できるので、"${path.module}/<jsonファイル名>" としてアップロードするファイルを指定します。

main.tf
# workflow.json
resource "azurerm_storage_share_file" "workflow" {
  name              = "workflow.json"
  storage_share_url = azurerm_storage_share.this.url
  path              = "site/wwwroot/workflow-example"
  source            = "${path.module}/workflow.json"
}

# parameters.json
resource "azurerm_storage_share_file" "parameters" {
  name              = "parameters.json"
  storage_share_url = azurerm_storage_share.this.url
  path              = "site/wwwroot"
  source            = "${path.module}/parameters.json"
}

# connections.json
resource "azurerm_storage_share_file" "connections" {
  name              = "connections.json"
  storage_share_url = azurerm_storage_share.this.url
  path              = "site/wwwroot"
  source            = "${path.module}/connections.json"
}

コードの全体は以下のようになります。

main.tf
main.tf
terraform {
  required_providers {
    azurerm = {
      source  = "hashicorp/azurerm"
      version = "4.58.0"
    }
  }
}
provider "azurerm" {
  features {}
  subscription_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
}

###################################
# App Service プラン
###################################

resource "azurerm_service_plan" "this" {
  name                = "asp-example"
  location            = "japaneast"
  resource_group_name = "rg-logicapp"
  sku_name            = "WS1"
  os_type             = "Windows"
}

###################################
# ストレージアカウント
###################################

resource "azurerm_storage_account" "this" {
  name                     = "stlogicappexample0001"
  resource_group_name      = "rg-logicapp"
  location                 = "japaneast"
  account_kind             = "StorageV2"
  account_tier             = "Standard"
  account_replication_type = "LRS"
}

###################################
# ファイル共有
###################################

resource "azurerm_storage_share" "this" {
  name               = "logicapp-example"
  storage_account_id = azurerm_storage_account.this.id
  quota              = 50
}

###################################
# Logic App Standard
###################################

resource "azurerm_logic_app_standard" "this" {
  name                       = "logicapp-example"
  location                   = "japaneast"
  resource_group_name        = "rg-logicapp"
  app_service_plan_id        = azurerm_service_plan.this.id
  storage_account_name       = azurerm_storage_account.this.name
  storage_account_access_key = azurerm_storage_account.this.primary_access_key
  # ここで、ファイル共有の名前を指定することができる
  storage_account_share_name = azurerm_storage_share.this.name
  # app_settings で環境変数を設定できる
  # 不足分の環境変数をここで指定する
  app_settings = {
    FUNCTIONS_INPROC_NET8_ENABLED = "1"
    FUNCTIONS_WORKER_RUNTIME      = "dotnet"
    LOGIC_APPS_POWERSHELL_VERSION = "7.4"
    WEBSITE_NODE_DEFAULT_VERSION  = "~20"
  }
  #
  identity {
    type = "SystemAssigned"
  }
}

###################################
# ファイル共有 フォルダ
###################################

resource "azurerm_storage_share_directory" "this" {
  name              = "site/wwwroot/workflow-example"
  storage_share_url = azurerm_storage_share.this.url
}

###################################
# JSONファイルのアップロード
###################################

# workflow.json
resource "azurerm_storage_share_file" "workflow" {
  name              = "workflow.json"
  storage_share_url = azurerm_storage_share.this.url
  path              = "site/wwwroot/workflow-example"
  source            = "${path.module}/workflow.json"
}

# parameters.json
resource "azurerm_storage_share_file" "parameters" {
  name              = "parameters.json"
  storage_share_url = azurerm_storage_share.this.url
  path              = "site/wwwroot"
  source            = "${path.module}/parameters.json"
}

# connections.json
resource "azurerm_storage_share_file" "connections" {
  name              = "connections.json"
  storage_share_url = azurerm_storage_share.this.url
  path              = "site/wwwroot"
  source            = "${path.module}/connections.json"
}

結果

実際に作成して、Azureポータル上でどうなったか見てみます。

まず、概要画面です。通知タブにエラーがなく、右上の「ランタイム バージョン」に数字が表示されていれば問題ないです。

概要

次に、接続の設定です。

接続

次に、パラメーターの設定です。

パラメーター

最後に、ワークフローの設定です。

ワークフロー1

ワークフロー2

いずれも、JSONに記述した通り、想定通りになっていました。

最後に

最初、Logic Appsを作成したときに、どうやってワークフローを設定するのかわからず困っていました。また、作成後もエラーになったりで、結構調べながら問題解消していました。

同様の方の一助になれば幸いです。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?