Skip to content
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

Failure to enumerate environment in CreateSubnetInjectionEnterprisePolicy.ps1 #646

Open
markdepalma opened this issue Nov 26, 2024 · 0 comments

Comments

@markdepalma
Copy link

markdepalma commented Nov 26, 2024

Ran through a POC setup last week and was having an issue with CreateSubnetInjectionEnterprisePolicy.ps1. The script was failing (404 - Environment not found) when trying to get the Power environment I was specifying in the script.

I traced the issue back to the GetEnvironmentFromBAP function in the EnvironmentOperations.ps1 script. It seems that for some reason the API was not taking the environment ID directly, but I was able to use the same API to enumerate all my environments. I then looked at the PowerApps Administration PowerShell module code to see how they were doing pulling environments in the Get-AdminPowerAppEnvironment cmdlet. In this function they were enumerating all environments (which I had no issues doing) and then filtering by name.

I re-wrote the GetEnvironmentFromBAP function to enumerate all environments and then filter by id and was able to get everything to work after. I'm not sure if pagination comes into play with this API, but we don't have enough environments to hit that. I tried to look more into this BAP API, but was unable to find any real documentation on it.

Original function:

function GetEnvironmentFromBAP ($environmentId, $ApiVersion, $method, $body)
{
    $getEnvironmentUri = "https://{bapEndpoint}/providers/Microsoft.BusinessAppPlatform/environments/{environmentId}/?&api-version={apiVersion}" `
    | ReplaceMacro -Macro "{environmentId}" -Value $environmentId

    $environmentResult = InvokeApi -Method $method -Route $getEnvironmentUri -ApiVersion $ApiVersion -Body $body

    return $environmentResult
}

Modified function:

function GetEnvironmentFromBAP ($environmentId, $ApiVersion, $method, $body)
{
    $getEnvironmentUri = "https://{bapEndpoint}/providers/Microsoft.BusinessAppPlatform/environments/?&api-version={apiVersion}"

    $apiResult = InvokeApi -Method $method -Route $getEnvironmentUri -ApiVersion $ApiVersion -Body $body

    $environmentResult = $apiResult.value | Where {$_.name -eq $environmentId}

    return $environmentResult
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants