Search code examples
azureazure-active-directoryazure-web-app-serviceazure-keyvault

is it posible to access Azure App Configuration via URL or conected some how as enviroment setting of App Service?


On my App Service i have several KeyVaults pinting to diferents URL's. I create a layer on App Configuration that depending if the Label point to Dev-DB, QA-DB, o Stage-DB Change the database of the App Service.

All my app services have on Environment variables, inside Connection strings all the diferent databases. Inside of the Value i have this: "@Microsoft.KeyVault(SecretUri=https://{MyKeyvault}.vault.azure.net/secrets/{MyVariable}/)+\"Application Name={UserOfDB};\"",

And i want to use somthing like this: "@Microsoft.AppConfiguration(https://{MyAppConfig}.azconfig.net;Id={IdConfig};Secret={MySecret};Key={MyVariable};Label=${MyEnviromentVariable}) + \"Application Name={UserOfDB};\"",

But it gave me this error: Identity: System assigned managed identity Status: InvalidSyntax Error details: Reference was not able to be resolved because invalid reference syntax found.

I just need a way to easy switch between Databases without losing my mind in the process.


Solution

  • is it posible to access Azure App Configuration via URL or conected some how as enviroment setting of App Service?

    Yes, it is possible to access the App Configuration keys as @Microsoft.AppConfiguration in the Azure App Service Environment Variables.

    Check the below work around to add key as AppConfiguration reference in App Service:

    • In App Configuration, add new keys with Key-Value and Key Vault reference.

    • I have created 2 keys with each 1 option.

    enter image description here

    • In App Configuration, navigate to Import/export option to export the keys to the required Target(I have selected App Service).

    enter image description here

    • Click on select the resource and select your Azure App Service.

    enter image description here

    • Select the option Export as reference and click on Apply.

    enter image description here

    • Now in App Service App Settings, you can see the keys are exported as App Configuration.

    enter image description here

    • Your error indicates the syntax of the reference is incorrect.
    • My configuration reference syntax,
    @Microsoft.AppConfiguration(Endpoint=https://harshuappconfig.azconfig.io; Key=SampleKey)
    
    • Endpoint key is missing in your reference.

    • Initially I got the below error.

    MSINotEnabled - Reference was not able to be resolved because site Managed Identity not enabled.
    
    • Enable Identity option for Azure App Service.

    enter image description here

    • Now I got another error.
    App Configuration reference was not resolved because site was denied access to the App Config store.
    
    • I have tried to add the same for Connection String, got the access error.

    With Import/Export option, it is clear that adding Configuration settings with App Configuration reference is possible. But make sure you have enough permissions to access the App Configuration.