Pulumi AzureNative栈创建EventGrid Topic无法获取PrimaryAccessKey问题
问题原因
Pulumi AzureNative 栈完全对齐 Azure 原生 REST API 的行为设计,访问密钥属于敏感信息,不会随资源的基础查询结果返回,因此 Topic 资源对象本身不直接暴露 PrimaryAccessKey、SecondaryAccessKey 属性,属于正常设计,并非功能遗漏或待开发。
旧版 Azure 经典栈在内部封装了密钥查询的调用逻辑,因此会直接将两个密钥属性挂载到资源对象上,两者的底层逻辑是一致的。
解决方法
你可以调用 AzureNative 提供的 ListTopicKeys 方法单独查询 EventGrid Topic 的访问密钥,示例代码如下:
using Pulumi.AzureNative.EventGrid; var topic = new Topic("eventgrid-topic-status", new TopicArgs { TopicName = "egt-status-dev", ResourceGroupName = "rg-testapp-dev", Location = "westeurope" }); // 调用列表密钥接口获取访问密钥 var topicKeys = ListTopicKeys.Invoke(new ListTopicKeysInvokeArgs { TopicName = topic.Name, ResourceGroupName = topic.ResourceGroupName }); // 提取对应密钥属性 var primaryAccessKey = topicKeys.Apply(keys => keys.PrimaryAccessKey); var secondaryAccessKey = topicKeys.Apply(keys => keys.SecondaryAccessKey); var endPointOutput = topic.Endpoint; // 可按需导出到栈输出 Pulumi.Export("topicPrimaryAccessKey", primaryAccessKey); Pulumi.Export("topicSecondaryAccessKey", secondaryAccessKey); Pulumi.Export("topicEndpoint", endPointOutput);
内容的提问来源于stack exchange,提问作者Joerg Krause
相关产品推荐
相关产品推荐

