You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过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对应页面查看已创建的密钥,位置和下图示例一致:
通过GUI创建Function App Host密钥的示例


内容的提问来源于stack exchange,提问作者Amaresh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 00:45:03