简体   繁体   中英

How to pass parameters to ARM template using azure python sdk?

i run the following command as a bash script.

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"

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 . 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. For more details, please refer to here

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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