|
1 | 1 | ---
|
2 |
| -title: CI/CD for Azure API Management using ARM templates |
3 |
| -description: Introduction to API DevOps with Azure API Management, using Azure Resource Manager templates to manage API deployments in a CI/CD pipeline |
| 2 | +title: Use DevOps and CI/CD to publish APIs |
| 3 | +description: Introduction to API DevOps with Azure API Management |
4 | 4 | services: api-management
|
5 |
| -author: dlepow |
| 5 | +author: adrianhall |
6 | 6 | ms.service: api-management
|
7 | 7 |
|
8 | 8 | ms.topic: conceptual
|
9 |
| -ms.date: 10/09/2020 |
10 |
| -ms.author: danlep |
| 9 | +ms.date: 08/15/2022 |
| 10 | +ms.author: adhal |
11 | 11 | ---
|
12 | 12 |
|
13 |
| -# CI/CD for API Management using Azure Resource Manager templates |
| 13 | +# Use DevOps and CI/CD to publish APIs |
14 | 14 |
|
15 |
| -This article shows you how to use API DevOps with Azure API Management, through Azure Resource Manager templates. With the strategic value of APIs, a continuous integration and continuous deployment (CI/CD) pipeline has become an important aspect of API development. It allows organizations to automate deployment of API changes without error-prone manual steps, detect issues earlier, and ultimately deliver value to users faster. |
| 15 | +With the strategic value of APIs in the enterprise, adopting DevOps continuous integration (CI) and deployment (CD) techniques has become an important aspect of API development. This article discusses the decisions you'll need to make to adopt DevOps principles for the management of APIs. |
16 | 16 |
|
17 |
| -For details, tools, and code samples to implement the DevOps approach described in this article, see the open-source [Azure API Management DevOps Resource Kit](https://github.com/Azure/azure-api-management-devops-resource-kit) in GitHub. Because customers bring a wide range of engineering cultures and existing automation solutions, the approach isn't a one-size-fits-all solution. |
| 17 | +API DevOps consists of three parts: |
18 | 18 |
|
19 |
| -For architectural guidance, see: |
| 19 | +:::image type="content" source="media/devops-api-development-templates/api-management-cicd-flow.png" alt-text="Diagram that illustrates API DevOps flow."::: |
20 | 20 |
|
21 |
| -* **API Management landing zone accelerator**: [Reference architecture](/azure/architecture/example-scenario/integration/app-gateway-internal-api-management-function?toc=%2Fazure%2Fapi-management%2Ftoc.json&bc=/azure/api-management/breadcrumb/toc.json) and [design guidance](/azure/cloud-adoption-framework/scenarios/app-platform/api-management/landing-zone-accelerator?toc=%2Fazure%2Fapi-management%2Ftoc.json&bc=/azure/api-management/breadcrumb/toc.json) |
| 21 | +Each part of the API DevOps pipeline is discussed below. |
22 | 22 |
|
23 |
| -## The problem |
| 23 | +## API definition |
24 | 24 |
|
25 |
| -Organizations today normally have multiple deployment environments (such as development, testing, and production) and use separate API Management instances for each environment. Some instances are shared by multiple development teams, who are responsible for different APIs with different release cadences. |
| 25 | +An API developer writes an API definition by providing a specification, settings (such as logging, diagnostics, and backend settings), and policies to be applied to the API. The API definition provides the information required to provision the API on an Azure API Management service. The specification may be based on a standards-based API specification (such as [WSDL][1], [OpenAPI][2], or [GraphQL][3]), or it may be defined using the Azure Resource Manager (ARM) APIs (for example, an ARM template describing the API and operations). The API definition will change over time and should be considered "source code". Ensure that the API definition is stored under source code control and has appropriate review before adoption. |
26 | 26 |
|
27 |
| -As a result, customers face the following challenges: |
| 27 | +There are several tools to assist producing the API definition: |
28 | 28 |
|
29 |
| -* How to automate deployment of APIs into API Management |
30 |
| -* How to migrate configurations from one environment to another |
31 |
| -* How to avoid interference between different development teams that share the same API Management instance |
| 29 | +* The [Azure API Management DevOps Resource Toolkit][4] includes two tools that provide an Azure Resource Manager (ARM) template. The _extractor_ creates an ARM template by extracting an API definition from an API Management service. The _creator_ produces the ARM template from a YAML specification. The DevOps Resource Toolkit supports SOAP, REST, and GraphQL APIs. |
| 30 | +* The [Azure API Ops Toolkit][5] provides a workflow built on top of a [git][21] source code control system (such as [GitHub][22] or [Azure Repos][23]). It uses an _extractor_ similar to the DevOps Resource Toolkit to produce an API definition that is then applied to a target API Management service. API Ops supports REST only at this time. |
| 31 | +* The [dotnet-apim][6] tool converts a well-formed YAML definition into an ARM template for later deployment. The tool is focused on REST APIs. |
| 32 | +* [Terraform][7] is an alternative to Azure Resource Manager to configure resources in Azure. You can create a Terraform configuration (together with policies) to implement the API in the same way that an ARM template is created. |
32 | 33 |
|
33 |
| -## Manage configurations in Resource Manager templates |
| 34 | +You can also use IDE-based tools for editors such as [Visual Studio Code][8] to produce the artifacts necessary to define the API. For instance, there are [over 30 plugins for editing OpenAPI specification files][9] on the Visual Studio Code Marketplace. You can also use code generators to create the artifacts. The [CADL language][10] lets you easily create high-level building blocks and then compile them into a standard API definition format such as OpenAPI. |
34 | 35 |
|
35 |
| -The following image illustrates the proposed approach. |
| 36 | +## API approval |
36 | 37 |
|
37 |
| -:::image type="content" source="media/devops-api-development-templates/apim-devops.png" alt-text="Diagram that illustrates DevOps with API Management."::: |
| 38 | +Once the API definition has been produced, the developer will submit the API definition for review and approval. If using a git-based source code control system (such as [GitHub][22] or [Azure Repos][23]), the submission can be done via [Pull Request][11]. A pull request informs others of changes that have been proposed to the API definition. Once the approval gates have been confirmed, an approver will merge the pull request into the main repository to signify that the API definition can be deployed to production. The pull request process empowers the developer to remediate any issues found during the approval process. |
38 | 39 |
|
39 |
| -In this example, there are two deployment environments: *Development* and *Production*. Each has its own API Management instance. |
| 40 | +Both GitHub and Azure Repos allow approval pipelines to be configured that run when a pull request is submitted. You can configure the approval pipelines to run tools such as: |
40 | 41 |
|
41 |
| -* API developers have access to the Development instance and can use it for developing and testing their APIs. |
42 |
| -* A designated team called the *API publishers* manages the Production instance. |
| 42 | +* API specification linters such as [Spectral][12] to ensure that the definition meets API standards required by the organization. |
| 43 | +* Breaking change detection using tools such as [openapi-diff][13]. |
| 44 | +* Security audit and assessment tools. [OWASP maintains a list of tools][14] for security scanning. |
| 45 | +* Automated API test frameworks such as [Newman][15], a test runner for [Postman collections][16]. |
43 | 46 |
|
44 |
| -The key in this proposed approach is to keep all API Management configurations in [Azure Resource Manager templates](../azure-resource-manager/templates/syntax.md). The organization should keep these templates in a source control system such as Git. As illustrated in the image, a Publisher repository contains all configurations of the Production API Management instance in a collection of templates: |
| 47 | +> [!NOTE] |
| 48 | +> Azure APIs must conform to a [strict set of guidelines][26] that you can use as a starting point for your own API guidelines. There is a [Spectral configuration][27] for enforcing the guidelines. |
45 | 49 |
|
46 |
| -|Template |Description | |
47 |
| -|---------|---------| |
48 |
| -|Service template | Service-level configurations of the API Management instance, such as pricing tier and custom domains. | |
49 |
| -|Shared templates | Shared resources throughout an API Management instance, such as groups, products, and loggers. | |
50 |
| -|API templates | Configurations of APIs and their subresources: operations, policies, diagnostic settings. | |
51 |
| -|Master (main) template | Ties everything together by [linking](../azure-resource-manager/templates/linked-templates.md) to all templates and deploying them in order. To deploy all configurations to an API Management instance, deploy the main template. You can also deploy each template individually. | |
| 50 | +Once the automated tools have been run, the API definition is reviewed by the human eye. Tools won't catch all problems. A human reviewer ensures that the API definition meets the organizational criteria for APIs, including adherence to security, privacy, and consistency guidelines. |
52 | 51 |
|
53 |
| -API developers will fork the Publisher repository to a Developer repository and work on the changes for their APIs. In most cases, they focus on the API templates for their APIs and don't need to change the shared or service templates. |
| 52 | +## API publication |
54 | 53 |
|
55 |
| -## Migrate configurations to templates |
56 |
| -API developers face challenges when working with Resource Manager templates: |
| 54 | +The API definition will be published to an API Management service through a release pipeline. The tools used to publish the API definition depend on the tool used to produce the API definition: |
57 | 55 |
|
58 |
| -* API developers often work with the [OpenAPI Specification](https://github.com/OAI/OpenAPI-Specification) and might not be familiar with Resource Manager schemas. Authoring templates manually might be error-prone. |
| 56 | +* If using the [Azure API Management DevOps Resource Toolkit][4] or [dotnet-apim][6], the API definition is represented as an ARM template. Tasks are available for [Azure Pipelines][17] and [GitHub Actions][18] to deploy an ARM template. |
| 57 | +* If using the [Azure API Ops Toolkit][5], the toolkit includes a publisher that writes the API definition to the service. |
| 58 | +* If using [Terraform][7], CLI tools will deploy the API definition on your service. There are tasks available for [Azure Pipelines][19] and [GitHub Actions][20] |
59 | 59 |
|
60 |
| - A tool called [Creator](https://github.com/Azure/azure-api-management-devops-resource-kit/blob/main/src/README.md#creator) in the resource kit can help automate the creation of API templates based on an Open API Specification file. Additionally, developers can supply API Management policies for an API in XML format. |
| 60 | +> **Can I use other source code control and CI/CD systems?** |
| 61 | +> |
| 62 | +> Yes. The process described works with any source code control system (although API Ops does require that the source code control system is [git][21] based). Similarly, you can use any CI/CD platform as long as it can be triggered by a check-in and run command line tools that communicate with Azure. |
61 | 63 |
|
62 |
| -* For customers who are already using API Management, another challenge is to extract existing configurations into Resource Manager templates. For those customers, a tool called [Extractor](https://github.com/Azure/azure-api-management-devops-resource-kit/blob/main/src/README.md#Extractor) in the resource kit can help generate templates by extracting configurations from their API Management instances. |
| 64 | +## Best practices |
63 | 65 |
|
64 |
| -## Workflow |
| 66 | +There's no industry standard for setting up a DevOps pipeline for publishing APIs, and none of the tools mentioned will work in all situations. However, we see that most situations are covered by using a combination of the following tools and services: |
65 | 67 |
|
66 |
| -* After API developers have finished developing and testing an API, and have generated the API templates, they can submit a pull request to merge the changes to the publisher repository. |
| 68 | +* [Azure Repos][23] stores the API definitions in a [git][21] repository. |
| 69 | +* [Azure Pipelines][17] runs the automated API approval and API publication processes. |
| 70 | +* [Azure API Ops Toolkit][5] provides tools and workflows for publishing APIs. |
67 | 71 |
|
68 |
| -* API publishers can validate the pull request and make sure the changes are safe and compliant. For example, they can check if only HTTPS is allowed to communicate with the API. Most validations can be automated as a step in the CI/CD pipeline. |
| 72 | +We've seen the greatest success in customer deployments, and recommend the following practices: |
69 | 73 |
|
70 |
| -* Once the changes are approved and merged successfully, API publishers can choose to deploy them to the Production instance either on schedule or on demand. The deployment of the templates can be automated using [GitHub Actions](https://docs.github.com/en/actions), [Azure Pipelines](/azure/devops/pipelines), [Azure PowerShell](../azure-resource-manager/templates/deploy-powershell.md), [Azure CLI](../azure-resource-manager/templates/deploy-cli.md), or other tools. |
| 74 | +* Set up either [GitHub][22] or [Azure Repos][23] for your source code control system. This choice will determine your choice of pipeline runner as well. GitHub can use [Azure Pipelines][17] or [GitHub Actions][18], whereas Azure Repos must use Azure Pipelines. |
| 75 | +* Set up an Azure API Management service for each API developer so that they can develop API definitions along with the API service. Use the consumption or developer SKU when creating the service. |
| 76 | +* Use [policy fragments][24] to reduce the new policy that developers need to write for each API. |
| 77 | +* Use the [Azure API Ops Toolkit][5] to extract a working API definition from the developer service. |
| 78 | +* Set up an API approval process that runs on each pull request. The API approval process should include breaking change detection, linting, and automated API testing. |
| 79 | +* Use the [Azure API Ops Toolkit][5] publisher to publish the API to your production API Management service. |
71 | 80 |
|
| 81 | +Review [Automated API deployments with API Ops][28] in the Azure Architecture Center for more details on how to configure and run a CI/CD deployment pipeline with API Ops. |
72 | 82 |
|
73 |
| -With this approach, an organization can automate the deployment of API changes into API Management instances, and it's easy to promote changes from one environment to another. Because different API development teams will be working on different sets of API templates and files, it prevents interference between different teams. |
| 83 | +## References |
74 | 84 |
|
75 |
| -## Video |
| 85 | +* [Azure DevOps Services][25] includes [Azure Repos][23] and [Azure Pipelines][17]. |
| 86 | +* [Azure API Ops Toolkit][5] provides a workflow for API Management DevOps. |
| 87 | +* [Spectral][12] provides a linter for OpenAPI specifications. |
| 88 | +* [openapi-diff][13] provides a breaking change detector for OpenAPI v3 definitions. |
| 89 | +* [Newman][15] provides an automated test runner for Postman collections. |
76 | 90 |
|
77 |
| -> [!VIDEO https://www.youtube.com/embed/4Sp2Qvmg6j8] |
78 |
| -
|
79 |
| -## Next steps |
80 |
| - |
81 |
| -- See the open-source [Azure API Management DevOps Resource Kit](https://github.com/Azure/azure-api-management-devops-resource-kit) for additional information, tools, and sample templates. |
| 91 | +<!-- Links --> |
| 92 | +[1]: https://www.w3.org/TR/wsdl20/ |
| 93 | +[2]: https://www.openapis.org/ |
| 94 | +[3]: https://graphql.org/learn/schema/ |
| 95 | +[4]: https://github.com/Azure/azure-api-management-devops-resource-kit |
| 96 | +[5]: https://github.com/Azure/APIOps |
| 97 | +[6]: https://github.com/mirsaeedi/dotnet-apim |
| 98 | +[7]: https://www.terraform.io/ |
| 99 | +[8]: https://code.visualstudio.com/ |
| 100 | +[9]: https://marketplace.visualstudio.com/search?term=OpenAPI&target=VSCode&category=All%20categories&sortBy=Relevance |
| 101 | +[10]: https://github.com/microsoft/cadl |
| 102 | +[11]: https://docs.github.com/en/pull-requests/collaborating-with-pull-requests/proposing-changes-to-your-work-with-pull-requests/about-pull-requests |
| 103 | +[12]: https://stoplight.io/open-source/spectral |
| 104 | +[13]: https://github.com/Azure/openapi-diff |
| 105 | +[14]: https://owasp.org/www-community/api_security_tools |
| 106 | +[15]: https://github.com/postmanlabs/newman |
| 107 | +[16]: https://learning.postman.com/docs/getting-started/creating-the-first-collection/ |
| 108 | +[17]: /azure/azure-resource-manager/templates/deployment-tutorial-pipeline |
| 109 | +[18]: https://github.com/marketplace/actions/deploy-azure-resource-manager-arm-template |
| 110 | +[19]: https://marketplace.visualstudio.com/items?itemName=charleszipp.azure-pipelines-tasks-terraform |
| 111 | +[20]: https://learn.hashicorp.com/tutorials/terraform/github-actions |
| 112 | +[21]: https://git-scm.com/ |
| 113 | +[22]: https://github.com/ |
| 114 | +[23]: /azure/devops/repos/get-started/what-is-repos |
| 115 | +[24]: ./policy-fragments.md |
| 116 | +[25]: https://azure.microsoft.com/services/devops/ |
| 117 | +[26]: https://github.com/microsoft/api-guidelines/blob/vNext/azure/Guidelines.md |
| 118 | +[27]: https://github.com/Azure/azure-api-style-guide |
| 119 | +[28]: /azure/architecture/example-scenario/devops/automated-api-deployments-apiops |
0 commit comments