2016-09-06 13 views
1

ARMテンプレートに複数のWebアプリケーションをプロビジョニングしていますが、複数のデプロイメントスロットにわたって単一の設定を維持するために、 。依存関係とプロパティの両方を別々に複製して管理する必要があります。私は変数を使用してみましたが、私の設定の多くは他のリソースに依存しており、変数が評価された時点で評価することはできません。ARMテンプレートを使用してデプロイメントスロット間でWebサイトの設定を共有

理想的には、すべてのスロットが同じ 'Microsoft.Web/sites/config'オブジェクトを参照するようにしたいと思いますが、その方法はわかりません。私の現在の展開スクリプトは

{ 
    "name": "[variables('siteName')]", 
    "type": "Microsoft.Web/sites", 
    "location": "[resourceGroup().location]", 
    "apiVersion": "2015-08-01", 
    "dependsOn": [ 
    "[concat('Microsoft.Web/serverfarms/', variables('serverfarm'))]", 
    "[resourceid('Microsoft.EventHub/namespaces', variables('fullEventHubNameSpace'))]" 
    ], 
    "tags": { 
    "[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('siteName'))]": "Resource" 
    }, 
    "properties": { 
    "name": "[variables('siteName')]", 
    "serverFarmId": "[resourceId('Microsoft.Web/serverfarms/', variables('serverfarm'))]", 
    "siteConfig": { 
     "AlwaysOn": true 
    } 
    }, 
    "resources": [ 
    { 
     "name": "appsettings", 
     "type": "config", 
     "apiVersion": "2015-08-01", 
     "dependsOn": [ 
     "[concat('Microsoft.Web/sites/', variables('siteName'))]", 
     "[concat('Microsoft.Insights/components/', variables('appInsightsSiteName'))]", 
     "[concat('Microsoft.Web/sites/', variables('otherSiteName'))]", 
     "[concat('Microsoft.DocumentDb/databaseAccounts/',variables('databaseAccountName'))]", 
     "[resourceid('Microsoft.EventHub/namespaces', variables('fullEventHubNameSpace'))]" 
     ], 
     "properties": { 
     "APPINSIGHTS_INSTRUMENTATIONKEY": "[reference(resourceId('Microsoft.Insights/components', variables('appInsightsName'))).InstrumentationKey]", 
     "KEYVAULT_PATH": "[parameters('keyVaultPath')]", 
     "KEYVAULT_SECRET": "[parameters('keyVaultSecret')]", 
     "OTHER_SITE": "[reference(concat('Microsoft.Web/sites/', variables('otherSiteName'))).hostnames[0]]", 
     "DB_KEY": "[listKeys(resourceId(concat('Microsoft.DocumentDb/databaseAccounts'),variables('databaseAccountName')),'2015-04-08').primaryMasterKey]", 
     } 
    }, 
    { 
     "apiVersion": "2015-08-01", 
     "name": "Staging", 
     "type": "slots", 
     "location": "[resourceGroup().location]", 
     "dependsOn": [ 
     "[resourceId('Microsoft.Web/Sites', variables('siteName'))]" 
     ], 
     "properties": { 
     }, 
     "resources": [ 
     { 
      "name": "appsettings", 
      "type": "config", 
      "apiVersion": "2015-08-01", 
      "dependsOn": [ 
      "[concat('Microsoft.Web/sites/', variables('siteName'))]", 
      "[concat('Microsoft.Insights/components/', variables('appInsightsName'))]", 
      "[concat('Microsoft.DocumentDb/databaseAccounts/',variables('databaseAccountName'))]", 
      "[concat('Microsoft.Web/sites/', variables('otherSiteName'))]", 
      "[resourceid('Microsoft.EventHub/namespaces', variables('fullEventHubNameSpace'))]", 
      "Staging" 
      ], 
      "properties": { 
      "APPINSIGHTS_INSTRUMENTATIONKEY": "[reference(resourceId('Microsoft.Insights/components', variables('appInsightsName'))).InstrumentationKey]", 
      "KEYVAULT_PATH": "[parameters('keyVaultPath')]", 
      "KEYVAULT_SECRET": "[parameters('keyVaultSecret')]", 
      "OTHER_SITE": "[reference(concat('Microsoft.Web/sites/', variables('otherSiteName'))).hostnames[0]]", 
      "DB_KEY": "[listKeys(resourceId(concat('Microsoft.DocumentDb/databaseAccounts'),variables('databaseAccountName')),'2015-04-08').primaryMasterKey]", 
      } 
     } 
     ] 
    } 
    ] 
}, 

このテンプレートのメンテナンス性の向上のためにどのような方法があります(これは、大規模な単純化されているが、私は実際にかなり多くの性質を持っている)、このようになりますか?

答えて

1

おそらく、あなたのテンプレートにcopyを使用することができます。

テンプレートでルートレベルにあなたのスロットを備えたセクションを移動し、追加

"copy": { 
    "name": "slotcopy", 
    "count": "[length(parameters('webSiteSlots'))]" 
}, 

名proppertyは次のようになりshlould:これにより

"name": "[concat(parameters('webSiteName'), '/', parameters('webSiteSlots')[copyIndex()].name)]", 

を使用すると、このリソースがされると言いますWebSiteリソースの子です。この詳細についてはhereをご覧ください。

今、あなたのテンプレートに複雑なオブジェクトの配列とパラメータを追加することができます。

:あなたのパラメータの

"webSiteSlots": { 
    "type": "array", 
    "minLength": 0, 
    "defaultValue": [] 
} 

は、あなたが今、あなたには、いくつかの追加の値を持つようにしたいスロットのコレクションを設定することができますファイル

"webSiteSlots": { 
    "value": [ 
     { 
      "name": "Staging", 
      "environment": "Production" 
     } 
    ] 
} 

あなたはこのような何かを行うことができ、これらの与えられた値を使用する:

"properties": { 
    "ASPNETCORE_ENVIRONMENT": "[parameters('webSiteSlots')[copyIndex()].environment]" 
} 

これは、公表されたコードをかなり軽くする必要があります。

挨拶、 カーク

+0

それは別のWebアプリケーションに私の展開スロットを回していないでしょうか? –

+0

@IainBrown名前タグが見つかりませんでした。これは関係を与えるでしょう。私は上記の私の答えを編集しました。 – KirKone

+0

OK、私はそれに行くよ、ありがとう –

関連する問題