Creating an Azure APIM instance
Creating an Azure APIM instance in Azure Devops using Release Pipelines
It is important to have a solid solution to keep your environments synchronized and be able to easily synchronize changes and fixes between those environments.
This blog contains a demo which will guide you through the process of setting up a release pipeline to provision a new API Management Service to an Azure Subscription.
Creating an Azure API management service
Start off by creating a new Azure API management service resource. Choose a name and put it in a new or existing resources group. For this demo a Developer tier resource will be sufficient.
Before creating the API management service, click the Automation options link at the bottom of the page. This will open the template page. In the template page we are going to download this template to be used in a VSTS release pipeline later on in the tutorial.
Creating a VSTS project and import the repository
In the next steps we will create an Azure DevOps solution, and add the template to the project. If you don’t yet have a DevOps account, you can create one for free. Once you’ve done that, you can create a project. In this case I chose for a private project, since I will be the only one working on this project. As version control we select Git.
Move to the Repos tab, and select the Upload Files option.
Extract all files from the .zip file we downloaded in the previous step, and upload it to the Repository.
Creating a release pipeline for the API Management service
To be able to use the generated templates we have to do some minor changes. First open the deploy.ps1. This is the PowerShell script we will be using to deploy the API Management template. Change the templateFilePath & the parametersFilePath. We have to change these values for us to be able to use the PowerShell script in the release pipeline.
Next remove the following lines from the PowerShell script. We don’t need these lines, as this will be managed outside of the script.
We also have to update the Template.json & Parameters.json. In both files we have to rename “name” & “location” because for some reason the PowerShell script fails when we use the standard parameter names. Make sure you use the same name in both Template & Parameters.
- Go to pipelines and select Releases. Select New release pipeline
- We will start with an Empty job.
- Select “Add an artifact”
- Select Azure repository and select the project and Source that you created earlier. We need to define this artifact to be able to use our deploy.ps1 script.
- In the stages select Stage 1 (1 job, 0 task)
- In the Agent job click the “+” to create a new task. “Search for Azure PowerShell” and click “Add”
- You can change the display name to whatever you want. Select your Azure Subscription, and set the script type to “Script File Path”.
- In the script Path we will select the deploy.ps1 from the linked artifacts.
- In the script arguments use following arguments. Replace the values between ‘*’ with your values-subscriptionId *yourSubscriptionId* -resourceGroupName *yourResourceGroupName* -resourceGroupLocation westeurope -deploymentName myFirstDeployment
- Save the changes, and save the release pipeline.We can now use the created release pipeline to create an instance of the API Management in our Azure Subscription. Go back to the release pipelines, select your pipeline and click “Create a release”.
- Choose your created stage and select “Create”.
- Open the created release, and click “Deploy”. Note: It is possible that the release will fail. This is due to the fact that in a free subscription the maximum time for a job is 30 minutes, and sometimes the creation of an APIM instance takes longer than 30 minutes. This shouldn’t impact the creation of the instance though.
After some time, you should be able to see the newly created APIM instance in your Azure Portal. It is easy to change the configuration values in your Azure DevOps Repository. Just navigate to the “parameters.json” and change whatever value you want. Make sure to create a new release when you did a change in one of the files.
The option to generate a deployment template in Azure is very useful. It took me a while to find out how to get my generated template to work in a release pipeline. Though, as soon as you know how to do this, it can be a very powerful baseline for your DevOps solution.