Azure blueprint - how to handle with ARM parameter file?

Problem statement

When you deploy an ARM template, it's normal to provide a parameter file, in which you can put custom values for parameters used during the ARM template deployment. When you add an artifact of ARM deployment into a blueprint, unluckily you can't use a parameter file on Azure Portal - there is just no field on UI for you to specify a parameter file as shown on the below screenshot.


But alternatively you can use a command line to add an artifact of ARM template deployment to a blueprint, which allows you to specify a parameter file! E.g. using the below PowerShell command to insert an ARM template deployment of a Log Analytics workspace.
$bpDefinition = Get-AzBlueprint -SubscriptionId '<sub Id>' -Name '<blueprint name>' -Version '<blueprint version number>'

New-AzBlueprintArtifact -Blueprint $bpDefinition -Type TemplateArtifact -Name 'la-workspace' -TemplateFile .\la-workspace-deploy.json -TemplateParameterFile .\la-workspace-deploy.parameters.json -ResourceGroupName <resource group name>

Once the artifact is imported, you can go back to Azure portal, open that blueprint, and edit that artifact. Assuming in the original ARM template you don't provide default values to those parameters, but provide all values using the parameter file. Once it's imported, you can see that all values in the parameter file show up on the 'Edit artifact' page. 

Behind the scene, the importing does two things for you,

  • Copy those parameter declarations from the ARM template file into the Blueprint.json, by adding the artifact name as the prefix. So all those parameters are now declared on the blueprint level, and visible to other artifacts.
  • Copy values in the parameter file into the parameter section of the artifact file, la-workspace.json.

************Blueprint.json************
{
  "properties": {
    "targetScope": "subscription",
    "parameters": {
      "la-workspace_name": {
        "type": "string",
        "metadata": {
          "displayName": "name (la-workspace)",
        },
        "allowedValues": []
      },
      "la-workspace_location": {
        "type": "string",
        "metadata": {
          "displayName": "location (la-workspace)",
        },
        "allowedValues": []
      },
      "la-workspace_sku": {
        "type": "string",
        "metadata": {
          "displayName": "sku (la-workspace)",
        },
        "allowedValues": []
      },
      "la-workspace_tags": {
        "type": "array",
        "metadata": {
          "displayName": "tags (la-workspace)",
        },
        "allowedValues": []
      }
     },

************Artifacts/la-workspace.json************
{
  "kind": "template",
  "properties": {
    "displayName": "la-workspace",
    "description": "",
    "dependsOn": [],
    "template": {
        ……
    },
    "resourceGroup": "ResourceGroup",
    "parameters": {
        "name": {
            "value": "la-workspace-test-01"
        },
        "location": {
            "value": "westus"
        },
        "sku": {
            "value": "pergb2018"
        },
        "tags": {
            "value": {}
        }
     }
  }
}

Note on the above screenshot every parameter is followed by an option of "This value should be specified when the blueprint is assigned". If you check this option for all of them, the artifact file will be updated to,

***************Artifacts/la-workspace.json*************
{
  "kind": "template",
  "properties": {
    "displayName": "la-workspace",
    "description": "",
    "dependsOn": [],
    "template": {
        ……
    },
    "resourceGroup": "ResourceGroup",
    "parameters": {
        "name": {
            "value": "[parameters('la-workspace_name')]"
        },
        "location": {
            "value": "[parameters('la-workspace_location')]"
        },
        "sku": {
            "value": "[parameters('la-workspace_sku')]"
        },
        "tags": {
            "value": "[parameters('la-workspace_tags')]"
        }
     }
  }
}

You may already notice, once you save the changes on this blueprint, the values imported from the original parameter file are gone. When you assign this blueprint, since there is no default values for those parameters, you have to fill in values for all those parameters one by one, which is troublesome.

Good practice

Assuming you already have a parameter file for your ARM template deployment, and now import this ARM template into a blueprint. In order to use those values in the original parameter file when assigning a blueprint, instead of filling them in manually, you'd better set default values in the ARM template file as more as possible, instead of leaving them in the parameter file. The default value of a parameter will be automatically copied to the blueprint.json file when you import the ARM template into a blueprint, and then used as the default during the blueprint assignment.


Comments

Popular posts from this blog

Deep-archive an aws S3 bucket with versioning enabled once

Good practices of using Python logging

Auto-installing NVIDIA device plug-in on GPU nodes only