azure - 如何通过ARM模板将AppService与Subnet集成

标签 azure terraform azure-rm-template terraform-provider-azure

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

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

我正在执行的 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="At least one resource deployment operation failed. Please list deployment operations for details. Please see https://aka.ms/arm-debug for usage details." Details=[{"code":"NotFound","message":"{\r\n \"error\": {\r\n \"code\": \"BadRequest\",\r\n \"message\": \"\"\r\n }\r\n}"}]

有什么指点吗?

最佳答案

如果您想将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'))]"
        ]
      }
  ]
}

更多详情请引用issue在 github 上

关于azure - 如何通过ARM模板将AppService与Subnet集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57737066/

相关文章:

azure 缓存预览

asp.net-mvc - WebSecurity.InitializeDatabaseConnection 方法只能调用一次

amazon-web-services - 如果条件为真,Terraform 使用 for 循环分配变量值

kubernetes - 使用 terraform 在 k8s 集群中授予 RBAC 角色

amazon-web-services - Terraform:如何确保我在预期的 AWS 账户上运行 terraform

azure - 是否有用于将逻辑应用程序绑定(bind)到 OMS 工作区的 ARM 模板解决方案?

Azure 资源管理器 - 将值转换为 'lower'

Azure 端点监控 - 内存使用情况

azure - 在参数文件中动态添加API连接

azure - 如何通知新的 Azure AD B2C 用户注册或登录使用 azure 函数 HTTP 触发器注册的应用程序?