Azure ARM templates - using the output of other deployments

后端 未结 3 836
忘掉有多难
忘掉有多难 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:50

    Are you using Azure DevOps Release Pipelines? You could just set the output to be created as variables so you can re-use them in the same or a different stage.

    We use these extensions on our projects

    • ARM Outputs https://github.com/keesschollaart81/vsts-arm-outputs
    • VSTS replacetokens https://github.com/qetza/vsts-replacetokens-task
    0 讨论(0)
  • 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.

    0 讨论(0)
  • 2021-01-03 12:55

    How are you doing your deployments? In PowerShell you can do something like:

    (Get-AzureResourceGroupDeployment NameOfResourceGroup).Outputs.NameOfOuputProperty.Value
    

    And that will give you the output of the most recent deployment. You can also throw the entire deployment object into a var and have at it that way.

    $d = Get-AzureResourceGroupDeployment NameOfResourceGroup
    

    Which would be faster if you needed a many output properties.

    That help?

    Update for AzureRM cmdlet

    The syntax is largely the same:

    (Get-AzureRmResourceGroupDeployment -ResourceGroupName NameOfResourceGroup -Name NameOfDeployment).Outputs.NameOfOutputProperty.value
    

    If you have multiple deployments you can use:

    Get-AzureRmResourceGroupDeployment -ResourceGroupName NameOfResourceGroup 
    

    To see them all and see what the names are...

    0 讨论(0)
提交回复
热议问题