createUiDefinition.json for ARM Azure web app

Viewed 656

I have created the ARM template for azure web app. I need to publish the ARM template to azure market place. I have used the azure publish portal https://publish.windowsazure.com/workspace/multi-resource-solutions for publishing the ARM template.

To on-board the ARM template to azure market place zip file must contain a mainTemplate.json and createUiDefinition.json. I found some samples for createUiDefination.json file in https://github.com/Azure/azure-quickstart-templates but all the createUiDefination.json is for VM. I am unable to find the samples or tutorials for createUiDefination.json for Azure web app.

I need to validate the azure web app site name is already exists or not. Also need to create or use the app service plan.

Is there is any tutorial or sample for creating createUiDefination.json for azure web app?

2 Answers

I need to validate the azure web app site name is already exists or not.

This is not possible, you need to add to the site name a unique String, to ensure that the site name is globally unique. For example you could use in your ARM template this function: uniqueString()

Similar question was answered by a Microsoft employee.

Also need to create or use the app service plan.

Add an App Service Plan to your Azure Resource Manager Template. For example like this:

{
  "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
  "contentVersion": "1.0.0.0",
  "parameters": {
    "hostingPlanName": {
      "type": "string",
      "minLength": 1
    },
    "skuName": {
      "type": "string",
      "defaultValue": "F1",
      "allowedValues": [
        "F1",
        "D1",
        "B1",
        "B2",
        "B3",
        "S1",
        "S2",
        "S3",
        "P1",
        "P2",
        "P3",
        "P4"
      ],
      "metadata": {
        "description": "Describes plan's pricing tier and capacity. Check details at https://azure.microsoft.com/en-us/pricing/details/app-service/"
      }
    },
    "skuCapacity": {
      "type": "int",
      "defaultValue": 1,
      "minValue": 1,
      "metadata": {
        "description": "Describes plan's instance count"
      }
    }
  },
  "variables": {
    "webSiteName": "[concat('webSite', uniqueString(resourceGroup().id))]"
  },
  "resources": [
    {
      "apiVersion": "2015-08-01",
      "name": "[parameters('hostingPlanName')]",
      "type": "Microsoft.Web/serverfarms",
      "location": "[resourceGroup().location]",
      "tags": {
        "displayName": "HostingPlan"
      },
      "sku": {
        "name": "[parameters('skuName')]",
        "capacity": "[parameters('skuCapacity')]"
      },
      "properties": {
        "name": "[parameters('hostingPlanName')]"
      }
    },
    {
      "apiVersion": "2015-08-01",
      "name": "[variables('webSiteName')]",
      "type": "Microsoft.Web/sites",
      "location": "[resourceGroup().location]",
      "tags": {
        "[concat('hidden-related:', resourceGroup().id, '/providers/Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]": "Resource",
        "displayName": "Website"
      },
      "dependsOn": [
        "[resourceId('Microsoft.Web/serverfarms/', parameters('hostingPlanName'))]"
      ],
      "properties": {
        "name": "[variables('webSiteName')]",
        "serverFarmId": "[resourceId('Microsoft.Web/serverfarms', parameters('hostingPlanName'))]"
      }
    }
  ]
}

Validating an app service's name is possible in createUiDefinition.json.

The crux of it is the Microsoft.Solutions.ArmApiControl, which can be used to call ARM apis as part of the validation of a text box. Here is an example:

    {
      "$schema": "https://schema.management.azure.com/schemas/0.1.2-preview/CreateUIDefinition.MultiVm.json#",
      "handler": "Microsoft.Azure.CreateUIDef",
      "version": "0.1.2-preview",
      "parameters": {
        "basics": [
          {}
        ],
        "steps": [
          {
            "name": "domain",
            "label": "Domain Names",
            "elements": [
              {
                  "name": "domainInfo",
                  "type": "Microsoft.Common.InfoBox",
                  "visible": true,
                  "options": {
                      "icon": "Info",
                      "text": "Pick the domain name that you want to use for your app."
                  }
              },
              {
                "name": "appServiceAvailabilityApi",
                "type": "Microsoft.Solutions.ArmApiControl",
                "request": {
                  "method": "POST",
                  "path": "[concat(subscription().id, '/providers/Microsoft.Web/checknameavailability?api-version=2021-02-01')]",
                  "body": "[parse(concat('{\"name\":\"', concat('', steps('domain').domainName), '\", \"type\": \"Microsoft.Web/sites\"}'))]"
                }
              },
              {
                "name": "domainName",
                "type": "Microsoft.Common.TextBox",
                "label": "Domain Name Word",
                "toolTip": "The name of your app service",
                "placeholder": "yourcompanyname",
                "constraints": {
                  "validations": [
                    {
                      "regex": "^[a-zA-Z0-9]{4,30}$",
                      "message": "Alphanumeric, between 4 and 30 characters."
                    },
                    {
                      "isValid": "[not(equals(steps('domain').appServiceAvailabilityApi.nameAvailable, false))]",
                      "message": "[concat('Error with the url: ', steps('domain').domainName, '. Reason: ', steps('domain').appServiceAvailabilityApi.reason)]"
                    },
                    {
                      "isValid": "[greater(length(steps('domain').domainName), 4)]",
                      "message": "The unique domain suffix should be longer than 4 characters."
                    },
                    {
                      "isValid": "[less(length(steps('domain').domainName), 30)]",
                      "message": "The unique domain suffix should be shorter than 30 characters."
       

             }
              ]
            }
          },
          {
            "name": "section1",
            "type": "Microsoft.Common.Section",
            "label": "URLs to be created:",
            "elements": [
              {
                "name": "domainExamplePortal",
                "type": "Microsoft.Common.TextBlock",
                "visible": true,
                "options": {
                    "text": "[concat('https://', steps('domain').domainName, '.azurewebsites.net - The main app service URL')]"
                }
              }
            ],
            "visible": true
          }
        ]
      }
    ],
    "outputs": {
      "desiredDomainName": "[steps('domain').domainName]"
    }
  }
}

You can paste that in to the createUiDefinition.json sandbox azure provides to test it out.

To look at how to do an Azure App Service instead of a VM, look in to documentation like this and use it as the maintemplate.json in the app.zip package.

Related