1
votes

Our company is having multiple web services deployed each having three environments- Dev, Staging, and Production. Each environment has separate resource groups which contain application insights for the service. It's a tedious task to fetch the instrumentation key for each environment and set in the appsettings file. Instead, we want to automate this process in a way.

We are thinking in the direction- we will provide the application insight name as a placeholder which will get replaced to the actual instrumentation key at the deployment time after fetching it from the respective resource group.

I have gone through some articles but I'm unable to achieve same.

Please suggest me some approaches for the same.

1
What have you tried so far?evilSnobu
I have tried fetching the instrumentation key from the specific resource group and then replacing its value with the instrumentation key I received using Powershell script on my local machine. But I don't know whether it is a correct approach or not. @evilSnobuHarshvardhan Chittora
Are you using PowerShell on your build server to deploy your stuff? If yes, then that's the correct approach.evilSnobu
Yeah, I'm using a PowerShell on my build server. So, in this case, I need to create a variable associated with my appsettings which will replace the value after executing some commands... @evilSnobuHarshvardhan Chittora
@evilSnobu I am also having the same query! Can you suggest what should I do, if I am not using PowerShell.Pranay Deep

1 Answers

2
votes

TLDR:

  • Add an output to your ARM template
  • Pick that up in the release as an variable
  • Use it to change your configuration

Details: When you are using an ARM template for deploying Application Insights, you can specify the template to return the key as an output variable (https://docs.microsoft.com/en-us/azure/azure-resource-manager/resource-manager-templates-outputs). The ARM template deployment task can pick these outputs up and make it available as a variable with an JSON object. A more easy approach is the ARM Outputs extension (https://marketplace.visualstudio.com/items?itemName=keesschollaart.arm-outputs) where you can directly make each individual output available as an variable.

After that, the 'Deploy Service Fabric Application' task allows you to override application parameters if names match (not very self-documenting) or you can use the tokenized approach you mentioned earlier. There are numerous extensions that can do that, including: https://marketplace.visualstudio.com/items?itemName=qetza.replacetokens (haven't tried it myself)