在不同资源组中使用 Azure Cli 创建专用终结点

Create Private Endpoint with Azure Cli in different resource group

我有一个资源组用于我的 vnet (rg-private-vnet) 和一个用于我的 webapp 和 sql 服务器 (rg-webapp)。现在我想在 rg-webapp 中为我的 SQl 服务器创建一个私有端点。 这适用于在 vnet 的资源组中创建专用终结点的情况。但我希望它位于 sql 服务器的资源组中。

我用过:

 az network private-endpoint create --name $sqlPrivateEndpoint --resource-group $resourceGroupVnet --vnet-name $vnetName --subnet $sqlSubnetName --private-connection-resource-id $id --connection-name mySqlConnection  --group-id sqlServer

如果我使用 rg-webapp,我会收到错误消息:

(InvalidResourceReference) Resource /subscriptions/XXX/[...} referenced by resource /subscriptions/XXX/[...] was not found. Please make sure that the referenced resource exists, and that both resources are in the same region.

使用 rg-private-vnet 就可以了。在 Azure 门户中,在 rg-webapp 资源组中创建端点没有问题。我没有看到任何更多参数来在不同的 rg 中创建它。

根据文档,您需要将子网的资源 ID 提供给 --subnet 参数(而不是子网名称),如果子网位于不同的位置,则跳过 --vnet-name 参数资源组:

--subnet Name or ID of an existing subnet. If name specified, also specify --vnet-name. If you want to use an existing subnet in other resource group or subscription, please provide the ID instead of the name of the subnet and do not specify the --vnet-name. (az network private-endpoint | Microsoft Docs)