An Azure service that provides fine-grained access management for Azure resources, enabling you to grant users only the rights they need to perform their jobs.
Hello @Sumit Gaur
Your understanding of the lifecycle is correct.
Microsoft.Authorization/roleEligibilityScheduleRequests should be thought of as a request/action resource, rather than the PIM eligibility itself. Creating an AdminAssign request creates the eligible assignment, but deleting that request resource doesn't semantically reverse the operation. Removing the eligibility requires another request with requestType = AdminRemove.
Because of that, don't model roleEligibilityScheduleRequests as a normal Terraform CRUD resource and expect:
terraform destroy → DELETE request resource → eligibility removed
Those operations don't have equivalent semantics.
For Terraform, the preferred abstraction is currently the AzureRM provider's: azurerm_pim_eligible_role_assignment
This resource specifically manages the lifecycle of a PIM Eligible Role Assignment, including scope, role definition, principal, and schedule.
A basic example is:
resource "azurerm_pim_eligible_role_assignment" "example" {
scope = azurerm_resource_group.example.id
role_definition_id = data.azurerm_role_definition.reader.id
principal_id = azuread_group.example.object_id
schedule {
expiration {
duration_days = 365
}
}
}
In other words, AzureRM should own the desired eligibility, while the underlying PIM schedule-request API remains an implementation detail.
Your AzureRM timeout is the issue to investigate, not replacing the resource permanently with an AzAPI roleEligibilityScheduleRequests resource. The fact that eligibility is created successfully but Terraform times out while reading/verifying it suggests a provider/API reconciliation issue rather than a failure of the PIM assignment itself.
Capture the AzureRM provider version, Terraform debug log, assignment scope, principal type, and whether the assignment has an expiration schedule. If the assignment appears successfully in PIM after Terraform times out, that's particularly useful evidence for a HashiCorp AzureRM provider issue.
Before doing anything else, test against the current AzureRM provider release. The Terraform Registry currently documents azurerm_pim_eligible_role_assignment as a supported resource.
If you must use AzAPI as a workaround, don't expect a single azapi_resource representing the AdminAssign request to provide correct destroy semantics. The lifecycle would need to explicitly model:
Create desired eligibility > Submit AdminAssign > Wait/read resulting eligibility > Destroy desired eligibility >Discover current eligibility > Submit AdminRemove > Wait until eligibility disappears
That last step is especially important for idempotency. Verify the resulting eligibility schedule, not whether the original request object still exists.
This request-based model isn't unique to Azure RBAC PIM. Microsoft Graph exposes Entra PIM using the same conceptual separation: roleEligibilityScheduleRequest represents the request, while roleEligibilitySchedule represents the resulting eligibility. Microsoft documents the request API as supporting add, revoke and extend operations rather than ordinary CRUD semantics.
Avoid Terraform local-exec/destroy-time scripts if this is intended to be a long-lived production solution. They make it difficult for Terraform to determine whether AdminRemove completed, failed asynchronously, or was already performed outside Terraform.
So I recommend using azurerm_pim_eligible_role_assignment as the lifecycle resource and troubleshooting/reporting its post-create timeout. Use AzAPI only as a temporary workaround if the AzureRM provider issue blocks you.
If you can provide the AzureRM provider version and the final Terraform error/timeout message, we can narrow down whether you're hitting an existing provider issue or a particular PIM API/state-read condition.
References:
azurerm_pim_eligible_role_assignment - Terraform Registry
Microsoft Graph - Create role eligibility schedule request
Microsoft Graph - List role eligibility schedules
=============================================================================
Help make this community better for everyone: If this answer helped or resolved your issue, please accept it or upvote it. If not, share more details in a comment so we can continue the discussion and find the right solution. Thank you.