How to create the package file when publish a solution template to marketplace?

To publish a solution template to marketplace, you need to upload a package file. This package file contains all the template files and createUIDefinitionFile.  The main template file should be named mainTemplate.json and is required.The createUIDefinition file describes how the inputs needed for the template need to be rendered. The file is also required and should be named createUIDefinition.json.

Prerequisites:

An azure subscription

Steps:

a. Create a mainTemplate.json

If you are not familiar with the structure and syntax of Azure Resource Manager templates, go through this article first. Here I create a sample mainTemplate.json file. The sample mainTemplate will create a VM with erverything configued but the osProfile. So I configured two parameters for osProfile. The value will be provided by the user via createUIDefinition.json file.

{
 "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
 "contentVersion": "1.0.0.0",
 "parameters": {
 "adminUserName": {
 "type": "string"
 },
 "adminPassword": {
 "string": "type"
 }
 },
 "variables": {
 "vnetID": "[resourceId('Microsoft.Network/virtualNetworks','myVNet')]",
 "subnetRef": "[concat(variables('vnetID'),'/subnets/mySubnet')]"
 },
 "resources": [{
 "apiVersion": "2016-03-30",
 "type": "Microsoft.Network/publicIPAddresses",
 "name": "myPublicIPAddress",
 "location": "[resourceGroup().location]",
 "properties": {
 "publicIPAllocationMethod": "Static"
 }
 },
 {
 "apiVersion": "2016-03-30",
 "type": "Microsoft.Network/virtualNetworks",
 "name": "myVNet",
 "location": "[resourceGroup().location]",
 "properties": {
 "addressSpace": {
 "addressPrefixes": ["10.0.0.0/16"]
 },
 "subnets": [{
 "name": "mySubnet",
 "properties": {
 "addressPrefix": "10.0.0.0/24"
 }
 }]
 }
 },
 {
 "apiVersion": "2016-03-30",
 "type": "Microsoft.Network/networkInterfaces",
 "name": "myNic",
 "location": "[resourceGroup().location]",
 "dependsOn": ["[resourceId('Microsoft.Network/publicIPAddresses/', 'myPublicIPAddress')]",
 "[resourceId('Microsoft.Network/virtualNetworks/', 'myVNet')]"],
 "properties": {
 "ipConfigurations": [{
 "name": "ipconfig1",
 "properties": {
 "privateIPAllocationMethod": "Dynamic",
 "publicIPAddress": {
 "id": "[resourceId('Microsoft.Network/publicIPAddresses','myPublicIPAddress')]"
 },
 "subnet": {
 "id": "[variables('subnetRef')]"
 }
 }
 }]
 }
 },
 {
 "apiVersion": "2016-04-30-preview",
 "type": "Microsoft.Compute/virtualMachines",
 "name": "myVM",
 "location": "[resourceGroup().location]",
 "dependsOn": ["[resourceId('Microsoft.Network/networkInterfaces/', 'myNic')]"],
 "properties": {
 "hardwareProfile": {
 "vmSize": "Standard_D1"
 },
 "osProfile": {
 "computerName": "[parameters('adminUserName')]",
 "adminUsername": "[parameters('adminUserName')]",
 "adminPassword": "[parameters('adminPassword')]"
 },
 "storageProfile": {
 "imageReference": {
 "publisher": "MicrosoftWindowsServer",
 "offer": "WindowsServer",
 "sku": "2012-R2-Datacenter",
 "version": "latest"
 },
 "osDisk": {
 "name": "myManagedOSDisk",
 "caching": "ReadWrite",
 "createOption": "FromImage"
 }
 },
 "networkProfile": {
 "networkInterfaces": [{
 "id": "[resourceId('Microsoft.Network/networkInterfaces','myNic')]"
 }]
 }
 }
 }]
}

After finishing the template, it’s ready to test it on the portal. You can edit your template by clicking new->Tempplate deployment->Custom deployment->Edit template. If it can be deployed successfully, then you can move to next step. If not, you can see the error message if there is something wrong with your template after clicking ‘Save’ and ‘Purchase’ button. Correct the error, then try again.

 

b. Create a createUIDefinition.json

CreateUIDefinition is used by the Azure portal to generate the user interface for creating a managed application. For more details, you can refer to Getting started with CreateUIDefinition. As there are two parameters which need to be filled in mainTemplate.json, this sample CreateUIDefinition.json will provide the corresponding outputs.

{
“handler”: “Microsoft.Compute.MultiVm”,
“version”: “0.0.1-preview”,
“parameters”: {
“basics”: [],
“steps”: [{
“name”: “Infrastructure”,
“label”: “Infrastructure”,
“subLabel”: {
“preValidation”: “Configure the infrastructure required to support my Deploy”,
“postValidation”: “Done”
},
“bladeTitle”: “test Deploy Infrastructure”,
“elements”: [{
“name”: “adminUserName”,
“type”: “Microsoft.Compute.UserNameTextBox”,
“label”: “User name”,
“defaultValue”: “”,
“toolTip”: “”,
“constraints”: {
“required”: true,
“regex”: “^[a-z0-9A-Z]{1,30}$”,
“validationMessage”: “Only alphanumeric characters are allowed, and the value must be 1-30 characters long.”
},
“osPlatform”: “Windows”,
“visible”: true
},
{
“name”: “adminPassword”,
“type”: “Microsoft.Common.PasswordBox”,
“label”: {
“password”: “Password”,
“confirmPassword”: “Confirm password”
},
“toolTip”: “”,
“constraints”: {
“required”: true,
“regex”: “”,
“validationMessage”: “”
},
“options”: {
“hideConfirmation”: false
},
“visible”: true
}]
}],
“outputs”: {
“adminUserName”: “[steps(‘Infrastructure’).adminUserName]”,
“adminPassword”: “[steps(‘Infrastructure’).adminPassword]”
}
}
}

After finishing the createUIDefinition.json, you also need to test it locally before publishing it to marketplace. The steps are as below.

  1. Create using the Azure storage explorer a new public container. (set the public access level). For example named : “tony”.
  2. Upload the file “createUiDefinition.json” to this container.
  3. You can get the URL of the blob from portal.
  4. Now you will have to encode this URL , you can use https://www.urlencoder.org/ for this. The encoded URL looks like: https%3A%2F%2Ftonystoraget.blob.core.windows.net%2Ftony%2FcreateUiDefinition.json
  5. Now replace the URL in the text below: https://portal.azure.com/#blade/Microsoft_Azure_Compute/CreateMultiVmWizardBlade/internal_bladeCallId/anything/internal_bladeCallerParams/{“initialData”:{},”providerConfig”:{“createUiDefinition“:” URL from step 4 “}}
  6. Open a new browser and paste in the URL from step 5. And the result will be

Summary

Congratulation, you have finished the mainTemplate.json and createUIDefinition.json. The last thing you need to do is package them and upload it. About how to publish the solution template, you can follow this article.

Leave a Reply

Your email address will not be published. Required fields are marked *