如何通过 Azure CLI 将 IP 地址添加到 Cosmosdb 数据库防火墙

How to add IP address to a Cosmosdb database firewall through the Azure CLI

我想通过 Azure CLI 将我的 IP 添加到 cosmosdb 防火墙。 使用 Azure CLI 的唯一方法是使用 az cosmosdb update,但它会覆盖防火墙中的当前 IP。

我正在使用 MacOS,所以我可以通过 curl ifconfig.me.

获取我的 IP

如何在不覆盖当前 IP 的情况下将我的 IP 添加到防火墙?

您可以简单地使用 az cosmosdb list 获取列表并将您的 IP 附加到列表,然后 cosmosdb update 使用该列表:

DESIRED_IP=$(curl ifconfig.me)
CURRENT_IPS=$(az cosmosdb list | jq -r '.[0].ipRules | .[] | .ipAddressOrRange' | paste -sd "," -)
DESIRED_IPS=$CURRENT_IPS,$DESIRED_IP
az cosmosdb update -n .. -g .. --ip-range-filter "$DESIRED_IPS"