question

ThiyaguRajendran-6719 avatar image
0 Votes"
ThiyaguRajendran-6719 asked shivapatpi-MSFT answered

How to get vnetSubnetID from ARM template output of AKS cluster


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
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @ThiyaguRajendran-6719 ,
Can you attach the full ARM template here ?

Regards,
Shiva.

0 Votes 0 ·

@shivapatpi-MSFT Thanks for the reply. Please find the full template attached145060-akstempalte.log


0 Votes 0 ·
akstempalte.log (2.9 KiB)

1 Answer

shivapatpi-MSFT avatar image
0 Votes"
shivapatpi-MSFT answered

Hello @thiyagurajendran-8290 ,
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://docs.microsoft.com/en-us/azure/templates/Microsoft.ContainerService/2019-02-01/managedClusters?tabs=json#quickstart-templates
https://docs.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.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.