user1220169
user1220169

Reputation: 813

Azure App Service Deployment Slot and Key Vault mapping in ADO Release pipelines

I have an Azure App Service where I want to have a Deployment Slot for doing zero-downtime deployments. The problem I am facing is, how to apply 2 different appsetting values for the "staging" deployment slot and production slot, for example if I want to point to 2 different DB connection strings.

  1. I cannot/do not want to do this directly via Azure Portal, but via ADO's Release Pipelines (Classic).
  2. My current Release Pipeline stages look like this: enter image description here

a. Stage 1 is to deploy new code to Staging Slot b. Stage 2 is to do a slot swap c. Stage 3 is optional for rollbacks (swap slot again)

  1. Within Stage-1 following is how things are setup: Stage-1: enter image description here

a. So I refer to a KeyVault (which contains production DB connection string for example) b. Stop the staging slot, deploy new code and start the slot up.

  1. Stage-2 is setup this way:

enter image description here

a. Here I do a slot swap between staging and production slots

Now my end goal is to basically have ConnectionStringA in the staging slot and ConnectionStringB in the production slot for DB appsettings which come from the KeyVault.What is the best way to accomplish this?

Possible solutions?

  1. One possible solution is to have 2 separate KeyVaults for Staging and Production slots. But I do not know how to use a different KeyVault in Stage-2, or if even that is possible to replace the key vault with another one before slot-swap.

  2. Another solution is to mark the DB connection string as "deployment slot setting", and maintain only the StagingDB connection string in KeyVault, that way the staging slot will use the staging DB string after deployment, but after a slot-swap, it will use the production setting. But this would mean, I need to maintain the Prod DB connection string in the Azure Portal itself on the production slot, without it coming from the KeyVault.

Let me know if there is a recommendation for the final goal of having 2 different appsettings on the staging slot and prod slot.

Upvotes: 0

Views: 441

Answers (1)

Vicnroll
Vicnroll

Reputation: 64

First, you don't need to stop your App Service to deploy in a deployment slot, I think you can skip that step.

Then, to have multiple connectiong strings, you can use Feature Flags, this let you enable some functionality based on some condition (the conditions are not required for the use of Feature Flags, but in your case it is).

Check the "How to filter feature flags" point. You can have multiple feature flags and set a label on each one. In your project, you can use this flags to filter your connectionString depending if it is production or no. You can store those connection into Azure Key Vault and pick the one you need based on that Feature Flag

Feature Flags configuration

Feature Flags management is located in the Azure portal, so with a few clicks you can modify the behavior of your application without redeploying it.

Upvotes: 0

Related Questions