-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
azurerm_pim_eligible_role_assignment fails with nil error on only two resources from mapped variable #22513
Comments
Reproducible with same intermittent behaviour, affects groups and only some groups intermittently. |
We lost our P2 license, after getting it back, all previous created azurerm_pim_eligible_role_assignment resources are throwing: |
I am intermittently getting this error - I can create it if the PIM assignment is not already present in most cases, but in others it just still gives a nil error. Edit: just noticed something interesting. The one team that was giving me problems had the same PIM role already present as active, rather than eligible. Not sure how that came to pass. After removing the active role by going to the resource group in question and removing it from IAM, it still throws the nil error here. In the end, I had to edit the state file manually to remove the index key item for azurerm_pim_eligible_role_assignment for the index key throwing the nil error. Doing so allowed TF to proceed and create the role successfully. I'm guessing all of this was leftovers from when TF was still having issues from earlier versions of this resource provider. @sorenhuus If you check in the portal, are the PIM assignments still present for the scopes in question? If so, are you able to destroy them via TF? |
@MohnJadden Removing the resources from state works for me as well, but not permanently. In my experience I get this problem every time I run a terraform plan after the scheduled expiration time is exceeded, which is problematic when I need to extend my terraform configuration to create new eligible role assignments. Does anyone have the same experience using |
I am seeing the same behavior as @kristeey - Every 3month we are hacking away at the state file to re-apply the pim roles. |
@MohnJadden They are there in the portal, on apply I get "A resource with the ID xxxxxxxxxxxx already exists - to be managed via Terraform this resource needs to be imported into the State...", so something must have been removed from the state. If I then delete the pim assignments form the portal. Terraform fails refreshing on the plan step. So something must still be in the state. |
yes we are facing the same issue and hence we stopped using the terraform PIM resource and reverted back to bash script |
Gotcha - the only other thing I can think of is to try terraform state list and see if the PIM resource is already present, then use terraform state rm to remove it. If it's not in terraform state list, maybe it's still in the state file and require manual removal. Unfortunately none of this fixes the root cause - Terraform somehow misses picking up the existing resource, the import dialog for the PIM resource provider behaves oddly and isn't well scoped or documented for Windows, and it doesn't cleanly add/remove. The other complication is by PIM eligible vs. PIM active, and the fact that we can't do PIM assignment settings - those have to happen in the portal. Honestly, speaking as someone who doesn't really do much TF and has been trying to undertake more in TF rather than in the Azure portal - this is something we only do once per resource group or subscription, and the fact that we have existing manual steps to fill the gap, this is just not a feature that anyone thought of as anything other than the 1-year block. Hopefully they put in fixes for this issue and the others but it just seems like PIM for Azure resources is just not as sexy a feature for TF to add functionality from end to end. |
I made a small PS script that takes the raw Azure DevOps log, with the failed applies from the azurerm_pim_eligible_role_assignment resources, and deletes them. After thats done, plan and apply can be run without errors. Its not refined in anyway. Hope it helps someone.
|
Is there an existing issue for this?
Community Note
Terraform Version
1.5.3
AzureRM Provider Version
3.64.0
Affected Resource(s)/Data Source(s)
azurerm_pim_eligible_role_assignment
Terraform Configuration Files
Debug Output/Panic Output
Expected Behaviour
All teams in the mapped variable contained within our tfvars file should have the Virtual Machine Administrator Login created as an Azure AD PIM eligible role for each resource group created in the configuration as specified.
Actual Behaviour
Terraform throws "Error: retrieving Role Management Policy" for only teams 4 and 11 and ends. No changes are made. The full text of the error is given in the gists linked above.
Steps to Reproduce
Important Factoids
Nothing further, just a standard Azure tenant
References
No response
The text was updated successfully, but these errors were encountered: