is there a terraform way I can assign additional UAMI apart from the
one in identity {..} block and use it to access ACR?
According to the details you provided, you can create an additional UAMI and associate it with the AKS cluster kubelet identity, then assign the role to the UAMI, example code here:
resource "azurerm_kubernetes_cluster" "example" {
name = "example-aks1"
location = azurerm_resource_group.example.location
resource_group_name = azurerm_resource_group.example.name
dns_prefix = "exampleaks1"
default_node_pool {
name = "default"
node_count = 1
vm_size = "Standard_D2_v2"
}
identity {
type = "SystemAssigned"
}
kubelet_identity {
client-id = azurerm_user_assigned_identity.kubelet.client_id
object-id = azurerm_user_assigned_identity.kubelet.principal_id
user_assigned_identity_id = azurerm_user_assigned_identity.kubelet.id
}
...
}
resource "azurerm_role_assignment" "acr_for_kubelet" {
principal_id = azurerm_user_assigned_identity.kubelet.client_id
scope = azurerm_container_registry.container_registry.id
role_definition_name = "AcrPull"
}
Update:
Actually, when you create the AKS and enable the system-assigned managed identity, then it will create the two user-assigned identities for the AKS cluster, one is to access other resources, and one is to manage the AKS cluster itself and this one is the kubelet identity.
It doesn't make sense to assign the kubelet identity permission to access the ACR. What you need to do is to assign the AKS identity permission to access the ACR. Or use the secret and service account inside the Kubernetes to access the ACR.