Deploying API Management with ARM Templates

I’ve been working in a client for a few weeks where the idea was to create some Logic Apps and expose them as API’s to be consumed by internal applications and external clients. To expose them while having some other services on top of the APIs like caching and security we used the API Management.

After the development was almost completed, we started planning the migration to the test and productions environments and that’s when we started looking at options to copy everything that we have in the API Management development environment to these new ones.

For those that have been working with Azure for some time, we expect to have an ARM template that represents the resource we want to deploy in another environment and with the API Management is no different. So, in this post, I’ll be showing how to deploy API Management with ARM Templates.

Extracting the ARM Template

The first thing we need to do is to extract the ARM template and to do so we can just use the Azure Portal to that as you can see below.

The problem with this approach is that the ARM template here does not expose everything you need to have another instance of it running right away and you will have to add a lot of missing information. So when looking for more ways of doing this, I found a blog post made by Matias Logdberg where he created a PowerShell module that enables us to extract everything related to the API Management instance we want to deploy in other environments.

You can find this blog post here: http://mlogdberg.com/apimanagement/arm-template-creator.

So using this module I did the following steps:

  • Created a Visual Studio project to hold this ARM Template and parametrized for each environment that I needed. In the picture below DEV, TEST, and PROD.

The ARM template generated came with all API’s, operations, policies, products, named values and more. I had to add manually was the creation of the API Management instance itself, but maybe there is some parameter in the module to also expose that. Another thing that I had to do was to parametrize the values that I needed inside the policies and some other points as below:

Below you will see the complete ARM template for one API with all its operations, policies and products.

Deployment in other environments

Once you have the ARM template completely parametrized, you can then use PowerShell, Visual Studio, VSTS, or the Azure Portal to deploy it to the environment you want.

From Visual Studio, you have the deploy command in the project as the picture below shows.

As described in the code of the ARM template, the creation of the API Management instance is commented out. I’ll just enable this part of the code when I’m setting up a new instance. Please be aware that the creation of a new API Management namespace takes a long time (between 30 minutes and 1 hour). The update of the instance itself is very quick and it’s completed in a couple of minutes.

Summary

With this approach, will be a lot easier to maintain the instances of API Management in several environments in sync and also, I’ll be able to see what changes are being made in the code over time.

Alessandro Moura

Certified BizTalk, Mulesoft, TOGAF and Azure. Integration Specialist. Solutions Architect.

Leave a Reply

%d bloggers like this: