简体   繁体   English

如何使用 azure python ZEAE18BC41E1434DD98FA2DD989531DA8 将参数传递给 ARM 模板

[英]How to pass parameters to ARM template using azure python sdk?

i run the following command as a bash script.我将以下命令作为 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 

the following seems like it should work:以下似乎应该工作:

  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()

but how do you do the equivalent of "-p @./azure/sensor/trafficmirrorstack.parameters.json -p CustomerName=$1"但是你怎么做相当于“-p @./azure/sensor/trafficmirrorstack.parameters.json -p CustomerName=$1”

thanks in advance提前致谢

When we use Azure python sdk to deploy arm template, we just can use provide the paramater file URL or define parameter as json with the method resource_client.deployments.begin_create_or_update . When we use Azure python sdk to deploy arm template, we just can use provide the paramater file URL or define parameter as json with the method resource_client.deployments.begin_create_or_update . we can not use the two method at the same time.我们不能同时使用这两种方法。 For more details, please refer to here更多详情,请参考这里在此处输入图像描述

Besides, in azure cli, it will read multiple "parameter" you provide then define one Jobject with these "parameter" as parameters when we deploy arm template.此外,在 azure cli 中,它会读取您提供的多个“参数”,然后在我们部署 arm 模板时使用这些“参数”作为parameters定义一个 Jobject。 For more details, please refer to here更多详情,请参考这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM