简体   繁体   English

Azure 应用程序网关 ARM 后端 HttpSettingsCollection 中 pickHostNameFromBackendAddress 和主机名的模板问题

[英]Azure Application gateway ARM template issue with pickHostNameFromBackendAddress and hostname in backendHttpSettingsCollection

Getting issue in ARM template while configuring backendHttpSettingsCollection.配置 backendHttpSettingsCollection 时出现 ARM 模板问题。 I can not use pickHostNameFromBackendAddress for both condition (true, false ), If we select True then it is throwing eror for hostname, I tried applying json('null'), but still it is throwing the same error.我不能将 pickHostNameFromBackendAddress 用于这两个条件(true,false),如果我们 select True 那么它会为主机名抛出错误,我尝试应用 json('null'),但它仍然抛出相同的错误。

Is there any way we can Implement both condition in same ARM template.有什么办法可以在同一个 ARM 模板中实现这两个条件。

Template:模板:

{
        "name": "backendHttpSettingsCollection",
        "count": "[length(parameters('backendHttpSettings'))]",
        "input": {
          "name": "[parameters('backendHttpSettings')[copyIndex('backendHttpSettingsCollection')].name]",
          "properties": {
            "port": 443,
            "pickHostNameFromBackendAddress": "[parameters('backendHttpSettings')[copyIndex('backendHttpSettingsCollection')].pickHostNameFromBackendAddress]",
            "hostName": "[if(parameters('backendHttpSettings')[copyIndex('backendHttpSettingsCollection')].pickHostNameFromBackendAddress, json('null') , parameters('backendHttpSettings')[copyIndex('backendHttpSettingsCollection')].hostName)]",
            "protocol": "Https",
            "probeEnabled": "[parameters('backendHttpSettings')[copyIndex('backendHttpSettingsCollection')].probeEnabled]",
            "probe": {
              "id": "[resourceId('Microsoft.Network/applicationGateways/probes',  parameters('applicationGatewayName'), parameters('backendHttpSettings')[copyIndex('backendHttpSettingsCollection')].probe)]"
            }
          }
        }
      },

Parameter:范围:

 {
      "name": "https-test1",
      "hostName": "",
      "probeEnabled": true,
      "pickHostNameFromBackendAddress": true,
      "probe": "slash-probe1"
    },

Thanks谢谢

I can reproduce the same error.我可以重现同样的错误。 It cannot pass the template validation even if the null or blank value is assigned to hostName .即使将 null 或空值分配给hostName也无法通过模板验证。

As a workaround, You can have a try wrapping all the properties in a parameter object. Define two object parameters for the true and false scenario.作为解决方法,您可以尝试将所有属性包装在参数 object 中。为 true 和 false 场景定义两个 object 参数。 See below example:请参阅以下示例:

 "parameters": {
               "pick": {
                  "type": "bool",
                  "defaultValue": true
               },
               "host": {
                  "type": "string",
                  "defaultValue": "leviCustom.com"
               },
            "pickFalse":{
                "type": "object",
                "defaultValue":{
                    "port": 443,
                    "protocol": "Https",
                    "cookieBasedAffinity": "Disabled",
                    "hostName": "[parameters('host')]",
                    "pickHostNameFromBackendAddress": false,
                    "requestTimeout": 20
                }
            },
            "pickTrue":{
                "type": "object",
                "defaultValue":{
                    "port": 443,
                    "protocol": "Https",
                    "cookieBasedAffinity": "Disabled",
                    "pickHostNameFromBackendAddress": true,
                    "requestTimeout": 20
                }
            }
        },

"backendHttpSettingsCollection": [
                            {
                                "name": "LeviHttpSetting",
                                "properties": "[if(parameters('pick'),parameters('pickTrue'),parameters('pickFalse'))]"
                            }

taken Properties as variable like below:将属性作为变量,如下所示:

"copy": [
  {
    "name": "backendHttpSettingsCollectionWithHost",
    "count": "[length(parameters('backendHttpSettings'))]",
    "input": {
      "name": "[parameters('backendHttpSettings')[copyIndex('backendHttpSettingsCollectionWithHost')].name]",
      "properties": {
        "port": 443,
        "hostName": "[parameters('backendHttpSettings')[copyIndex('backendHttpSettingsCollectionWithHost')].hostname]",
        "protocol": "Https",
        "probeEnabled": "[parameters('backendHttpSettings')[copyIndex('backendHttpSettingsCollectionWithHost')].probeEnabled]",
        "probe": {
          "id": "[resourceId('Microsoft.Network/applicationGateways/probes',  parameters('applicationGatewayName'), parameters('backendHttpSettings')[copyIndex('backendHttpSettingsCollectionWithHost')].probe)]"
        }
    }
  },
  {
    "name": "backendHttpSettingsCollectionWithoutHost",
    "count": "[length(parameters('backendHttpSettings'))]",
    "input": {
      "name": "[parameters('backendHttpSettings')[copyIndex('backendHttpSettingsCollectionWithoutHost')].name]",
      "properties": {
        "port": 443,
        "pickHostNameFromBackendAddress": "[parameters('backendHttpSettings')[copyIndex('backendHttpSettingsCollectionWithoutHost')].pickHostNameFromBackendAddress]",
        "protocol": "Https",
        "probeEnabled": "[parameters('backendHttpSettings')[copyIndex('backendHttpSettingsCollectionWithoutHost')].probeEnabled]",
        "probe": {
          "id": "[resourceId('Microsoft.Network/applicationGateways/probes',  parameters('applicationGatewayName'), parameters('backendHttpSettings')[copyIndex('backendHttpSettingsCollectionWithoutHost')].probe)]"
        }
      }
    }
  }

and used in application gateway properties as below:并在应用程序网关属性中使用如下:

"backendHttpSettingsCollection": "[if(variables('pickHostNameFromBackendAddress')[0], variables('backendHttpSettingsCollectionWithoutHost') , variables('backendHttpSettingsCollectionWithHost'))]",
    

this is working for both conditions这适用于两种情况

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

相关问题 如何通过Azure ARM模板将证书上传到应用程序网关 - How to upload a certificate to Application gateway through Azure ARM Template 将 Url 规则从不同的 ARM 模板添加到 Azure 应用程序网关 - Add Url Rule to Azure Application Gateway from a different ARM template 从 azure 查询 azure 应用程序网关设置或整个 ARM 模板 - Query azure application gateway settings or whole ARM template from azure Azure ARM模板问题 - Azure ARM template issue 具有专用IP地址的Application Gateway ARM模板 - Application Gateway ARM Template with Private IP Address 如何使用 AGIC 将主机名分配给 Azure 应用程序网关 - How to assign an hostname to an Azure Application Gateway with AGIC 应用程序网关ARM模板-用于启用防火墙的参数 - Application Gateway ARM Template - Parameter for Enabling Firewall 在 Azure 中的应用程序网关的 ARM 中获取动态 IP - Fetching dynamic IP in ARM of Application gateway in Azure 尝试使用ARM模板在Azure中部署应用程序网关,但在创建时无法引用侦听器 - Trying to deploy an application gateway in azure with ARM template but it can't refernece the Listener at creation ARM模板中的Azure Application Insights警报规则 - Azure Application Insights Alert Rule in ARM Template
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM