terraform-provider-azurerm: r/kubernetes_cluster: api returns InvalidIdentityValues during update
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 0.14.5 (same behaviour with 0.14.4) Azurerm 2.45.0 (same behaviour with 2.44.0)
Affected Resource(s)
azurerm_kubernetes_clusterwhen using identity.type=âUserAssignedâ
Terraform Configuration Files
resource "azurerm_user_assigned_identity" "aks" {
resource_group_name = "myresourcegroup"
location = "francecentral"
name = "mycluster-identity"
}
resource "azurerm_kubernetes_cluster" "aks" {
name = "mycluster"
location = "francecentral"
resource_group_name = "myresourcegroup"
node_resource_group = "myresourcegroup-nodes"
identity {
type = "UserAssigned"
user_assigned_identity_id = azurerm_user_assigned_identity.aks.id
}
network_profile {
network_plugin = "kubenet"
network_policy = "calico"
load_balancer_sku = "Standard"
outbound_type = "userDefinedRouting"
...
}
private_cluster_enabled = false
kubernetes_version = "1.18.14"
addon_profile {
...
}
default_node_pool {
...
enable_auto_scaling = true
min_count = 3
max_count = 18
}
Debug Output
Error: updating Managed Kubernetes Cluster "mycluster" (Resource Group "myresourcegroup"): containerservice.ManagedClustersClient#CreateOrUpdate: Failure sending request: StatusCode=400 -- Original Error: Code="InvalidIdentityValues" Message="Invalid value for the identities '/subscriptions/xxxxxxxxx/resourceGroups/myresourcegroup/providers/Microsoft.ManagedIdentity/userAssignedIdentities/mycluster-identity'. The 'UserAssignedIdentities' property keys should only be empty json objects, null or the resource exisiting property."
on aks.tf line 1, in resource "azurerm_kubernetes_cluster" "aks":
1: resource "azurerm_kubernetes_cluster" "aks" {
Expected Behaviour
The creation of azurerm_kubernetes_cluster worked without any problem. When I change a simple property (not related with user assigned identity), like default_node_pool.min_count I would expect the apply to not raise issues with UserAssignedIdentities
Actual Behaviour
The creation of azurerm_kubernetes_cluster worked without any problem. When I change a simple property like default_node_pool.min_count or any other, I receive the error reported in Debug Output section.
Steps to Reproduce
- Create a cluster with user assigned identity (of course via terraform)
- Change an azurerm_kubernetes_cluster property such as default_node_pool.min_count
terraform plan, no problem in the planterraform applyand approve : error raised here
References
Using UserAssigned identity, a feature released in 1.44.0 (https://github.com/terraform-providers/terraform-provider-azurerm/pull/8737/files)
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 36
- Comments: 24 (4 by maintainers)
Quote from Azure support:
The workaround works because it triggers the update logic for
identityproperty. If terraform thinks theidentityproperty is updated, it will generate a correctidentitybody. Any letter case change can trigger this updating logic. Related code part: https://github.com/terraform-providers/terraform-provider-azurerm/blob/v2.49.0/azurerm/internal/services/containers/kubernetes_cluster_resource.go#L1120https://github.com/terraform-providers/terraform-provider-azurerm/blob/v2.49.0/azurerm/internal/services/containers/kubernetes_cluster_resource.go#L1835
This can be a temporary workaround before the issue is fully fixed.
Personally, I would like a fix in azure-sdk-for-go to permanently fix this. The reason for this issue is introduced in this comment: https://github.com/terraform-providers/terraform-provider-azurerm/issues/10406#issuecomment-791930148 . In AKSâs swagger, we have defined
userAssignedIdentities.additionalProperties.properties.principalIdanduserAssignedIdentities.additionalProperties.properties.clientIdas readonly. In the specification, readonly is defined as:It should be SDKâs responsibility to handle this part of work. Itâs quite common for developers to GET an object and then PUT it, itâs not reasonable to let SDK user to manually handle this. For some language, such as python, the auto-generated SDK already has the ability to set readonly properties to none before sending the request, but thatâs not the case for go. I think some manual work need to be done in azure-sdk-for-go, the related issue: https://github.com/Azure/azure-sdk-for-go/issues/14478
Also, this worked for me without having to write out the whole id string.
This worked for me as well. Thank you @BartVanBerkel and @aging-dh Cheers!
I can confirm that the workaround works, but I end up in the same issue as with #11223 that it wants to do an update each time I run terrafrom apply asit wants to change the user_assigned_identity_id from resourceGroups to resourcegroups.
We have exactly the same issue as described here and opened a ticket with MSFT (ref. 2104080050000277)
After some testing the MSFT engineer discovered that the resourceId of the identity contains a uppercase
ginresourcegroups.Working MI ID: â/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourcegroups/my_rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/my_identityâ
Non-working MI ID: â/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx/resourceGroups/my_rg/providers/Microsoft.ManagedIdentity/userAssignedIdentities/my_identityâ
So if I use the following configuration (see below) it will actually deploy and update.
In #10296 the resourceId has been changed to have the uppercase
G⌠Azure isnât really clear whether it should contain agorG. Because if you look in the portal at the properties of the user assigned identity resource it will show you the resourceId with aG. But when you use powershell of az-cli to see the resourceId it will show you the lowercaseg.Please do note that I donât consider this as a good workaround⌠But hopefully it shines a light on what is going wrong here.
I forgot to update⌠but you are 100% correct. In some update scenarios the âworkaroundâ doesnât work. As said: âPlease do note that I donât consider this as a good workaroundâŚâ
Sorry for the thumbs down! I just wanted to flag that the work around is not working for me. Iâm still getting the original
The 'UserAssignedIdentities' property keys should only be empty json objects, null or the resource exisiting property.error.Is there a link to the Microsoft ticket so we can track it?