如何通过Pulumi在C#中创建Function App的Host密钥
如何通过Pulumi使用C#创建Azure Function App的Host密钥
首先确认,Pulumi Azure Native provider已经原生支持Host级别的密钥创建,无需调用额外的自定义接口,以下是可直接运行的实现方案:
前置条件
- 已安装NuGet包:
Pulumi.AzureNative - 已完成Function App基础资源的创建
完整实现代码
using Pulumi; using Pulumi.AzureNative.AppService; using Pulumi.AzureNative.AppService.Inputs; class FunctionAppStack : Stack { public FunctionAppStack() { // 替换为你的资源组和Function App名称 var resourceGroupName = "your-resource-group"; var functionAppName = "your-function-app-name"; // 自定义Host密钥创建 var customHostKey = new WebAppHostKey("customHostKey", new WebAppHostKeyArgs { ResourceGroupName = resourceGroupName, Name = functionAppName, // 自定义的密钥名称 KeyName = "business-api-host-key", // 可选配置:如果不传入Value参数,Azure会自动生成安全随机密钥 Key = new HostKeyArgs { // 如需固定密钥值可取消注释下方配置 // Value = "your-custom-fixed-secret-value" } }); // 输出创建完成的密钥值,方便后续使用 this.GeneratedHostKey = customHostKey.Value; } [Output] public Output<string> GeneratedHostKey { get; set; } }
效果验证
执行pulumi up完成部署后,你可以在Azure Portal的Function App对应页面查看已创建的密钥,位置和下图示例一致:
内容的提问来源于stack exchange,提问作者Amaresh
相关产品推荐
相关产品推荐

