.net - Pulumi InputMap<string> - 如何使用资源输出作为键?

标签 .net .net-core pulumi

在创建一些 Azure 资源(例如 MetricAlert ( https://www.pulumi.com/docs/reference/pkg/azure-native/insights/metricalert/ ))时,我遇到了 InputMap 类型。

正如您从 MetricAlert 文档中看到的,在某些情况下您需要在 Tags 属性中传入对其他资源的引用。 Intellisense 向我展示了 Tags 是一个 InputMap,它接受 Output<> 作为值...但不幸的是,它的工作方式是引用需要作为键传入 - 值只是字符串“Resource”。

有什么方法可以将我的输出传递到这些标签中,它正在成为将这些警报放入我们的堆栈的拦截器。

    Tags = 
    {
        { "hidden-link:/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/components/webtest-name-example", "Resource" },
        { "hidden-link:/subscriptions/12345678-1234-1234-1234-123456789101/resourcegroups/rg-example/providers/microsoft.insights/webtests/component-example", "Resource" },
    },

最佳答案

您需要使用Apply来构建这样的字典。对于单个 key :

Tags = otherResource.Id.Apply(id => new Dictionary<string, string>
{
    { $"hidden-link:{id}", "Resource" },
}),

对于两个键:

Tags = Output.Tuple(resource1.Id, resource2.Id).Apply(items => new Dictionary<string, string>
{
    { $"hidden-link:{items.Item1}", "Resource" },
    { $"hidden-link:{items.Item2}", "Resource" },
}),

关于.net - Pulumi InputMap<string> - 如何使用资源输出作为键?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69016321/

相关文章:

c# - 未能创建 CoreCLR,HRESULT : 0x80070057

.net-core - 如何使用 Cake 从私有(private) VSTS 源恢复私有(private) NuGet 包

amazon-web-services - 如何在Pulumi中实现共享资源

python - VS Code 无法识别 Pulumi 和 Pulumi Azure Native

typescript - Pulumi 在运行时获取 kubernetes 上下文

asp.net - 在我的 VS 2013 环境中获取 ASP.NET 4.5(安装或升级)

c# - 表达式树中的 ArrayAccess 与 ArrayIndex

.net - 以编程方式使用 "Microsoft Save as PDF"加载项而不安装 Word

c# - 处理winform应用程序中的意外事件

c# - .net 核心中的库配置?