-
Notifications
You must be signed in to change notification settings - Fork 478
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Forced Replacement of azurerm_role_assignment Resource Due to principal_id Evaluation Order in terraform-azurerm-aks Module #617
Comments
Hi team, |
@morbendor why you are passing both
|
@morbendor you can remove from the Terraform docs:
You don't need the following block: Lines 525 to 532 in 2e3c548
So you don't need to pass Lines 343 to 350 in 2e3c548
|
Please use a valid configuration and let us know if this problem is still reproducible. Thanks |
Even if I don't explicitly use the client_id variable (as shown here), I still receive a message indicating that the resource will be force-replaced. This seems to happen because the resource relies on some data to determine the principal_id.
As a result, every time I run terraform plan or terraform apply, it triggers a force-replace action.
|
I cannot reproduce it on my greenfield installation. I wonder if you have something in your terraform state that triggers this replacement. Could you please use the command
and
What do you see ? Thanks |
module.aks_ods01.cluster_identity
azurerm_user_assigned_identity.main
I believe my principal ID is being sourced from this data reference:
|
I am not able to reproduce it. @lonegunmanb can you please also have a look. Thanks |
If you're available, we can arrange a meeting to debug this issue using my code in a new environment that we'll create. Thanks! |
Is there an existing issue for this?
Greenfield/Brownfield provisioning
greenfield
Terraform Version
1.9.2
Module Version
9.2.0
AzureRM Provider Version
3.117.0
Affected Resource(s)/Data Source(s)
azurerm_role_assignment.network_contributor_on_subnet
Terraform Configuration Files
tfvars variables values
Debug Output/Panic Output
Expected Behaviour
When using the terraform-azurerm-aks module with a specified var.client_id and identity_type = "UserAssigned":
1.No Replacement:
The azurerm_role_assignment.network_contributor_on_subnet resource should not be flagged for replacement during each terraform plan or terraform apply if var.client_id remains unchanged.
Consistent Principal ID:
The principal_id in the azurerm_role_assignment should use var.client_id directly if provided, avoiding reliance on data sources or computed values that are resolved only after apply.
Idempotent Plans:
Subsequent terraform plan runs after an initial apply should indicate no changes if the configuration has not been altered.
By ensuring the principal_id prioritizes var.client_id, the module's behavior becomes predictable and avoids unnecessary resource replacements.
Proposed Change:
Actual Behaviour
When using the terraform-azurerm-aks module (version 9.2.0) with identity_type = "UserAssigned" and providing var.client_id:
Forced Replacement:
During each terraform plan, the azurerm_role_assignment.network_contributor_on_subnet resource is flagged for replacement due to the principal_id being derived from data sources that are not resolved until apply. This happens even when var.client_id remains the same.
Unresolved Data Dependency:
The try(data.azurerm_user_assigned_identity.cluster_identity[0].principal_id, azurerm_kubernetes_cluster.main.identity[0].principal_id) evaluation occurs before terraform apply, causing the principal_id to be marked as (known after apply).
Non-Idempotent Plans:
Subsequent terraform plan runs continue to show changes due to the azurerm_role_assignment resource needing to be replaced, even when no configuration changes have been made.
This behavior leads to unnecessary resource replacements and disrupts the efficiency and predictability of deployments.
Current Code:
Steps to Reproduce
No response
Important Factoids
No response
References
No response
The text was updated successfully, but these errors were encountered: