Azure / template-specs

MIT License
31 stars 4 forks source link

Issue to reference linked template output values in an AKS node pool definition (value vnetSubnetID) #53

Closed ihommani closed 3 years ago

ihommani commented 3 years ago

Hi, I am currently facing the following issue:

From a linked template called createVnet I set the output poolSubNetId and agwSubNetId which correspond to Vnet subnet Ids. The way I forge them relies on the resourceId ARM template function:

"poolSubNetId": {
            "type": "string",
            "value": "[resourceId('Microsoft.Network/virtualNetworks/subnets',variables('vnet-name'), variables('snetNodePoolName'))]"
        },
        "agwSubNetId": {
            "type": "string",
            "value": "[resourceId('Microsoft.Network/virtualNetworks/subnets',variables('vnet-name'),'snet-applicationgateway')]"
        }

I checked that the strings are Ok on the lone deployment of the linked template through a dedicated template spec.

Now I want to reference these outputs inside inlined resources of the parent ARM template: an app Gateway and an AKS cluster.

It works fine with the application Gateway:

"gatewayIPConfigurations": [
                    {
                        "name": "agwIpConfig",
                        "properties": {
                            "subnet": {
                                "id": "[reference('createVnet').outputs.agwSubNetId.value]"
                            }
                        }
                    }
                ]

However the temp spec deployment fails when I set the vnetSubnetID in the AKS AgentProfile with the error:

"The value of parameter agentPoolProfile.vnetSubnetID is invalid. Please see https://aka.ms/aks-naming-rules for more details.\"
"agentPoolProfiles": [
                    {
                        ...
                        "vnetSubnetID": "[reference('createVnet').outputs.poolSubNetId.value]",
                        ...
                     }

Am I missing something, or is it an issue ?

ihommani commented 3 years ago

Hi, I finally found the issue. I was misusing the reference() function that should point to an entity accessible from the same deployment template. No 'creatVnet' is available so it get something different than an Id (maybe an error message or null output) that is provided as a VnetId; Hence the message. Solution is to pass the Vnet id as a parameter of this deployment template and set the value in the main temlate that orchestrate the linked template (value being an output of a previous Vnet linked deploy).