2016-07-08 52 views
0

好的,我已經完成了所有使用ARM模板描述的內容 - https://azure.microsoft.com/en-us/documentation/articles/web-sites-integrate-with-vnet。除了一件事 - 啓用VNET與預先存在的VNET集成。如何在Azure ARM模板中創建新資源?

這可以在ARM模板中完成嗎? 謝謝!

+0

燦你分享你的模板,讓我不必重新開始? –

+0

我希望我可以,但這是一個客戶端,而且它有很大的參數和變量。很抱歉,不能這樣做。 – alvipeo

回答

4

以下是可能對您有所幫助的示例模板。它的修改從this quickstart sample in GitHub

{ 
    "$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", 
    "contentVersion": "1.0.0.0", 
    "parameters": { 
     "hostingPlanName": { 
     "type": "string", 
     "minLength": 1, 
     "metadata": { 
      "description": "Name of the hosting plan to use in Azure." 
     } 
     }, 
     "webSiteName": { 
     "type": "string", 
     "minLength": 1, 
     "metadata": { 
      "description": "Name of the Azure Web app to create." 
     } 
     }, 
     "vnetName": { 
     "type": "string", 
     "minLength": 1, 
     "metadata": { 
      "description": "Name of an existing Azure VNet which has a Gateway Subnet already, and is in the resource group you are going to deploy." 
     } 
     }, 
     "skuName": { 
     "type": "string", 
     "defaultValue": "S1", 
     "allowedValues": [ 
      "S1", 
      "S2", 
      "S3", 
      "P1", 
      "P2", 
      "P3", 
      "P4" 
     ], 
     "metadata": { 
      "description": "Describes plan's pricing tier and instance size. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/" 
     } 
     }, 
     "skuCapacity": { 
     "type": "int", 
     "defaultValue": 1, 
     "minValue": 1, 
     "metadata": { 
      "description": "Describes plan's instance count" 
     } 
     } 
    }, 
    "resources": [ 
     { 
     "apiVersion": "2015-08-01", 
     "name": "[parameters('hostingPlanName')]", 
     "type": "Microsoft.Web/serverfarms", 
     "location": "[resourceGroup().location]", 
     "tags": { 
      "displayName": "HostingPlan" 
     }, 
     "sku": { 
      "name": "[parameters('skuName')]", 
      "capacity": "[parameters('skuCapacity')]" 
     }, 
     "properties": { 
      "name": "[parameters('hostingPlanName')]" 
     } 
     }, 
     { 
     "apiVersion": "2015-08-01", 
     "name": "[parameters('webSiteName')]", 
     "type": "Microsoft.Web/sites", 
     "location": "[resourceGroup().location]", 
     "tags": { 
      "[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]": "Resource", 
      "displayName": "Website" 
     }, 
     "dependsOn": [ 
      "[concat('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]" 
     ], 
     "properties": { 
      "name": "[parameters('webSiteName')]", 
      "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]" 
     }, 
     "resources": [ 
      { 
       "apiVersion": "2015-08-01", 
       "name": "web", 
       "type": "config", 
       "dependsOn": [ 
        "[concat('Microsoft.Web/sites/', parameters('webSiteName'))]" 
       ], 
       "properties": { 
        "pythonVersion": "3.4" 
       } 
      }, 
      { 
       "apiVersion": "2015-08-01", 
       "name": "[parameters('vnetName')]", 
       "type": "virtualNetworkConnections", 
       "location": "[resourceGroup().location]", 
       "dependsOn": [ 
        "[concat('Microsoft.Web/sites/', parameters('webSiteName'))]" 
       ], 
       "properties": { 
        "vnetResourceId": "[concat(resourceGroup().id, '/providers/Microsoft.Network/virtualNetworks/', parameters('vnetName'))]" 
       } 
      } 
     ] 
     } 
    ] 
} 

這裏有3件事你應該小心。

  1. 該模板以python web應用程序模板開頭,並添加了「Microsoft.Web/sites/virtualNetworkConnections」資源。因此,如果您使用其他編程語言,則可以從其他一些模板開始。

  2. 預先存在的VNet應與您正在部署的資源組位於同一個資源組中。如果您使用的VNet不在同一資源組中,則應修改「Microsoft.Web/sites/virtualNetworkConnections」的「屬性」中的「vnetResourceId」。

  3. 您正在使用的VNet應該有一個帶有點到站點地址的網關。否則,您將無法將您的Web應用程序集成到VNet。有關詳細信息,請參閱Configure a Point-to-Site connection to a virtual network using PowerShell

更新:關於我如何得到這個信息,那麼,沒有太多關於這個在網絡上。這個模板是基於PowerShell解決方案和我對ARM模板的知識構建的。 PowerShell解決方案在this article中提供。獲取ARM模板的另一種可能方式是在一個資源組中創建這些資源,並在門戶中導出資源組的模板。但是,對於這種情況,這不會起作用,因爲資源類型「Microsoft.Web/sites/virtualNetworkConnections」尚不受支持。但是,您仍然可以通過PowerShell命令Get-AzureRmResource和選項-debug查看REST API。

Get-AzureRmResource -ResourceGroupName <resource group> -ResourceType Microsoft.Web/sites/virtualNetworkConnections -Name <web app>/<VNet> -debug -ApiVersion 2015-08-01 

您將獲得以下REST API。

烏里:

https://management.azure.com/subscriptions/<subscription id>/resourceGroups/<resource group>/providers/Microsoft.Web/sites/<web app>/virtualNetworkConnections/<VNet>?api-version=2015-08-01 

身體:

{ 
    "id": "/subscriptions/<subscription id>/resourceGroups/<resource group>/providers/Microsoft.Web/sites/<web app>/virtualNetworkConnections/<VNet>", 
    "name": "<VNet>", 
    "type": "Microsoft.Web/sites/virtualNetworkConnections", 
    "location": "<Location>", 
    "tags": null, 
    "properties": { 
    "vnetResourceId": "/subscriptions/<subscription id>/resourceGroups/<resource group>/providers/Microsoft.Network/virtualNetworks/<VNet>" 
    "certThumbprint": "<Thumbprint>", 
    "certBlob": "<cert>", 
    "routes": null, 
    "resyncRequired": false, 
    "dnsServers": null 
    } 
} 

跳過一些自動生成的值,你會得到這非常類似於一個我寫的模板:

{ 
    "name": "<VNet>", 
    "type": "Microsoft.Web/sites/virtualNetworkConnections", 
    "location": "<Location>", 
    "properties": { 
    "vnetResourceId": "/subscriptions/<subscription id>/resourceGroups/<resource group>/providers/Microsoft.Network/virtualNetworks/<VNet>" 
    } 
} 
+0

你介意解釋你是如何得到這些信息的?資源管理器?你從哪裏得到這個模式?謝謝! – alvipeo

+0

請參閱我的更新。 –

+0

感謝您的更新!我不知道關於-debug的技巧!好一個! – alvipeo

相關問題