Search code examples
.netazureappsettings

Import key-vault reference azure app settings


I'm using portal to import JSON file which contains key-value pairs. Need help in importing key-valult references.

I prepare a json file like

{
  AppSettings: {
     "testKey": "testValue",
     "testSecrete": "<akv-Reference-TestSecreteKey>"
   }
}

what should I add in place "akv-Reference-TestSecreteKey", so that when I import this file it add as key-vault reference.

While Import I choose:

  1. Type: Configuration File
  2. Code: .Net enter image description here

I tried this

{
    "AppSettings": {        
        "Test": "testValue",
            "TestSceret": "@Microsoft.KeyVault(SecretUri=
https://xyz.vault.azure.net/secrets/SecretValue/)"
    }
}

But it added as key-value, with value same as @Microsoft.KeyVault(S...


Solution

  • Found the answer from my colleague, we need to separate our json file from regular keys, and key vault secrets.

    key vault secret json will look like

    {
        "AppSettings": {        
            "testKey": "{\"uri"\: \"https://xyz.vault.azure.net/secrets/SecretValue/")"
        }
    }
    

    And while importing there will be different contentType something like 'application/vnd.microsoft.appconfig.keyvaultref+json;charset=utf-8'.

    This will add key as keyvault reference.