2

When creating some Azure resources such as MetricAlert (https://www.pulumi.com/docs/reference/pkg/azure-native/insights/metricalert/) I have come across the the InputMap type.

As you can see from the MetricAlert documentation, in some scenarios you need to pass in references to other resources in the Tags property. Intellisense shows me Tags is an InputMap which accepts Output<> for the values... but unfortunately the way this works is that the reference needs to be passed in as the key - the value is just the string "Resource".

Is there any way I can pass in my Output into these tags, it is becoming a blocker for getting these alerts into our stack.

    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" },
    },
DaveBeta
  • 447
  • 1
  • 5
  • 11

1 Answers1

3

You'd need to use Apply to build such a dictionary. For a single key:

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

for two keys:

Tags = Output.Tuple(resource1.Id, resource2.Id).Apply(items => new Dictionary<string, string>
{
    { $"hidden-link:{items.Item1}", "Resource" },
    { $"hidden-link:{items.Item2}", "Resource" },
}),
Mikhail Shilkov
  • 34,128
  • 3
  • 68
  • 107
  • I couldn't find any examples doing this and I hadn't realised I just needed to create a dictionary and there is an implicit cast. Thank you!! – DaveBeta Sep 02 '21 at 22:10