Merging two Azure API Management services together
Posted on: June 3, 2024Azure API Management has over the years become a very popular service in Azure. Over the years many practices with APIM have matured including DevOps and CI/CD practices.
Previously there was Azure API Management DevOps Resource Kit and currently there is Azure APIOps Toolkit.
Many customers are using Infrastructure as Code (IaC) to manage their APIM instances. If you have all that in place, then making even larger changes to the environment should not be too daunting task.
I was working with one customer who had two APIM instances for their internal integrations and they wanted to merge them together. Before merging two Azure API Management services together, they had the following setup:
They wanted to merge these two APIM instances together and this was the interim state:
And course, after the successful merge, the final state is this:
One thing they didn’t yet have a solution in their process: how to handle the subscription keys. They had already quite a lot of integrations connecting to another instance they planned to merge into the main instance. They wanted to keep the subscription keys the same for the existing customers. It should be “seamless” for their customers.
Luckily, there are Get-AzApiManagementSubscriptionKey cmdlet for getting the subscription keys and New-AzApiManagementSubscription cmdlet for creating a new subscription with existing keys:
# Export
Get-AzApiManagementSubscription `
-Context $apimContextSource
# Import
New-AzApiManagementSubscription `
-Context $apimContextTarget `
-Name $subscriptionName `
-Scope $scope `
-PrimaryKey $primarySubscriptionKey `
-SecondaryKey $secondarySubscriptionKey `
I created a small example PowerShell script to handle the subscription key move:
- Export the subscription keys from the source APIM to a CSV file
- Allows you to review the CSV file and make any necessary manual changes
- There is
ToBeImported
column indicating if the subscription key should be imported to the target APIM
- There is
- Import the subscription keys to the target APIM from the CSV file
Here is the script:
Btw… aka.ms/apimlove is good link collection to APIM resources.
I hope you find this useful!