【发布时间】:2021-04-30 16:13:23
【问题描述】:
我将以下命令作为 bash 脚本运行。
az group create -n $1-rg -l eastus2
az deployment group create -g $1-rg -n $1-deploy \
-f ./azure/sensor/trafficmirrorstack.json \
-p @./azure/sensor/trafficmirrorstack.parameters.json \
-p CustomerName=$1
az deployment group show -g $1-rg -n $1-deploy
以下似乎应该可以工作:
rg_name = f"{name}-rg"
deploy_name = f"{name}-deploy"
region = list(region_params.keys())[0]
# add resource group
rg_result = resource_client.resource_groups.create_or_update(
rg_name,
{
"location": region
}
)
print(f"Provisioned resource group {rg_result.name} in the {rg_result.location} region")
with open("./sensor/trafficmirrorstack.json") as template_file:
print("!!!!1")
print(f"{0}".format(template_file.read()))
#print(f"{0}".format(template_file.read()))
print("!!!!2")
template = f"{0}".format(template_file.read())
parameters = {"CustomerName": { "value": name}}
deployment_params = {
"mode": "Incremental",
"template": template,
"parameters": parameters
}
# Create deployment
deployment_create_result = resource_client.deployments.begin_create_or_update(
rg_name,
deploy_name,
{"properties": deployment_params},
# deployment_params,
)
deployment_create_result = deployment_create_result.result()
但是你怎么做相当于“-p @./azure/sensor/trafficmirrorstack.parameters.json -p CustomerName=$1”
提前致谢
【问题讨论】:
-
据我了解,你想覆盖参数文件中的一对键值对。对?如果有,请参考docs.microsoft.com/en-us/python/api/azure-mgmt-resource/…。我们不能同时使用 parametersLink 和参数。
-
我的预期问题是我可以在 azure cli 中指定多个“参数”。在我上面的示例中,“-p @./azure/sensor/trafficmirrorstack.parameters.json”是一个文件,“-p CustomerName=$1”是名称值对。 “参数= {“客户名称”:{“值”:名称}}部署参数= {“模式”:“增量”,“模板”:模板,“参数”:参数}”。似乎只允许其中之一
-
我的问题与这个 github 问题类似。 [github.com/Azure/azure-sdk-for-python/issues/478] 只添加了多个参数指定的附加复杂性。