如何在Azure ARM模板中创建新资源?

问题描述:

好的,我已经完成了所有使用ARM模板描述的内容 - https://azure.microsoft.com/en-us/documentation/articles/web-sites-integrate-with-vnet。除了一件事 - 启用VNET与预先存在的VNET集成。如何在Azure ARM模板中创建新资源?

这可以在ARM模板中完成吗? 谢谢!

+0

灿你分享你的模板,让我不必重新开始? –

+0

我希望我可以,但这是一个客户端,而且它有很大的参数和变量。很抱歉,不能这样做。 – alvipeo

以下是可能对您有所帮助的示例模板。它的修改从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