Exercise - Deploy a basic Logic Apps workflow using an ARM template

In this unit, we'll deploy a Logic Apps workflow using an Azure Resource Manager (ARM) template.

Creating resources in Azure

Normally, the first thing we'd do is to create a resource group to hold all the things that we need to create. This allows us to administer all the VMs, disks, network interfaces, and other elements that make up our solution as a unit. We can use the Azure CLI to create a resource group with the az group create command. It takes a --name to give it a unique name in our subscription, and a --location to tell Azure what area of the world we want the resources to be located by default.

Since we are in the free Azure sandbox environment, you don't need to do this step, instead, you will use the pre-created resource group [sandbox resource group name] in this exercise.

Download and examine a basic Resource Manager template

  1. From Cloud Shell, run the following curl command to download the template from GitHub.

    curl https://raw.githubusercontent.com/MicrosoftDocs/mslearn-logic-apps-and-arm-templates/master/basic-template/template.json > basic-template.json
    
  2. To view our template, open it in the build-in editor.

    code basic-template.json
    

    The logic app definition described in template.json is shown in the following listing.

    {
        "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
        "contentVersion": "1.0.0.0",
        "parameters": {},
        "variables": {},
        "resources": [
            {
                "type": "Microsoft.Logic/workflows",
                "apiVersion": "2017-07-01",
                "name": "HelloLogicAppsTemplate",
                "location": "westus2",
                "properties": {
                    "state": "Enabled",
                    "definition": {
                        "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
                        "contentVersion": "1.0.0.0",
                        "parameters": {},
                        "triggers": {
                            "manual": {
                                "type": "Request",
                                "kind": "Http",
                                "inputs": {
                                    "method": "GET",
                                    "schema": {}
                                }
                            }
                        },
                        "actions": {
                            "Response": {
                                "runAfter": {},
                                "type": "Response",
                                "kind": "Http",
                                "inputs": {
                                    "body": "Hello Logic Apps Template!",
                                    "statusCode": 200
                                }
                            }
                        },
                        "outputs": {}
                    },
                    "parameters": {}
                }
            }
        ],
        "outputs": {
            "logicAppUrl": {
               "type": "string",
               "value": "[listCallbackURL(concat(resourceId('Microsoft.Logic/workflows/', 'HelloLogicAppsTemplate'), '/triggers/manual'), '2017-07-01').value]"
            }
         }
    }
    

    As you can see from the preceding JSON definition, and as the template name suggests, this Logic App is basic. Let's look at the main components of this app. In the following snippet, we see that the app is called HelloLogicAppsTemplate. This name is hard-coded in the template. The location in which the app runs is also hard-coded to westus2.

    "name": "HelloLogicAppsTemplate",
    "location": "westus2",
    

    Scrolling down to the triggers section, we see that the app is triggered with an HTTP GET request. The trigger is named manual.

    "triggers": {
        "manual": {
            "type": "Request",
            "kind": "Http",
            "inputs": {
                "method": "GET",
                "schema": {}
            }
        }
    },
    

    Further on down in the actions section, we learn that this app contains one step or action. The action it carries out is to respond to the HTTP request with the message Hello Logic Apps Template!.

    "actions": {
        "Response": {
            "runAfter": {},
            "type": "Response",
            "kind": "Http",
            "inputs": {
                "body": "Hello Logic Apps Template!",
                "statusCode": 200
            }
        }
    },
    

    The ARM template has one output in the template's outputs section called logicAppUrl. This output variable lists the URL for the logic app when it is deployed. This makes it easy to test the app. The output uses listCallbackURL to create the URl, but the workflow name and trigger name are once again both hard-coded here.

    "outputs": {
        "logicAppUrl": {
           "type": "string",
           "value": "[listCallbackURL(concat(resourceId('Microsoft.Logic/workflows/', 'HelloLogicAppsTemplate'), '/triggers/manual'), '2017-07-01').value]"
        }
     }
    

    Let's now deploy this logic app and test it.

Validate and deploy the template

To deploy our logic app we'll use the az deployment group create command, since we are deploying to a resource group. When deploying using this command, you can choose to deploy a remote template by specifying its location with the --template-uri parameter. In our case, we want to deploy the template we have locally, so we'll set the --template-file parameter.

  1. From the Cloud Shell run az group deployment validate to validate the template.

    az group deployment validate \
    --resource-group <rgn>[sandbox resource group name]</rgn> \
    --template-file basic-template.json
    

    The --template-file argument points to the local template. The template's filename is basic-template.json.

    You see a large JSON block as output, which tells you that the template passed validation.

    Azure Resource Manager fills in the template parameters and checks whether the template would successfully run in your subscription.

    If validation failed, you would see a detailed description of the failure in the output.

  2. Run the following az deployment group create command in the Cloud Shell to deploy the logic app defined by our basic template to our sandbox resource group.

    az deployment group create \
    --name MyDeployment \
    --resource-group <rgn>[sandbox resource group name]</rgn> \
    --template-file basic-template.json
    

    This command resembles the previous command, but also includes the --name argument to give your deployment a name.

    This command takes 2-3 minutes to complete. When the deployment completes, you see another large JSON block as output that describes the deployment. You see provisioningState in the JSON result with the value Succeeded.

Verify deployment

  1. Run az group deployment show to verify the deployment.

    az group deployment show \
    --name MyDeployment \
    --resource-group <rgn>[sandbox resource group name]</rgn> 
    

    You see the same JSON block as you did previously. You can run this command later if you ever need these details about the deployment. The output is structured as JSON to make it easier to feed into other tools you might use to track your deployments and cloud usage.

  2. To see the app in action, find the logicAppUrl value in the JSON result. Select the URL and paste it into a new browser window. The page will display the Hello Logic Apps Template! message as shown in the following screenshot.

    Web browser displaying response from our basic logic app

Congratulations! You've successfully deployed a logic app using an ARM template.

As we noted in this exercise, the basic template has many hard-coded values. This makes the template less flexible than we'd like. We can improve the situation through the use of parameters.