Pulumi:如何更新AppFunction的AppSettings



如何在Pulumi中更新一个FunctionApp资源的AppSettings ?

背景:

从最近声明的服务总线命名空间资源中检索连接字符串后,我现在需要更新最近声明的FunctionApp资源的AppSettings属性。

资源宣言:

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,
});

连接字符串:

我假设只有在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);

那么我如何包括连接字符串,作为AppSetting到一个FunctionApp资源,这是等待服务总线命名空间的创建?

我了解到我不需要更新Azure Function app的应用程序设置。相反,我需要依赖类型/实用程序ServiceBus.ListNamespaceKeysArgs

例子:

对于服务总线连接字符串,可以利用以下示例:

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);
}
}
客户:

下面是客户端代码:

var connectionString = ConnectionString.Get(resourceGroup, busNamespace, authRule);

先决条件:

注意,需要声明NamespaceAuthorizationRule作为在Azure中获取服务总线连接字符串的先决条件。

下面的声明是一个例子:

new NamespaceAuthorizationRule(ruleName, new NamespaceAuthorizationRuleArgs {
AuthorizationRuleName = ruleName,
NamespaceName     = busNamespace.Name,
ResourceGroupName = resourceGroup.Name,
Rights = new[] { AccessRights.Listen,
AccessRights.Send
}
});

相关内容

  • 没有找到相关文章

最新更新