How can I update the AppSettings of a FunctionApp resource in Pulumi?
Context:
After retrieving the connection string from a recently declared Service Bus Namespace resource, I now need to update the AppSettings property of a recently declared FunctionApp resource.
Resource Declaration:
var functionApp = appProfile.Items.Single(p => p.Key == "Name").Value;
return
new FunctionApp(functionApp, new()
{
Name = functionApp,
Location = resourceGroup.Location,
ResourceGroupName = resourceGroup.Name,
AppServicePlanId = plan.Id,
StorageAccountName = storageAccount.Name,
AppSettings = new InputMap<string>() { appSettings },
StorageAccountAccessKey = storageAccount.PrimaryAccessKey,
});
Connection String:
I assume a connection string can only be realized after a resource has been provisioned in Azure.
var namespaceKeys =
Output.Tuple(busNamespace.Name, authRule.Name)
.Apply(async entries => await ServiceBus.ListNamespaceKeys.InvokeAsync(new ServiceBus.ListNamespaceKeysArgs
{
NamespaceName = entries.Item1,
AuthorizationRuleName = entries.Item2,
ResourceGroupName = resourceGroup.GetResourceName()
}));
var connectionString = namespaceKeys.Apply(ns => ns.PrimaryConnectionString);
So how can I include the connection string, as an AppSetting to a FunctionApp resource, that is pending Service Bus Namespace creation?
I learned that I don't need to update the app settings of an Azure Function App. Instead, I need to rely on the type/utility, ServiceBus.ListNamespaceKeysArgs.
Example:
For a service bus connection string, the following example can be leveraged:
using Pulumi;
using Pulumi.AzureNative.Resources;
using ServiceBus = Pulumi.AzureNative.ServiceBus;
namespace IaC.MyApp.Client;
public static class ConnectionString
{
public static Output<string> Get(ResourceGroup resourceGroup, ServiceBus.Namespace busNamespace, ServiceBus.NamespaceAuthorizationRule authRule)
{
var namespaceKeys =
Output.Tuple(busNamespace.Name, authRule.Name)
.Apply(async entries => await ServiceBus.ListNamespaceKeys.InvokeAsync(new ServiceBus.ListNamespaceKeysArgs {
NamespaceName = entries.Item1,
AuthorizationRuleName = entries.Item2,
ResourceGroupName = resourceGroup.GetResourceName()
}));
return namespaceKeys.Apply(ns => ns.PrimaryConnectionString);
}
}
Client:
Here's the client code:
var connectionString = ConnectionString.Get(resourceGroup, busNamespace, authRule);
Prerequisites:
Note that a NamespaceAuthorizationRule needs to be declared as a prerequisite to getting the connection string of a service bus in Azure.
The following declaration is an example:
new NamespaceAuthorizationRule(ruleName, new NamespaceAuthorizationRuleArgs {
AuthorizationRuleName = ruleName,
NamespaceName = busNamespace.Name,
ResourceGroupName = resourceGroup.Name,
Rights = new[] { AccessRights.Listen,
AccessRights.Send
}
});