Skip to content

Failure to enumerate environment in CreateSubnetInjectionEnterprisePolicy.ps1 #646

Open
@markdepalma

Description

@markdepalma

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
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions