Warm tip: This article is reproduced from serverfault.com, please click

Azure API Management-如何使用Azure CLI设置VNET / SubNet?

(Azure API Management - How to set the VNET/SubNet using Azure CLI?)

发布于 2020-11-29 10:04:30

我已经创建了我的VNET和SubNet,如下所述

RESOURCE_GROUP="POC-RG"
LOCATION="westus"
APIMNAME="poc-apim-98"
PUBLISHER="Demo"
PUBLISHEREMAIL="myemail@demo.com"
SKU="Premium"
VNETNAME="app-vnet"
APITYPE="External"

az network vnet create \
  --resource-group ${RESOURCE_GROUP} \
  --name ${VNETNAME} \
  --location ${LOCATION}

az network vnet subnet create \
--resource-group ${RESOURCE_GROUP} \
--vnet-name ${VNETNAME} \
--name apim \
--address-prefixes 10.0.5.0/24

我想在上面创建的apim子网中配置Azure API管理

az apim create --name ${APIMNAME} -g ${RESOURCE_GROUP} -l ${LOCATION} --sku-name ${SKU} --publisher-email ${PUBLISHEREMAIL} --publisher-name ${PUBLISHER} --virtual-network ${APITYPE}

看起来Azure CLI在创建APIM时不采用子网参数,如何使用azure cli设置子网并创建Azure API管理?

Questioner
Karthikeyan Vijayakumar
Viewed
11
krishg 2020-11-30 16:13:59

你是对的。由于某些原因az apim create,不提供输入VNET子网参考的选项。

你有2个选择:

az group deployment create --resource-group <my-resource-group> --template-uri https://raw.githubusercontent.com/Azure/azure-quickstart-templates/master/201-api-management-create-with-external-vnet/azuredeploy.json

或者,

  • az resource创建APIM后,使用命令添加子网引用。
az apim create --name ${APIMNAME} -g ${RESOURCE_GROUP} -l ${LOCATION} --sku-name ${SKU} --publisher-email ${PUBLISHEREMAIL} --publisher-name ${PUBLISHER} --virtual-network ${APITYPE}

$apimResourceId = az apim show -n ${APIMNAME} -g ${RESOURCE_GROUP} --query 'id' -o json

$subnetResourceId = az network vnet subnet show -g ${RESOURCE_GROUP} -n apim --vnet-name ${VNETNAME} --query 'id' -o json

az resource update --ids $apimResourceId --set properties.virtualNetworkConfiguration.subnetResourceId=$subnetResourceId