[英]Pulumi: How to update AppSettings of an AppFunction
如何在 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
}
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.