terraform-provider-azurerm: Updates to azurerm_kubernetes_cluster fail when cluster uses managed AAD integration
Community Note
- Please vote on this issue by adding a đ reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave â+1â or âme tooâ comments, they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment
Terraform (and AzureRM Provider) Version
Terraform v0.12.26
- provider.azurerm v2.14.0
Affected Resource(s)
azurerm_kubernetes_cluster
Terraform Configuration Files
resource "azurerm_resource_group" "aks" {
name = "aks-service-rg"
location = "northeurope"
}
resource "azurerm_kubernetes_cluster" "aks" {
name = "aks-service"
location = azurerm_resource_group.aks.location
resource_group_name = azurerm_resource_group.aks.name
node_resource_group = "aks-infra-rg"
dns_prefix = "aks-dev"
enable_pod_security_policy = false
private_cluster_enabled = false
api_server_authorized_ip_ranges = null
default_node_pool {
name = "default"
node_count = 4
vm_size = "Standard_B2ms"
os_disk_size_gb = 30
vnet_subnet_id = var.virtual_network.subnets.aks.id
max_pods = 60
type = "VirtualMachineScaleSets"
}
linux_profile {
admin_username = var.admin_username
ssh_key {
key_data = tls_private_key.aks.public_key_openssh
}
}
role_based_access_control {
enabled = true
azure_active_directory {
managed = true
admin_group_object_ids = [for key, value in local.cluster_admins : value.object_id]
}
}
identity {
type = "SystemAssigned"
}
addon_profile {
azure_policy {
enabled = true
}
oms_agent {
enabled = true
log_analytics_workspace_id = var.log_analytics_workspace.id
}
kube_dashboard {
enabled = true
}
http_application_routing {
enabled = false
}
}
network_profile {
network_plugin = "azure"
network_policy = "azure"
load_balancer_sku = "Basic"
service_cidr = var.kubernetes_service_cidr
docker_bridge_cidr = var.docker_bridge_cidr
dns_service_ip = cidrhost(var.kubernetes_service_cidr, 2)
}
tags = local.tags
}
Debug Output
Panic Output
Expected Behavior
- Enable feature âMicrosoft.ContainerService/AAD-V2â on subscription
- Apply plan to create cluster with managed Azure Active Directory integration
- Change value of tags - or any other argument that doesnât necessitate a replacement of the resource
- Run terraform plan
- Apply plan
- Tags are updated to reflect changes
Actual Behavior
- Enable feature âMicrosoft.ContainerService/AAD-V2â on subscription
- Apply plan to create cluster with managed Azure Active Directory integration
- Change value of tags - or any other argument that doesnât necessitate a replacement of the resource
- Run terraform plan
- Apply plan
- Apply fails with error: -
Error: updating Managed Kubernetes Cluster AAD Profile in cluster âaks-serviceâ (Resource Group âaks-service-rgâ): containerservice.ManagedClustersClient#ResetAADProfile: Failure sending request: StatusCode=400 â Original Error: Code=âBadRequestâ Message=âOperation âresetAADProfileâ is not allowed for managed AAD enabled cluster.â
Steps to Reproduce
- Register feature âMicrosoft.ContainerService/AAD-V2â on subscription as per https://docs.microsoft.com/en-us/azure/aks/managed-aad
terraform planterraform apply- Make changes to resource
terraform planterraform apply
Important Factoids
References
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 35
- Comments: 35 (5 by maintainers)
Iâve implemented a fix and added Acceptance tests to cover the scenarios in this issue.
If nothing goes wrong it will make next release! đ
@tombuildsstuff or anyone can we mayber get this into the next release as a fix? currently it blocks from using the feature as updates to the cluster makes this break.
This has been released in version 2.21.0 of the provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. As an example:
The error message also appears when trying to update Kubernetes version. There are too many issues to even consider a reliable work around, so feature is unusable. Just had to revert to using service principle unfortunately.
This error also occurs when modifying other properties of the cluster such as the max node count on a node pool
error:
@aristosvo I did just like you wrote, I upgraded to AAD-v2 with registering feature.
// I registered AAD-V2 feature az feature register --name AAD-V2 --namespace Microsoft.ContainerService // created AD group for AKS az ad group create --display-name myAKSAdmin --mail-nickname myAKSAdmin // added myself to group az ad group member add --group myAKSAdmin --member-id $id
// Updated cluster groupid=$(az ad group show --groupmyAKSAdmin --query objectId --output tsv) tenantid=$(az account show --query tenantId --output tsv) az aks update -g myaks-rg -n myaks-aks --aad-tenant-id $tenantid --aad-admin-group-object-ids $groupid
I somehow think that terraform can query if AAD is used đ My mistake.
My configuration now (I have to uncomment SPâs)
role_based_access_control { enabled = true azure_active_directory { managed = true // optional: admin_group_object_ids = [âmyAKSAdmin_groupID_not_textâ]
#client_app_id = var.aad_client_app_id #server_app_id = var.aad_server_app_id #server_app_secret = var.aad_server_app_secret tenant_id = var.aad_tenant_id } }
@sutinse1 Can you explain in short what you did before you ended up with the mentioned error?
What I think you did was as follows:
azurerm_kubernetes_clusterwith the setup from the course:AAD-v2via commandlineaz aks update -g myResourceGroup -n myManagedCluster --enable-aador similar.If not, Iâm very curious how your configuration ended up in the state with the error đ
EDIT: This is working fine now, it was my loosing configuration. Thanks aristosvo!
So I added like instructed to main main.tf
WORKED!
I get still error about ResetAADProfile althoug I used v2.21.0 azurerm provider.
Error: updating Managed Kubernetes Cluster AAD Profile in cluster âsutinenseaks-aksâ (Resource Group âsutinenseaks-rgâ): containerservice.ManagedClustersClient#ResetAADProfile: Failure sending request: StatusCode=400 â Original Error: Code=âBadRequestâ Message=âOperation âresetAADProfileâ is not allowed for managed AAD enabled cluster.â
on main.tf line 45, in resource âazurerm_kubernetes_clusterâ âdemoâ: 45: resource âazurerm_kubernetes_clusterâ âdemoâ {
I up terraform.zip graded azurerm provider to 2.21.0 terraform init -upgrade
Upgraded also kubernetes provider 1.11.1 -> 1.12.0, not still working
terraform version Terraform v0.13.0
My try was done according that tutorial https://github.com/Azure/sg-aks-workshop
@tkinz27 your talking about two different things here. The managed AAD integration this issue refers to is related to being able to login to the cluster for admin work as an AAD user, has nothing to do with the clusters access to other resources.
Using managed identity for the cluster identity creates a user assigned managed identity which you can retrieve the name of using the âuser_assigned_identity_idâ of the âkubelet_identityâ block. you would then grant this managed identity access to ACR.
Upgrading provider to 2.21.0 version works đ
resetAADProfile with API version 2020-06-01 seems to support
enableAzureRBAC: https://docs.microsoft.com/en-us/rest/api/aks/managedclusters/resetaadprofile#request-bodySo I guess this could be fixed by using the new API version.
Week late on this buuutt⌠me and a colleague had same error yesterday. We noticed you could update the rbac details via cli so for anyone that wants a workaround while this is being looked at: we deleted the aks cluster, set the role_based_access_control block to
then created a null resource where we update the managed admin ids
However, youâll also need a ignore_change on the aks rbac block
az version: 2.8 azurerm_provider version: 2.15
EDIT: if tags change, it still raises the resetAADProfile error. You can add this to the ignore if that works for you, but obviously you canât update tags (big disadvantage). Unfortunately, there is no az aks update tags options either. Investigating using
az resource tag