-1

Getting issue in ARM template while configuring backendHttpSettingsCollection. 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.

Is there any way we can Implement both condition in same ARM template.

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

old_timer
  • 69,149
  • 8
  • 89
  • 168
AUGgn
  • 47
  • 8
  • @old_timer , May I know the reason for your negative vote ? I am stuck with this issue please see you can help on this. I wanted to implement ARM with true and false value of pickHostNameFromBackendAddress in single template, – AUGgn Sep 02 '20 at 04:04

2 Answers2

0

I can reproduce the same error. It cannot pass the template validation even if the null or blank value is assigned to 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. 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'))]"
                            }
Levi Lu-MSFT
  • 27,483
  • 2
  • 31
  • 43
  • This will not make a difference as when you pick pickHostNameFromBackendAddress as true ARM will not allow you to use HostName property in template. We can only provide HostName when we have pickHostNameFromBackendAddress as false. – AUGgn Sep 02 '20 at 09:05
  • actually problem is this error : "code": "ApplicationGatewayBackendHttpSettingsHostNameFieldConflict", "message": "HostName field may only be specified if pickHostNameFromBackendAddress is set to false in context.. we can not specify HostName property if pickHostNameFromBackendAddress is set as true , even the null or blank value is not permitted – AUGgn Sep 03 '20 at 12:17
  • I see the problem. You can check out the workaround above. – Levi Lu-MSFT Sep 04 '20 at 07:43
  • Thanks, I have taken it as variable as I need to support more then one Item in array, – AUGgn Sep 04 '20 at 14:09
0

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

AUGgn
  • 47
  • 8
  • I am facing the same issue. Could you share the whole template? Thanks in advance! – Erik Jul 22 '21 at 08:26
  • Getting the following Error: Code=InvalidTemplate; Message=Deployment template validation failed: 'The template variable 'backendHttpSettingsCollectionWithHost' is not valid: The language expression property 'hostname' doesn't exist, available properties are 'name, port, protocol, cookieBasedAffinity, pickHostNameFromBackendAddress, affinityCookieName, requestTimeout, probe'.. Please see https://aka.ms/arm-template-expressions for usage details.'. This is because I do not always set the hostname. If I choose hostname: "" it will pick the configuration with hostname parameter. – Erik Jul 22 '21 at 10:07
  • HI @Erik , not able to post full template here, First block of code is part of variable, and last block is used in property. – AUGgn Aug 02 '21 at 16:43
  • You only have one backendHttpSettingsCollection per deployment? I have an array with combination of with and without hostname. variables('pickHostNameFromBackendAddress')[0]; This only looks at the first one. – Erik Aug 03 '21 at 09:35