Azure ARM templates - using the output of other deployments

后端 未结 3 837
忘掉有多难
忘掉有多难 2021-01-03 12:13

What I am interested in is reading the output parameters of another deployment in a different resource group. My ARM templates are something like:

  1. platform.jso
3条回答
  •  孤街浪徒
    2021-01-03 12:53

    I know this is an old question but for others who come along, as of 03/12/18 you can definitely do this.

    You need to ensure your output is formatted as per the Microsoft documentation for output variables which broadly has the format

    "outputs": {
      "resourceID": {
        "type": "string",
        "value": "[resourceId('Microsoft.Network/publicIPAddresses', parameters('publicIPAddresses_name'))]"
      }
    }
    

    You can then use these outputs in your templates by referencing the deployment using a resource reference which has the format

    reference(resourceName or resourceIdentifier, [apiVersion], ['Full'])
    

    Note that you will need to provide the api version, as the deployment may use a different api version to the one your parent template uses.

    Your reference would then look something like the following

    {
      "comments": "This would have an output named myOutput you want to use",
      "apiVersion": "2017-05-10",
      "type": "Microsoft.Resources/deployments",
      "name": "my-deployment",
      "resourceGroup": "...",
      "properties": {
        "mode": "Incremental",
        "templateLink": {
          "uri": "...",
          "contentVersion": "1.0.0.0"
        },
        "parameters": { }
    },
    {
      "comments": "This makes use of myOutput from my-deployment",
      "apiVersion": "2017-05-10",
      "type": "Microsoft.Resources/deployments",
      "name": "my-dependent-deployment",
      "properties": {
        "mode": "Incremental",
        "templateLink": {
          "uri": "...",
          "contentVersion": "1.0.0.0"
        },
        "parameters": {
          "myValueFromAnotherDeployment": { "value": "[reference('my-deployment', '2017-05-10').outputs.myOutput.value]" }
        }
      }
    }
    

    Note the slightly awkward "repackaging" of the value, where we use myOutput.value as the input to the dependent deployment, and put that in an object with the key "value": "....". This is because ARM parameters must have a 'value' property in order to be valid.

    You'll get invalid template errors if you try to use the output directly (because output variables have a 'type' and this is not an allowed key in a parameter). That's why you need to get the value property and then put it back into the value in downstream templates.

提交回复
热议问题