0

When I inject IConfiguration in a function, it does not find any keys that only live in my "Azure App Configuration".

I have a functionApp (V3) that accesses App Configuration using the DefaultAzureCredential. I am running this locally in debug hence the need for a default credential. I also have multiple Tenants so I had to set the VisualStudioTenantId and SharedTokenCacheTenantId on DefaultAzureCredentialOptions. My Visual studio user was also given the role "App Configuration Data Reader" to be able to debug.

When connecting to App configuration I get no errors. Editedto add: I have setup AppConfiguration to authenticate with AzureAD.

See code below:

public override async void ConfigureAppConfiguration(IFunctionsConfigurationBuilder builder)
{
    var credOptions = new DefaultAzureCredentialOptions();

    var tenantId = Environment.GetEnvironmentVariable("Tenant_Id");

    credOptions.VisualStudioTenantId = tenantId;
    
    credOptions.SharedTokenCacheTenantId = tenantId;

    var cred = new DefaultAzureCredential(credOptions);

    /*Works but requires SharedTokenCacheTenantId*/
    var secretClient = new SecretClient(new Uri(vaultURI), cred);
    var secret = await secretClient.GetSecretAsync("<secret name>");

    /*Works but where are my keys when I try to access them?*/
    builder.ConfigurationBuilder.AddAzureAppConfiguration(options =>
    {
        options.Connect(new Uri(appConfigURI), cred);
        
    }).Build(); //Should I be building this??

}

In my function

public FunctName(IConfiguration configuration)
{
    _configuration = configuration;
}

And when I access the property

var prop = _configuration["PropertyName"];
Griddy
  • 93
  • 1
  • 8

2 Answers2

0

There is an example function app that uses IFunctionsConfigurationBuilder here https://github.com/Azure/AppConfiguration/blob/main/examples/DotNetCore/AzureFunction/FunctionApp/Startup.cs . I would recommend taking a look and seeing if there are any missing pieces.

The title mentions "using DefaultAzureCredential on local". Does that mean that this works as expected if you use a connection string?

J. Campbell
  • 680
  • 4
  • 5
  • Hi, this is the example I followed. Looks like `builder.Services.AddAzureAppConfiguration();` is not injecting my configuration so I have logged a bug on the Azure/AppConfiguration forum. Will keep you updated. – Griddy Mar 19 '21 at 06:26
  • I have to hang my head in shame - notice the async void ConfigureAppConfiguration. This caused my ConfigureAppConfiguration to not await, causing configure to add my App Configuration before it was populated. – Griddy Mar 19 '21 at 06:53
0

Notice the async void ConfigureAppConfiguration. This caused my ConfigureAppConfiguration to not execute synchronously, causing configure to add my App Configuration before it was populated.

Griddy
  • 93
  • 1
  • 8