我想通过 Azure CLI 将我的 IP 添加到 cosmosdb 防火墙。
使用 Azure CLI 执行此操作的唯一方法是使用 az cosmosdb update
,但它会覆盖防火墙中的当前 IP。
我使用的是 MacOS,所以我可以通过 curl ifconfig.me
获取我的 IP。
如何在不覆盖当前 IP 的情况下将我的 IP 添加到防火墙?
答案 0 :(得分:2)
您可以简单地使用 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"