Azure / azure-blueprints

A library of sample Blueprints that can be easily imported via API or PowerShell
MIT License
258 stars 150 forks source link

Passing values between artifacts #45

Closed kkazala closed 3 years ago

kkazala commented 3 years ago

I want to pass values between artifacts. Following the https://github.com/Azure/azure-blueprints/blob/master/README.md#passing-values-between-artifacts and https://docs.microsoft.com/en-us/azure/governance/blueprints/reference/blueprint-functions#artifacts documentation I built a sample Blueprint, where the contents of artifacts are as follows: templateA.json

{
    "kind": "template",
    "properties": {
      "dependsOn": ["policyAssignment"],
      "template": {
          "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "parameters": {},
          "variables": {},
          "resources": [],
          "outputs": {
            "myString": {
              "type": "string",
              "value": "Aaa Bbb Ccc"
            }
          }
      },
      "resourceGroup": "SingleRG",
      "displayName": "My ARM TemplateA",
      "parameters": {}
    },
    "type": "Microsoft.Blueprint/blueprints/artifacts",
    "name": "templateA"
}

template B.json

{
    "kind": "template",
    "properties": {
      "dependsOn": ["templateA"],
      "template": {
          "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "parameters": {},
          "variables": {},
          "resources": []

      },
      "resourceGroup": "SingleRG",
      "displayName": "My ARM TemplateB",
      "parameters": {
        "blueprintMyString": {
          "value": "[artifacts('templateA').outputs.myString]"
        }
      }
    },
    "type": "Microsoft.Blueprint/blueprints/artifacts",
    "name": "templateB"
}

Unfortunatelly, Import-AzBlueprintWithArtifact returns Import-AzBlueprintWithArtifact : This artifact is invalid. Error: 'Parameter 'blueprintMyString' does not exist in the template specified by the blueprint artifact 'templateB'.'

Any idea on what the problem might be? Did I misunderstood the documentation?

alex-frankel commented 3 years ago

I think you need blueprintMyString to also be declared in the template inside of the artifact:

{
    "kind": "template",
    "properties": {
      "dependsOn": ["templateA"],
      "template": {
          "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
          "contentVersion": "1.0.0.0",
          "parameters": {
            "blueprintMyString": {
              "type": "string"
            }  
          },
          "variables": {},
          "resources": []

      },
      "resourceGroup": "SingleRG",
      "displayName": "My ARM TemplateB",
      "parameters": {
        "blueprintMyString": {
          "value": "[artifacts('templateA').outputs.myString]"
        }
      }
    },
    "type": "Microsoft.Blueprint/blueprints/artifacts",
    "name": "templateB"
}

Basically the artifact parameter needs to be consumed by the template somehow.

kkazala commented 3 years ago

@alex-frankel Oh, I haven't noticed it. You are absolutely, right, that was the reason! Thank you VERY much! :)