【问题标题】:How to integrate AppService with Subnet through ARM template如何通过ARM模板将AppService与子网集成
【发布时间】:2020-01-04 07:37:24
【问题描述】:

我正在使用 arm 模板和 terraform 在 VNet 中设置 AppService 与特定子网的集成。它抛出错误,有人可以帮我指出模板有什么问题吗?

我已经通过 Terraform 脚本创建了网关、具有动态 IP 地址的 VNet 和 3 个为Microsoft.Web 启用服务端点的子网。我无法进行应用服务 - VNet 集成,因此我使用“azurerm_template_deployment”为此执行特定的手臂模板。

我正在执行的 ARM 模板

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "sites_uos_aue_web_web_name": {
      "defaultValue": "some-name-develop-web",
      "type": "string"
    },
    "serverfarms_externalid": {
      "defaultValue": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/SOME-Develop-ARG-App-WEB/providers/Microsoft.Web/serverfarms/some-name-develop-asp-web",
      "type": "string"
    },
    "virtual_network_name": {
      "type": "string",
      "defaultValue": "some-aue-develop-vnet-agw"
    },
    "subnet_resource_id": {
      "type": "string",
      "defaultValue": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/SOME-Develop-ARG-App-WEB/providers/Microsoft.Network/virtualNetworks/some-aue-develop-vnet-agw"
    }
  },
  "variables": {},
  "resources": [
    {
      "name": "[parameters('sites_uos_aue_web_web_name')]",
      "type": "Microsoft.Web/sites",
      "apiVersion": "2018-11-01",
      "kind": "app",
      "location": "Asia East",
      "properties": {
        "enabled": true,
        "hostNameSslStates": [
          {
            "name": "[concat(parameters('sites_uos_aue_web_web_name'), '.azurewebsites.net')]",
            "sslState": "Disabled",
            "hostType": "Standard"
          },
          {
            "name": "[concat(parameters('sites_uos_aue_web_web_name'), '.scm.azurewebsites.net')]",
            "sslState": "Disabled",
            "hostType": "Repository"
          }
        ],
        "serverFarmId": "[parameters('serverfarms_externalid')]",
        "reserved": false,
        "requestTracingEnabled": true,
        "httpLoggingEnabled": true,
        "detailedErrorLoggingEnabled": true,
        "vnetName": "[parameters('virtual_network_name')]"
      },    
      "resources": []
    },
    {
      "type": "Microsoft.Web/sites/config",
      "apiVersion": "2018-11-01",
      "name": "[concat(parameters('sites_uos_aue_web_stepupweb_name'), '/web')]",
      "location": "Australia East",
      "dependsOn": [
        "[resourceId('Microsoft.Web/sites', parameters('sites_uos_aue_web_web_name'))]"
      ],
      "properties": {
        "requestTracingEnabled": true,
        "requestTracingExpirationTime": "9999-12-31T23:59:00Z",
        "httpLoggingEnabled": true,
        "logsDirectorySizeLimit": 35,
        "detailedErrorLoggingEnabled": true,
        "scmType": "LocalGit",
        "vnetName": "[parameters('virtual_network_name')]",
        "ipSecurityRestrictions": [
          {
            "vnetSubnetResourceId": "[concat(parameters('subnet_resource_id'), '/subnets/frontend')]",
            "action": "Allow",
            "name": "FrontendSubnetAccess"
          }
        ]
      }
    }
  ]
}

执行时出现以下错误

Error: Error waiting for deployment: Code="DeploymentFailed" Message="至少一项资源部署操作失败。请列出部署操作以了解详细信息。请参阅https://aka.ms/arm-debug了解使用详情。"详情=[{"code":"NotFound","message":"{\r\n \"error\": {\r\n \"code\": \"BadRequest\",\r\n \"message\": \"\"\r\n }\r\n}"}]

任何指针?

【问题讨论】:

    标签: azure terraform arm-template terraform-provider-azure


    【解决方案1】:

    如果您想将 Azure Vnet 与 Azure 应用服务集成,可以参考以下 ARM 模板:

    {
      "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
        "environmentName": {
          "type": "string"
        },
        "location": {
          "type": "string",
          "defaultValue": "[resourceGroup().location]",
          "metadata": {
            "description": "Location for all resources."
          }
        }
      },
      "variables": {
        "entropy": "[uniqueString(resourceGroup().id, parameters('environmentName'))]",
    
        "vnetName": "[concat(parameters('environmentName'), 'vnet')]",
        "vnetPrefix": "10.0.0.0/8",
    
        "subnetName": "WebAppSubnet",
        "subnetRef": "[resourceId('Microsoft.Network/virtualNetworks/subnets', variables('vnetName'), variables('subnetName'))]",
        "subnetPrefix": "10.0.0.0/24",
    
    
    
        "appServicePlanName": "[concat(parameters('environmentName'), 'asp')]",
        "webAppName": "[concat(parameters('environmentName'), variables('entropy'))]"
      },
      "resources": [
        {
          "apiVersion": "2018-04-01",
          "type": "Microsoft.Network/virtualNetworks",
          "name": "[variables('vnetName')]",
          "location": "[parameters('location')]",
          "properties": {
            "addressSpace": {
              "addressPrefixes": [
                "[variables('vnetPrefix')]"
              ]
            },
            "subnets": [
              {
                "name": "[variables('subnetName')]",
                "properties": {
                  "addressPrefix": "[variables('subnetPrefix')]",
                  "serviceEndpoints": [
                    {
                      "service": "Microsoft.Storage"
                    }
                  ],
                  "delegations": [
                    {
                      "name": "webapp",
                      "properties": {
                        "serviceName": "Microsoft.Web/serverFarms",
                        "actions": [
                          "Microsoft.Network/virtualNetworks/subnets/action"
                        ]
                      }
                    }
                  ]
                }
              }
            ]
          }
        },
          {
            "apiVersion": "2017-08-01",
            "type": "Microsoft.Web/serverfarms",
            "kind": "app",
            "name": "[variables('appServicePlanName')]",
            "location": "[parameters('location')]",
            "properties": {},
            "dependsOn": [],
            "sku": {
              "name": "S1"
            }
          },
          {
            "apiVersion": "2016-08-01",
            "type": "Microsoft.Web/sites",
            "kind": "app",
            "name": "[variables('webAppName')]",
            "location": "[parameters('location')]",
            "properties": {
              "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]"
            },
            "resources": [
                {
                    "name": "virtualNetwork",
                    "type": "config",
                    "apiVersion": "2018-02-01",
                    "location": "[parameters('location')]",
                    "dependsOn": [
                      "[concat('Microsoft.Web/sites/', variables('WebAppName'))]",
                      "[concat('Microsoft.Network/virtualNetworks/', variables('vnetName'))]"
                    ],
                    "properties":
                    {
                        "subnetResourceId": "[variables('subnetRef')]",
                        "swiftSupported": true
                    }
                  }
            ],
            "dependsOn": [
              "[resourceId('Microsoft.Web/serverfarms', variables('appServicePlanName'))]"
            ]
          }
      ]
    }
    

    更多详情请参考github上的issue

    【讨论】:

    • 感谢@test123,在我必须为我的基础设施做一些自定义更改后,这很好。
    【解决方案2】:

    Azure 有两个版本的VNet Integration 功能。一个版本支持与同一区域中的 VNet 集成,另一个版本支持与其他区域中的 VNet 或经典 VNet 集成,但需要虚拟网络网关。您似乎使用网关所需的 VNet 集成。您需要在 JSON 模板中包含 Microsoft.Web/sites/virtualNetworkConnections 资源。

    正如我所见,您在这一段中有错误,

     "type": "Microsoft.Web/sites/config",
          "apiVersion": "2018-11-01",
          "name": "[concat(parameters('sites_uos_aue_web_stepupweb_name'), '/web')]",
    

    应该是"name": "[concat(parameters('sites_uos_aue_web_web_name'), '/web')

    在您的情况下,您可以添加虚拟网络(启用了 VNet 网关)参数和参考:

     "virtualNetworks_test_externalid": {
                "defaultValue": "/subscriptions/xxx/resourceGroups/xx/providers/Microsoft.Network/virtualNetworks/test",
                "type": "string"
            }
    

    并添加资源Microsoft.Web/sites/virtualNetworkConnections

    {
            "type": "Microsoft.Web/sites/virtualNetworkConnections",
            "apiVersion": "2016-08-01",
            "name": "[concat(parameters('sites_uos_aue_web_web_name'), '/test')]",
            "location": "Central US",
            "dependsOn": [
                "[resourceId('Microsoft.Web/sites', parameters('sites_uos_aue_web_web_name'))]"
            ],
            "properties": {
                "vnetResourceId": "[parameters('virtualNetworks_test_externalid')]",
                "resyncRequired": false,
                "isSwift": true
    
            }
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-11-18
      • 2018-08-16
      • 1970-01-01
      • 1970-01-01
      • 2017-11-11
      • 1970-01-01
      • 2020-01-06
      • 2019-11-08
      相关资源
      最近更新 更多