Azure API Management and DevOps with Git version control

In this section, we will focus on Azure API Management and how we can leverage DevOps capabilities to build a continuous release pipeline for API Management. We will work with an ARM template to create and update an API Management instance and demonstrate how we can leverage an ARM template to define products, APIs, and policies within an Azure API Management instance.

We will extend our DevOps solution and add new project for Azure API Management. The project will consist of an ARM definition file and a parameter file, which is used to deploy resources across multiple environments:

  1. In the ARM definition file, the first step is to define a resource for API Management with a resource type such as Microsoft.ApiManagement/service:
{
"apiVersion": "2017-03-01",
"name": "[parameters('apimanagementname')]",
"type": "Microsoft.ApiManagement/service",
"location": "[resourceGroup().location]",
"tags": {},
"sku": {
"name": "[parameters('sku')]",
"capacity": "[parameters('skuCount')]"
},
"properties": {
"publisherEmail": "[parameters('publisherEmail')]",
"publisherName": "[parameters('publisherName')]"
"notificationSenderEmail": "[email protected]"
}
}
  1. To add a global policy, we need to define a nested resource within the Azure API Management instance, which will inherit the dependency from a parent resource:
{
"apiVersion": "2017-03-01",
"dependsOn": [
"[concat('Microsoft.ApiManagement/service/',parameters('azureapimanagementName')]"

]
"name": "policy",
"properties": {
"policyContent": "[parameters('tenanatpolicy')]"
}
}
  1. To define policies in API Management, you can either refer to the preceding chapter on API Management, or you can look into the Microsoft documentation via the following link: https://docs.microsoft.com/en-us/azure/api-management/api-management-policies.
  2. Next, we can use the ARM template to import an external API through the OpenAPI definition. Here, we have taken an example of an OpenAPI definition for a pet store:
 "resources": [
{
"apiVersion": "2017-03-01",
"type": "apis",
"name": "sampleswaggerforpetstore",
"dependsOn": [
"[concat('/subscriptions/','[subscription().subscriptionId]','/resourceGroups/','[resourceGroup().name]','/providers/',
'Microsoft.ApiManagement/service/', parameter('azureapiManagementName'))]"
],
"properties": {
"contentFormat": "swagger-link-json",
"contentValue": "http://petstore.swagger.io/v2/swagger.json",
"path": "examplepetstore"
}
}
]
  1. Similarly, you can also add your Logic Apps and Functions (with no OpenAPI definition) endpoint into Azure API Management using the HTTPS protocol:
{
"apiVersion": "2017-03-01",
"type": "apis",
"name": "samplellogicapps",
"dependsOn": [
"[concat('Microsoft.ApiManagement/service/', variables('azureapiManagementName'))]"
],
"properties": {
"serviceUrl": "https://logicappsendpoint",
"path": "logicapps",
"protocols": [
"https"
]
}
}
  1. To group multiple APIs into single products in the API Management instance, add a products resource to the ARM definition file:
{
"apiVersion": "2017-03-01",
"type": "products",
"name": "exampleProduct",
"dependsOn": [
"[concat('/subscriptions/','[subscription().subscriptionId]','/resourceGroups/','[resourceGroup().name]','/providers/','Microsoft.ApiManagement/service/', variables('azureapiManagementName'))]"
],
"properties": {
"displayName": "Sample Product Name",
"description": "Description for sample product",
"subscriptionRequired": true,
"approvalRequired": false,
"subscriptionsLimit": 1,
"state": "published"
},
"resources": [
{
"apiVersion": "2017-03-01",
"type": "apis",
"name": "exampleApi",
"dependsOn": [
"[concat('/subscriptions/','[subscription().subscriptionId]','/resourceGroups/','[resourceGroup().name]','/providers/','Microsoft.ApiManagement/service/', variables('azureapiManagementName'))]",
"[concat('Microsoft.ApiManagement/service/', variables('azureapiManagementName'), '/apis/sampleswaggerforpetstore')]"
]
}
]
}
  1. This will allow us to have a single policy defined for a group of APIs along with a single authentication and authorization model for clients to invoke APIs hosted in Azure. 

You can find more details on ARM definition for Azure API Management at the following GitHub link, which is managed by Microsoft and community members: https://github.com/Azure/azure-quickstart-templates/tree/master/201-api-management-create-with-vnet.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.147.59.217