hashicorp / terraform-provider-azuread

Terraform provider for Azure Active Directory
https://registry.terraform.io/providers/hashicorp/azuread/latest/docs
Mozilla Public License 2.0
417 stars 283 forks source link

azuread_directory_role_eligibility_schedule_request returning RoleNotFound on creation #1356

Open Fodsuk opened 3 months ago

Fodsuk commented 3 months ago

Community Note

Terraform (and AzureAD Provider) Version

Affected Resource(s)

Terraform Configuration Files

resource "azuread_custom_directory_role" "iam" {

  display_name = "My Directory Role"
  description  = "My Directory Role"
  enabled      = true
  version      = "1.0"

  permissions {
    allowed_resource_actions = [
      "microsoft.directory/applications/basic/update",
      "microsoft.directory/applications/create",
      "microsoft.directory/applications/standard/read",
    ]
  }

}

resource "azuread_directory_role_eligibility_schedule_request" "iam" {
  role_definition_id = azuread_custom_directory_role.iam.object_id
  # principal id (you would need to source one in your own Entra)
  principal_id       = "3ed50089-5811-4504-a7c3-d04d64047eb7"
  directory_scope_id = "/"
  justification      = "create eligibility schedule request"
}

Debug Output

Panic Output

Expected Behavior

The eligibility role assignment is created

Actual Behavior

The custom role isn't found and the following error fails

Error: Eligibility schedule request for role "1d13bcc2-3044-42df-ac26-0ef2b1b762de" to principal "3ed50089-5811-4504-a7c3-d04d64047eb7", received 404 with error: RoleEligibilityScheduleRequestClient.BaseClient.Post(): unexpected status 404 with OData error: RoleNotFound: The role is not found.
β”‚
β”‚   with azuread_directory_role_eligibility_schedule_request.iam,
β”‚   on directory_role_assignment.tf line 18, in resource "azuread_directory_role_eligibility_schedule_request" "iam":
β”‚   18: resource "azuread_directory_role_eligibility_schedule_request" "iam" {
β”‚
β”‚ RoleEligibilityScheduleRequestClient.BaseClient.Post(): unexpected status 404 with OData error: RoleNotFound: The role is not found.

Steps to Reproduce

  1. terraform apply

Important Factoids

I have tried adding a wait provisioner to the custom directory role creation

resource "azuread_custom_directory_role" "iam" {

  display_name = "My Directory Role"
  description  = "My Directory Role"
  enabled      = true
  version      = "1.0"

  permissions {
    allowed_resource_actions = [
      "microsoft.directory/applications/basic/update",
      "microsoft.directory/applications/create",
      "microsoft.directory/applications/standard/read",
    ]
  }

  # wait 10 minutes for role to be ready
  provisioner "local-exec" {
    command     = "Start-Sleep 600"
    interpreter = ["pwsh", "-Command"]
  }

}

References

nbaju1 commented 2 months ago

Does the same thing happen if you only include the custom role in the initial apply, then add in the azuread_directory_role_eligibility_schedule_request afterwards?

Gaarindor commented 2 months ago

I am now getting a few other issues with the same configuration on every single apply (so initial and adding afterwards):

Working:

azurerm has some similar issues as well.

I have imported with the same resource names, no change.