How to get vnetSubnetID from ARM template output of AKS cluster

Thiyagu Rajendran 1 Reputation point
2021-10-29T05:22:25.927+00:00

I have used ARM template to create private AKS cluster which automatically creates a virtual network. In the same virtual network subnet, I want to deploy few more resources using the subnetID from the previous AKS creation step.

The below mentioned outputs of ARM template results in error

"outputs": {
"clusterSubnetId": {
"type": "string",
"value": "[reference(variables('gwname'), '2021-08-01', 'Full').properties.agentPoolProfiles[0].vnetSubnetID]"
}
}

Error says vnetSubnetID is not a valid property.

Azure Kubernetes Service
Azure Kubernetes Service
An Azure service that provides serverless Kubernetes, an integrated continuous integration and continuous delivery experience, and enterprise-grade security and governance.
2,447 questions
{count} votes

1 answer

Sort by: Most helpful
  1. shiva patpi 13,366 Reputation points Microsoft Employee Moderator
    2021-11-01T02:54:27.207+00:00

    Hello @thiyagu rajendran ,
    You might have to define the vnetname , subnetname

    "VnetName": {
    "type": "string",
    "defaultValue": "vnet",
    "metadata": {
    "description": "The product k8s cluster vnet"
    }
    },
    "SubnetName": {
    "type": "string",
    "defaultValue": "subnet",
    "metadata": {
    "description": "The product k8s cluster subnet name"
    }
    },

    Then in the agent pool properties , you have to define the vnetSubnetID

    "agentPoolProfiles": [
    {
    "name": "agentpool",
    "osDiskSizeGB": 0,
    "count": 1,
    "vmSize": "[parameters('agentVMSize')]",
    "osType": "[parameters('osType')]",
    "storageProfile": "ManagedDisks",
    "vnetSubnetID": "[concat(resourceId('Microsoft.Network/virtualNetworks',parameters('vnetname')),'/subnets/',parameters('subnetname'))]"
    }

    Then you can use the : properties.agentPoolProfiles[0].vnetSubnetID

    If you are still facing the issue , kindly share the complete template which is used to create Private AKS Cluster + Along with another template which are used to create other resources.

    Couple of references:
    https://learn.microsoft.com/en-us/azure/templates/Microsoft.ContainerService/2019-02-01/managedClusters?tabs=json#quickstart-templates
    https://learn.microsoft.com/en-us/azure/azure-resource-manager/templates/outputs?tabs=azure-powershell

    FYI:
    In the template which you have shared , in the outputs section you are using a variable "testcluster" which is not defined as a part of Variables section the ARM template , it was defined in the Resources section which you can't reference by variables.

    "outputs": {
    "clusterSubnetId": {
    "type": "string",
    "value": "[reference(variables('testcluster'), '2021-08-01', 'Full').properties.agentPoolProfiles[0].vnetSubnetID]"
    }
    }

    Regards,
    Shiva.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.