# Reaching private endpoints from Power Platform with VNet injection

## Introduction

Say you're running Power Automate flows, and part of a flow needs to read a secret. That secret is stored in an Azure Key Vault with public network access disabled, reachable only through a private endpoint. By default, Power Platform calls Azure services from Microsoft-managed infrastructure, so it can't reach that private endpoint.

To solve this, you can set up virtual network support (subnet injection) for the Power Platform environment. The environment then uses a delegated subnet in your VNet, dedicated to that environment, for its outbound calls. The region you pick also decides how many VNets you need, which can be crucial if you're tied to a single Azure region in a geography that has two.

### Architecture

![Power Platform environment linked to an enterprise policy, sending outbound traffic through a delegated subnet to a Key Vault private endpoint in another subnet of the same Sweden Central VNet, with a private DNS zone linked to the VNet](https://cdn.hashnode.com/uploads/gql/6a4bb49901674f58c01ace43/4ba35df4-391f-47a5-a051-a477ef50a30d.png align="center")

## Prerequisites

- Managed environment
- Roles: Network Contributor (or equivalent) in Azure, Power Platform administrator in Entra
- Resource providers registered: `Microsoft.Network`, `Microsoft.PowerPlatform`
- PowerShell module: `Microsoft.PowerPlatform.EnterprisePolicies`
- DNS: the private DNS zone for the target service (here `privatelink.vaultcore.azure.net`) must be resolvable from the VNet

## Caveat: region pairs decide how many VNets you need

Each Power Platform region maps to one or more Azure regions. If it maps to two, like Norway with Norway East and Norway West, the enterprise policy needs a delegated subnet in a VNet in each of them, because the environment can run in, and fail over to, either one. Sweden maps only to Sweden Central, so a single VNet is enough.

If your platform is tied to one Azure region, a two-region geography means building and maintaining a VNet in a region you otherwise don't use. In that case, a single-region geography like Sweden can be the simpler choice.

## Step 1: Delegate the subnet

Create a subnet delegated to `Microsoft.PowerPlatform/enterprisePolicies` and size it carefully. Microsoft recommends a block larger than /24 if you plan to inject several managed environments into the subnet. This demo uses a /26 for a single environment.

![Azure portal subnet list showing powerplatform-subnet (10.0.4.128/26) delegated to Microsoft.PowerPlatform/enterprisePolicies, next to a non-delegated default subnet](https://cdn.hashnode.com/uploads/gql/6a4bb49901674f58c01ace43/0641a29b-6e24-4676-b8e5-ae3d06eb6ff8.png align="center")

## Step 2: Create the enterprise policy

An enterprise policy is deployed using the PowerShell module listed in the prerequisites. The policy is an Azure resource that represents the environment's network configuration (enable *Show hidden types* in the portal to see it). The scripts below cover both single-region and two-region geographies.

```powershell
# Single-region geography (e.g. Sweden)
New-SubnetInjectionEnterprisePolicy `
    -SubscriptionId    "00000000-0000-0000-0000-000000000000" `
    -TenantId          "00000000-0000-0000-0000-000000000000" `
    -ResourceGroupName "rg-powerplatform-demo" `
    -PolicyName        "ep-powerplatform-demo-sweden" `
    -PolicyLocation    "sweden" `
    -VirtualNetworkId  "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-powerplatform-demo/providers/Microsoft.Network/virtualNetworks/vnet-powerplatform-demo-sweden" `
    -SubnetName        "powerplatform-subnet"

# Two-region geography (e.g. Norway: one VNet in Norway East, one in Norway West)
New-SubnetInjectionEnterprisePolicy `
    -SubscriptionId    "00000000-0000-0000-0000-000000000000" `
    -TenantId          "00000000-0000-0000-0000-000000000000" `
    -ResourceGroupName "rg-powerplatform-demo" `
    -PolicyName        "ep-powerplatform-demo-norway" `
    -PolicyLocation    "norway" `
    -VirtualNetworkId  "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-powerplatform-demo/providers/Microsoft.Network/virtualNetworks/vnet-powerplatform-demo-norwayeast" `
    -SubnetName        "powerplatform-subnet" `
    -VirtualNetworkId2 "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-powerplatform-demo/providers/Microsoft.Network/virtualNetworks/vnet-powerplatform-demo-norwaywest" `
    -SubnetName2       "powerplatform-subnet"
```

![Azure portal showing the enterprise policy ep-powerplatform-demo-sweden of type Microsoft.PowerPlatform/enterprisePolicies in location Sweden](https://cdn.hashnode.com/uploads/gql/6a4bb49901674f58c01ace43/7121d39c-9f8c-4245-8c82-fc383e0e85f9.png align="center")

## Step 3: Link the policy to the environment

We now have a delegated subnet and an enterprise policy that represents our Power Platform environment. Last up is subnet injection.

```powershell
Enable-SubnetInjection `
    -EnvironmentId "00000000-0000-0000-0000-000000000000" `
    -PolicyArmId   "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/rg-powerplatform-demo/providers/Microsoft.PowerPlatform/enterprisePolicies/ep-powerplatform-demo-sweden"
```

## Step 4: Reach the private endpoint

Make sure traffic is allowed outbound from the delegated subnet to the Key Vault's private endpoint on port 443.

The final validation is inside the Power Automate flow: if the Get secret action can list the secrets in the Key Vault, you're through.

![Power Automate Get secret action listing the secrets from the private Key Vault, confirming the flow reaches it through the delegated subnet](https://cdn.hashnode.com/uploads/gql/6a4bb49901674f58c01ace43/b702b9bb-7aec-4d4a-adf2-e1af3bdf2b84.png align="center")

## Summary

This is a simplified setup, but the same principles apply in production. What changes in a regulated environment is who runs the commands, and from where.

With these steps in place, your Power Platform team can reach Azure resources behind private endpoints, without opening them up to public access.

## References

- [Virtual Network support overview (supported regions)](https://learn.microsoft.com/power-platform/admin/vnet-support-overview#supported-regions)
- [Set up virtual network support for Power Platform (PowerShell)](https://learn.microsoft.com/en-us/power-platform/admin/vnet-support-setup-configure?tabs=existing%2Csingle&pivots=powershell)
- [Troubleshoot virtual network issues](https://learn.microsoft.com/troubleshoot/power-platform/administration/virtual-network)
- [New-SubnetInjectionEnterprisePolicy](https://learn.microsoft.com/powershell/module/microsoft.powerplatform.enterprisepolicies/new-subnetinjectionenterprisepolicy)
- [Enable-SubnetInjection](https://learn.microsoft.com/powershell/module/microsoft.powerplatform.enterprisepolicies/enable-subnetinjection)
