LoginSignup
1
1

More than 5 years have passed since last update.

Azure Resource Manager Template でWeb Appに拡張機能を追加

Last updated at Posted at 2017-05-10

Azure Resource Manager Template(ARM Template) で、アプリケーションを実行するためのWeb Appの環境を自動的に作ろうとしたところ、拡張機能をどのように追加するのかがスキーマにその定義が見当たらなかった。
調べてみたところStackOverflowで同様の質問があり、その回答を元に色々試してみたところ、拡張機能を設定できた。

簡単なARM Templateを例にして、その方法を説明する。

テンプレートの例

例のために、Composerを利用したPHPアプリケーションを実行するためのWeb Appを作るテンプレートを作りました。

deployWebAppForPHPwithComposer.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "appName": {
            "defaultValue": "hello-php",
            "type": "string"
        }
    },
    "variables": {
    },
    "resources": [
        {
            "type": "Microsoft.Web/serverfarms",
            "apiVersion": "2015-08-01",
            "location": "[resourceGroup().location]",
            "name": "[concat(parameters('appName'), '-free-plan')]",
            "sku": {
                "name": "F1"
            },
            "properties": {
                "numberOfWorkers": 1
            }
        },
        {
            "type": "Microsoft.Web/sites",
            "name": "[parameters('appName')]",
            "apiVersion": "2015-08-01",
            "location": "[resourceGroup().location]",
            "properties": {
                "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', concat(parameters('appName'), '-free-plan'))]"
            },
            "resources" : [
                {
                    "name": "web",
                    "type": "config",
                    "apiVersion": "2015-08-01",
                    "properties": {
                       "phpVersion": "7.0"
                    },
                    "dependsOn": [
                        "[resourceId('Microsoft.Web/sites', parameters('appName'))]"
                    ]
                },
                {
                    "name": "ComposerExtension",
                    "type": "siteextensions",
                    "apiVersion": "2015-08-01",
                    "properties": {
                        "version": "0.3.3",
                        "feed_url": "https://www.siteextensions.net/api/v2/"
                    },
                    "dependsOn": [
                        "[resourceId('Microsoft.Web/sites', parameters('appName'))]"
                    ]
                }
            ],
            "dependsOn": [
                "[resourceId('Microsoft.Web/serverfarms', concat(parameters('appName'), '-free-plan'))]"
            ]
        }
    ]
}

肝心の部分は45行目から56行目Microsoft.Web/sitesの部分。
ここ記述で拡張機能のインストールを指定している。

注意するのは下記の3点。

  1. 拡張機能のインストールは対象のWeb App の作成が終わってからでないとできないため、dependsOn で対象のWeb Appとの依存を定義すること
  2. name に入る拡張機能の名前はAzure Portalの拡張機能の画面で表示されるものとは異なり、Site Extension Gallery の各パッケージのうURLに含まれているパッケージ名を指定すること。例えば、Composerの場合、Site Extension Galleryで検索すると、 http://www.siteextensions.net/packages/ComposerExtension/ なので、ComposerExtension をnameの値として使う。
  3. propertiesversion は、利用する拡張機能のバージョンを指定する。利用可能なバージョンは、Site Extension Galleryの各拡張機能のページ下部に記載されている。

これでまた自動で環境構築という野望に一歩近づきました :tada:
上のサンプルのテンプレートと実行方法はGistにアップしたのでチェックしてみて下さい。

参考

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