mercredi 17 février 2021

Azure Devops ARM Nested Resource copy function skip if null (Frontdoors arm template)

I have a deployment, where one routing rule is referencing two frontend ID's,

Parameter section below has an array, my thinking is to have Frontend1 as the second ID, and use a conditional if statement. But I do not know how to have a if statement on a nested {} resource, where I want to ignore deploying the 2nd Brackets frontend ID, if the value is null. Below is an example of two routing rules, one has a value, one is null.

        "routingRule":{
            "value": [
                {
                    "Frontend": "sitename",
                    "name": "site-name",
                    "backendPool": "pool-sitename",
                    "id": "sitename",         
                    "forwardingProtocol": "HttpsOnly",            
                    "frontend": "sitename.com"
                    "frontend1": "www.sitename.com"
                }, 
                {
                    "Frontend": "sitename1",
                    "name": "site-name1",
                    "backendPool": "pool-sitename1",
                    "id": "sitename1",         
                    "forwardingProtocol": "HttpsOnly",            
                    "frontend": "sitename1.com"
                    "frontend1": ""
                }


Arm Template

                {
                    "name":"routingRules",
                    "count": "[length(parameters('routingRule'))]",
                    "input": {
                    "name": "[concat(parameters('routingRule')[copyIndex('routingRules')].name)]", 
                    "id": "[concat(resourceId('Microsoft.Network/frontdoors', parameters('FD').name), '/routingRules/', parameters('routingRule')[copyIndex('routingRules')].name)]",
                    "properties": {
                        "frontendEndpoints": [
                            {
                                "id": "[concat(resourceId('Microsoft.Network/frontdoors', parameters('FD').name), '/FrontendEndpoints/', parameters('routingRule')[copyIndex('routingRules')].Frontend)]"
                            
                            }
                                                            {
                                "id": "[concat(resourceId('Microsoft.Network/frontdoors', parameters('FD').name), '/FrontendEndpoints/', parameters('routingRule')[copyIndex('routingRules')].Frontend1)]"
                            
                            }
                        ],
                        "acceptedProtocols": [
                            "Http",
                            "Https"
                        ],
                        "patternsToMatch": [
                            "/*"
                        ],
                        "enabledState": "Enabled",
                        "resourceState": "Enabled",
                        "routeConfiguration": {
                            "@odata.type": "#Microsoft.Azure.FrontDoor.Models.FrontdoorForwardingConfiguration",
                            "forwardingProtocol": "[concat(parameters('routingRule')[copyIndex('routingRules')].forwardingProtocol)]", 
                            "backendPool": {
                                "id": "[concat(resourceId('Microsoft.Network/frontdoors', parameters('FD').name), '/BackendPools/', parameters('routingRule')[copyIndex('routingRules')].backendPool)]"
                            }
                        },
                        "rulesEngine": {
                           "id": "[toLower(variables('rulesEngine'))]"                            
                    } }
                    }
                }  

any ideas how I can perform this loop and skip over null resources?

As a side note, i have had success skipping the value entirely in a Network Security Rule deployment, but only when its a if it exists, create otherwise skip parameter entirely, in this scenario I was not sure how to pull the final value from the param array, so referenced it in the variables section

    "variables": {
    "nsg1": {
        "id": "[resourceId('Microsoft.Network/networkSecurityGroups',parameters('nsg1'))]"
    }       
    },


                    "properties": {
                        "addressPrefix": "[concat(parameters('subnet')[copyIndex('subnets')].addressPrefix)]",    
                        "networkSecurityGroup": "[if(equals(parameters('subnet')[copyIndex('subnets')].networkSecurityGroupName, 'yes'), variables('nsg1'), json('null'))]"              
                    }
                }   

Aucun commentaire:

Enregistrer un commentaire