Azure function key vault data not accessible from .net core
I have an Azure function app .Net core solution from where, I am trying to access Azure key vault data, when the app is deployed. When in my local (development mode), I am accessing the key vault data from a local file (which is not deployed). Also, I want to have two more config files which will be deployed along with the app and will be used as per the environment where it is deployed.
I am stuck at one point..I am using three json files
* local.settings.json (for local)
* prod.settings.json (for prod)
* dev.settings.json (for non prod)
This is how I am configuring in my startup:
`if(env=prod)
{
var configBuilder = new ConfigurationBuilder()
.SetBasePath(applicationRootPath)
.AddJsonFile("prod.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
}
else
{
var configBuilder = new ConfigurationBuilder()
.SetBasePath(applicationRootPath)
.AddJsonFile("dev.settings.json", optional: true, reloadOnChange: true)
.AddEnvironmentVariables()
.Build();
}`
This is how I am accessing the data in startup:
var fromKeyVault=Environment.GetEnvironmentVariable("keyVaultKey");
var fromJson=configBuilder.GetValue("devKey");
both fromKeyVault and fromJson works perfectly in my local but when I try to deploy and test in non prod, fromKeyVault always returns null.
Do you see anything I can do to get a wayout of this issue.
The connection configuration has no issue between the .Net solution and Azure key vault.
Regards,
Debottam
I tried a few things like:
configBuilder.GetValue("keyVaultKey"); even this works well in my local but gives null in non prod.
The expectation is:
* The key vault values will be taken up from local.settings.json in my local env and when in prod/non prod, it should be coming from Azure key vault.
* In local, if any key is not present in local.settings.json then it should get it from dev.settings.json this behavior is also expected in environments.
0 comments:
Post a Comment
Thanks