Deploy ARM Templates using Azure Logic Apps & API Management

Amine Charot
Charot
Published in
6 min readMay 2, 2019

--

Integration systems become more and more important to build important applications. It’s also can be important to automate and orchestrate your infrastructure deployment.

Imagine that you are in a case where you should work on a such workflow to build your infrastructure :

  • Create a resource group
  • Create Azure Resources
  • Validate the resources and notify the teams
  • Trigger an Azure DevOps release
  • Only OPS team can run this workflow

This workflow can be done without writing a single line of code using Azure Logic Apps.

  • What is Azure Logic Apps

Integration platform is a solution able to integrate applications or services across a business using some connectors. Azure Logic Apps is an Integration Platform as a Service (IpaaS). As Microsoft defines, Azure Logic Apps is a cloud service that helps to automate and orchestrate tasks, business processes, and workflows. When you need to integrate apps, data, systems, and services across enterprises or organizations. Logic Apps simplifies designing and building scalable solutions for app integration, data integration, system integration, enterprise application integration (EAI), and business-to-business (B2B) communication, whether in the cloud, on premises, or both.

Azure Logic Apps has too many benefits like :

  • Easy to maintain : Azure Logic Apps has more than 100 connectors which allows to design and create a complex workflow without writing code which means that there is less code to write so less bugs to fix so less things to maintain.
  • Easy to monitor : You don’t have to “try{}catch{}”. You can monitor and extract diagnostics easally. Preventing the incidents is becoming the standard way to say “I have a resilient application”. Azure Logic Apps has an alert system built by Azure. Using Logic Apps, you will be able to track the workflow step by step until it fails or succeed.
  • Easy to understand : Its name is “Logic Apps” so it contains “Logic” so it should be easy to understand if you have some logic :D. Actually, Logic Apps design is a serie of steps where each step has a final goal to achieve. If I want to trigger the Logic App, I will create a step that will trigger it, if I want to terminate the App, I will create a step that will terminate the App with a status code …

Deploy an ARM Template with a Logic App

Let’s create a workflow that deploys an ARM Template as I’ve talked about :

  • Create a Resource Group;
  • Deploy ARM Template;
  • Validate the resources;
  • Notify the teams.

As I told you, Azure Logic Apps is easy to use. Its workflow is easy :

  • Triggers are the steps that starts a flow.
  • Actions are tasks done by the flow.
  • Controls user for branching statements.
  • Loops are for iterating over actions “n” times.

Let’s start by creating a trigger. We will choose a HTTP Trigger.

Since we will create an infrastructure, we may need a payload that defines parameters we need such as resource group name. The HTTP Trigger can create a schema from a sample and can validate it when we receive a request. If it is wrong, it will return 400.

Once is done, the generated schema must appear

Then you should require a schema validation. Go to settings and enable the schema validation

The second step should create the resource group. Its name will be in the request payload as defined before.

For the location, you may get it using the same thing as the resource group name (you know using the payload :D). In my case, I will choose West Europe.

Just after, we should make sure that the resource group has been created. We can use conditions to accomplish this.

Yes, you can guess it, we will test if the Provisioning State is successful. It’s easy using Logic Apps :D

If the resource group is not created, we will terminate the workflow with a failed status. Yes, we can do it using Logic Apps !

Otherwise, we can go ahead and deploy an ARM Template !

In order to make my workflow more flexible so it can deploy any ARM Template I want. I’ve added the URIs parameter to the request payload. So I will be able to give any template I want, and it will be deployed !

So the action will be as following

Again, we should test if the deployment has been succeeded or not. You know how to do it ?! Yes ! A condition ! I am proud of you :D

Let’s put all the puzzle together and test our workflow ! Using Postman, I sent a POST Request to the HTTP Url generated by Logic Apps

I was able to track my deployment in Logic Apps

Finally, I had the workflow history

I also had details of each of my deployment step

I also get the result :D

Azure API Management with Azure Logic Apps

Now that our logic application that deploys an ARM Template is ready, we should hide the backend and encapsulate the whole logic behind another service.

Azure API Management has a strong support for Azure Logic App, so we can expose it out of the box and benefit of all the Azure API Management advantages. As I told once for the cloud and DevOps, they go together like chocolate and coffee. Well, API Management and Logic Apps go together like chocolate and coffee too.

Since our Logic Apps can be triggered with a HTTP Trigger, we can use Azure API Management to expose this service (So deploy the ARM Templates in my case).

If we choose “Logic App”, we will find all the Logic Apps services that use the HTTP Trigger.

You just have to select the Logic App and API Management will pull all the information about the operations. Once is done, this API should appear.

Let’s go though the Developer Portal and send a request using this API

When we try to send the request, API Management suggest the schema done for the HTTP Trigger.

Now, the deployment team will pass through APIM to deploy the resources. So, you can control the Logic Apps, you can get more control, more security using APIM Policies.

Bella ciao,

--

--