Filter multiple Event Types on Pulumi AzureNative Event Grid Topic Subscription

Viewed 91

I create Event Grid Topic Subscriptions to Service Bus Queues:

var args = new EventSubscriptionArgs
{
   EventSubscriptionName = topic.SubscriptionName,
   Scope = topic.Id,
   Destination = new Pulumi.AzureNative.EventGrid.Inputs.ServiceBusQueueEventSubscriptionDestinationArgs
   {
     EndpointType = "ServiceBusQueue",
     ResourceId = queue.Id
   },
};

var sub=new EventSubscription(
  topic.SubscriptionName,
  args
); 

This works fine. Now I want to add a filter to only allow specific Event Types. According to the documentation I can add Filters like those:

args.Filter=new Pulumi.AzureNative.EventGrid.Inputs.EventSubscriptionFilterArgs
{
  SubjectBeginsWith="the_topic",
  SubjectEndsWith="the_topic"
}

But this is just one Topic, obviously. I need to be able to add an array of filters.

I expect that this can be done by EnableAdvancedFilteringOnArrays and AdvancedFilters somehow. But those properties aren't described anywhere (or I just wasn't able to find that information)

according to the documentation, AdvancedFilters is of type List<object> and I did not find any information what kind of object is expected there to be able to add multiple filters.

2 Answers

Haven’t used Pulumi, but I would suggest looking into the MSFT docs for Advanced filters (link) together with the docs on the operator you want to use, in your case stringBeginsWith.

As you can see the filtering should be applied in a key-value manner together with the operator to be used.

The Pulumi docs were half helpful. They showed the object you need to use but forget to mention the class is in the Pulumi.AzureNative.EventGrid.Inputs namespace. Below is a code snippet for creating the Pulumi.AzureNative.EventGrid.EventSubscription object. The Azure docs list the different type of filters you can use.

Filter = new AzureNative.EventGrid.Inputs.EventSubscriptionFilterArgs
{
    IncludedEventTypes = new[]
    {
        "Microsoft.Devices.DeviceTelemetry"
    },
    AdvancedFilters = new[]
    {
        new Pulumi.AzureNative.EventGrid.Inputs.StringInAdvancedFilterArgs
        {
            OperatorType = Pulumi.AzureNative.EventGrid.AdvancedFilterOperatorType.StringIn.ToString(),
            Key= "data.MyProperty",
            Values= new[] { "MyValue" }
        }
    }
},
Related