'How to get AKS nodepool vnet in Bicep

Existing AKS nodepool information

Nodepool Virtual network: managed

Nodepool subnet: managed


In Bicep script I want to create a private endpoint to connect AKS to Azure Redis service, so I tried to get vnet name and subnetId of the nodepool.

// Get existing k8s cluster
resource cluster 'Microsoft.ContainerService/managedClusters@2022-01-02-preview' existing = {
  name: clusterName
}

// Get existing k8s agent pool
resource agentPool 'Microsoft.ContainerService/managedClusters/agentPools@2022-01-02-preview' existing = {
  parent: cluster
  name: agentPoolName
}

// create private endpoint
resource redisPrivateEndpoint 'Microsoft.Network/privateEndpoints@2020-07-01' = {
  name: 'redis-pe'
  location: location
  properties: {
    subnet: {
      id: agentPool.properties.vnetSubnetID
    }
    privateLinkServiceConnections: [
      {
        name: 'redis-connection'
        properties: {
          privateLinkServiceId: redis.id
          groupIds: [
            'redisCache'
          ]
        }
      }
    ]
  }
}

There are two problems

  1. There is an error message telling me the value of agentPool.properties.vnetSubnetID doesn't exist
  2. There is no way to get Vnet name using something like, agentPool.properties.vnet

Any feedback will be appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source