microsoft / powerplatform-build-tools

Power Platform Build Tools automate common build and deployment tasks related to Power Platform. This includes synchronization of solution metadata (a.k.a. solutions) between development environments and source control, generating build artifacts, deploying to downstream environments, provisioning/de-provisioning of environments, and the ability to perform static analysis checks against your solution using the PowerApps checker service.
MIT License
186 stars 38 forks source link

'Requested instance not found' error when running pac admin assign-user #983

Open ramontebar opened 2 months ago

ramontebar commented 2 months ago

Describe the bug We are getting the following error when running pac admin assign-user

{"errors":[{"Subject":"Result","Description":"Requested instance 80de3309-2d49-ef11-bfdf-000d3a53722e not found","Code":"instanceNotFound"},{"Subject":"InnerException","Description":null,"Code":null},{"Subject":"AdditionalData","Description":null,"Code":null}],"information":[{"Subject":"Result","Description":"[\"SyncMode: Default\",\"Requested instance 80de3309-2d49-ef11-bfdf-000d3a53722e not found\"]","Code":"instanceNotFound"},{"Subject":"AdditionalResultDetails","Description":"","Code":null},{"Subject":"RequestId","Description":"81c1fd0b-f078-4cce-942e-e3b0dbd4b476","Code":null},{"Subject":"CorrelationId","Description":"c99335ef-ec6d-4661-892e-774cad03980f","Code":null},{"Subject":"SystemUserId","Description":null,"Code":null},{"Subject":"SecurityGroupId","Description":null,"Code":null},{"Subject":"Timestamp","Description":"7/24/2024 10:57:07 AM","Code":null}]}

To Reproduce Steps to reproduce the behavior:

1. Log in with a service principal

pac auth create `
 --applicationId $appId `
 --clientSecret $secret `
 --tenant $tenantId

2. Create a Developer environment

$newEnvironmentResponseJSON = pac admin create `
 --name $environmentName `
 --type 'Developer' `
 --user $userID `
 --async false `
 --json

$newEnvironmentDetails = $newEnvironmentResponseJSON | ConvertFrom-Json
$newEnvironmentID = $newEnvironmentDetails.EnvironmentId

3. Add user to environment as System Administrator

pac admin assign-user `
 --environment $newEnvironmentID `
 --user $userID `
 --role 'System Administrator'

Expected behavior The command pac admin assign-user should run successfully and add the user to the new environment as a System Administrator.

Please notice this error doesn't happen always. It happens right just after the environment has been created. If we wait 10-30 minutes after the environment has been created, it works.

PAC CLI Version 1.32.8+gf89d946

Powershell Version 7.4.2