Closed petegrimsdale closed 3 years ago
Subsequently: This module definition fails to find the resource group for the aks nodes:
param clustername string
var virtualMachineContributorRole = '/subscriptions/${subscription().subscriptionId}/providers/Microsoft.Authorization/roleDefinitions/9980e02c-c2be-4d73-94e8-173b1dc7cf3c'
resource id_clusterName_VMCResourceGroup 'Microsoft.Authorization/roleAssignments@2020-04-01-preview' = {
name: guid('appKubeletIdentityVirtualMachineContributor', resourceGroup().id)
scope: resourceGroup()
properties: {
roleDefinitionId: virtualMachineContributorRole
principalId: reference(resourceId('Microsoft.ContainerService/managedClusters', clustername), '2020-03-01', 'Full').identityProfile.kubeletidentity.objectId
principalType:'ServicePrincipal'
}
}
However if the kubeletidentity.objectId is output from an AKS module and passed to the role assignment this works as:
param aksKubeletIdentityObjectId string
var virtualMachineContributorRole = '/subscriptions/${subscription().subscriptionId}/providers/Microsoft.Authorization/roleDefinitions/9980e02c-c2be-4d73-94e8-173b1dc7cf3c'
resource appKubeletIdentityVirtualMachineContributor 'Microsoft.Authorization/roleAssignments@2020-04-01-preview' = {
name: guid('appKubeletIdentityVirtualMachineContributor', resourceGroup().id)
scope: resourceGroup()
properties: {
roleDefinitionId: virtualMachineContributorRole
principalId: aksKubeletIdentityObjectId
principalType: 'ServicePrincipal'
}
}
I'm a bit lost on what is the latest code you are working with. Can you paste the latest files you are using? From your last statement, it sounds like you may have gotten things working.
@alex-frankel - I have this working now passing the principalId to the module as a parameter solves the issue. Same applies when using an "inner" nested ARM template.
Bicep version 0.3.1
Describe the bug When deploying and AKS cluster resource within a bicep template and using AAD pod identity there is a need to grant the Managed Machine Operator role to the kublet identity on the scope of the AKS resource group. The role assignment is done within bicep module. When this bicep file is built into an ARM template it generates and inner nested template with a scope defined as the aks node resource group as expected. When validating the bicep or ARM files however, the validation or deployment fails with an error stating the aks node resource group does not exist. If the resource group is created in advance then the aks deployment raises an error that the resource group already exists. Error on validate: {"error":{"code":"ResourceGroupNotFound","message":"Resource group 'rg-aksdemo2-aks' could not be found."}}
In ARM this error does not occur when the nested template is defined with outer scope
To Reproduce create a bicep template to deploy AKS resource and module to assign role to the aks node resource group scope - examples below
Additional context Example Bicep file:
Module: