简体   繁体   English

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

[英]How to create a new resource in Azure ARM templates?

Ok, I've done everything what described here with ARM template - https://azure.microsoft.com/en-us/documentation/articles/web-sites-integrate-with-vnet . 好的,我已经用ARM模板完成了此处描述的所有操作-https: //azure.microsoft.com/zh-cn/documentation/articles/web-sites-integrate-with-vnet Except one thing - Enabling VNET Integration with a pre-existing VNET. 除了一件事-启用与现有VNET的VNET集成。

Can this be done in ARM templates? 可以在ARM模板中完成吗? Thanks! 谢谢!

Here is a sample template that might help you. 这是一个示例模板,可能会对您有所帮助。 It's modified from this quickstart sample in GitHub 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'))]"
              }
            }
         ]
      }
   ]
}

Here are 3 things you should be careful with. 这是您应注意的三件事。

  1. The template starts with a python web app template, and adds a "Microsoft.Web/sites/virtualNetworkConnections" resource. 该模板以python Web应用程序模板开头,并添加“ Microsoft.Web / sites / virtualNetworkConnections”资源。 So, if you are using other programing language, you can start with some other template. 因此,如果您使用其他编程语言,则可以从其他模板开始。

  2. The pre-existing VNet should be in the same resource group you are deploying. 先前存在的VNet应该与您要部署的资源组相同。 If the VNet you are using are not in the same resource group, you should modify the "vnetResourceId" in the "properties" of the "Microsoft.Web/sites/virtualNetworkConnections". 如果使用的VNet不在同一个资源组中,则应在“ Microsoft.Web / sites / virtualNetworkConnections”的“属性”中修改“ vnetResourceId”。

  3. The VNet you are using should have a Gateway with a Point-to-Site address already. 您使用的VNet应该已经有一个具有指向站点地址的网关。 Otherwise, you will not be able integrate you web app to the VNet. 否则,您将无法将Web应用程序集成到VNet。 For more details, see Configure a Point-to-Site connection to a virtual network using PowerShell 有关更多详细信息,请参阅使用PowerShell配置与虚拟网络的点对点连接

Update : About how I get this info, well, there is not much about this on the net. 更新 :关于我如何获取此信息,嗯,网上对此没有太多了解。 This template is constructed based on the PowerShell solution and my knowledge about ARM template. 该模板是基于PowerShell解决方案和我对ARM模板的了解而构建的。 The PowerShell solution is available in this article . 本文提供了PowerShell解决方案。 Another possible way to get an ARM template is to create those resources in one resource group, and export the template of the resource group in the portal. 获取ARM模板的另一种可能的方法是在一个资源组中创建这些资源,然后在门户中导出资源组的模板。 But, for this case, that is not going to work, because resource type "Microsoft.Web/sites/virtualNetworkConnections" is not supported yet. 但是,在这种情况下,这是行不通的,因为尚不支持资源类型“ Microsoft.Web / sites / virtualNetworkConnections”。 However, you can still get a look at the REST API by the PowerShell Command Get-AzureRmResource with option -debug . 但是,您仍然可以通过带有选项-debug的PowerShell命令Get-AzureRmResource来查看REST API。

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

You will get the following REST API. 您将获得以下REST API。

Uri: 乌里:

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

Body: 身体:

{
  "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
  }
}

Skipping some automatically generated values, you will get the template which is quite similar to the one I write: 跳过一些自动生成的值,您将获得与我编写的模板非常相似的模板:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Azure - Azure资源管理器(ARM模板)内进行测试 - How to test within Azure - Azure Resource Manager (ARM Templates) azure arm 模板“资源未定义”,即使它是 - azure arm templates “resource not defined” even though it is 如何使用ARM模板在azure监视器中配置新警报? - how to configure the new alerts in azure monitor using ARM templates? 如何使用ARM模板创建Azure Kubernetes服务(AKS) - How to Create Azure Kubernetes Service (AKS) using ARM Templates 如何使用 ARM 模板创建 Azure DigitalTwin 模型、关系和双胞胎? - How to create Azure DigitalTwin models,relationships and twins using ARM templates? 如何检查特定的 Azure ARM 资源是否存在,如果不存在,则使用 PowerShell 创建它 - How to check if a specific Azure ARM Resource exists or not and if not exists create it with PowerShell 如何在 Azure 资源管理器 (ARM) 模板中为 virtual.networks、存储帐户等参数提供下拉列表 - How to give drop down for parameters like virtual networks, storage accounts in Azure Resource Manager (ARM) templates ARM 模板所需的资源 - Resource needed for ARM templates 将 ARM 模板部署到 Azure 资源组时出现授权错误 - Authorisation errors when deploying ARM templates to Azure Resource Group 将 bool 参数类型用于 Azure 资源管理器 (ARM) 模板中的条件 - Using bool parameter type for conditions in Azure Resource Manager (ARM) templates
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM