According to the documentation:
https://docs.microsoft.com/en-us/azure/aks/configure-azure-cni#prerequisites
The cluster identity used by the AKS cluster must have at least Network Contributor permissions on the subnet within your virtual network.
The terraform-azurerm-aks module by default does not take care of this, and when I tried to create a Service of type: LoadBalancer I had this issue:
Events:
Type Reason Age From Message
---- ------ ---- ---- -------
Normal EnsuringLoadBalancer 4m39s (x16 over 54m) service-controller Ensuring load balancer
Warning SyncLoadBalancerFailed 4m38s (x16 over 54m) service-controller Error syncing load balancer: failed to ensure load balancer: Retriable: false, RetryAfter: 0s, HTTPStatusCode: 403, RawError: {"error":{"code":"AuthorizationFailed","message":"The client 'xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' with object id 'xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx' does not have authorization to perform action 'Microsoft.Network/virtualNetworks/subnets/read' over scope '/subscriptions/xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/fasthackterraform/providers/Microsoft.Network/virtualNetworks/acctvnet/subnets/subnet1' or the scope is invalid. If access was recently granted, please refresh your credentials."}}
This is a very well known issue and I fixed it adding to my Terraform code that calls the module the following resource:
# Grant AKS cluster access to use AKS subnet
resource "azurerm_role_assignment" "aks" {
principal_id = module.aks.system_assigned_identity[0].principal_id
role_definition_name = "Network Contributor"
scope = module.network.vnet_subnets[0]
depends_on = [module.aks]
}
However does it make sense to create this azurerm_role_assignment directly in the terraform-azurerm-aks module ?
According to the documentation:
https://docs.microsoft.com/en-us/azure/aks/configure-azure-cni#prerequisites
The
terraform-azurerm-aksmodule by default does not take care of this, and when I tried to create aServiceoftype: LoadBalancerI had this issue:This is a very well known issue and I fixed it adding to my Terraform code that calls the module the following resource:
However does it make sense to create this
azurerm_role_assignmentdirectly in theterraform-azurerm-aksmodule ?