Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enabling advanced_filtering_on_arrays_enabled #12609

Merged
merged 10 commits into from
Jul 22, 2021
12 changes: 12 additions & 0 deletions azurerm/internal/services/eventgrid/event_subscription.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,14 @@ func eventSubscriptionSchemaIncludedEventTypes() *pluginsdk.Schema {
}
}

func eventSubscriptionSchemaEnableAdvancedFilteringOnArrays() *pluginsdk.Schema {
return &pluginsdk.Schema{
Type: pluginsdk.TypeBool,
Optional: true,
Default: false,
}
}

func eventSubscriptionSchemaSubjectFilter() *pluginsdk.Schema {
return &pluginsdk.Schema{
Type: pluginsdk.TypeList,
Expand Down Expand Up @@ -991,6 +999,10 @@ func expandEventGridEventSubscriptionFilter(d *pluginsdk.ResourceData) (*eventgr
filter.AdvancedFilters = &advancedFilters
}

if v, ok := d.GetOk("advanced_filtering_on_arrays_enabled"); ok {
filter.EnableAdvancedFilteringOnArrays = utils.Bool(v.(bool))
}

return filter, nil
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ func resourceEventGridEventSubscription() *pluginsdk.Resource {
"retry_policy": eventSubscriptionSchemaRetryPolicy(),

"labels": eventSubscriptionSchemaLabels(),

"advanced_filtering_on_arrays_enabled": eventSubscriptionSchemaEnableAdvancedFilteringOnArrays(),
},
}
}
Expand Down Expand Up @@ -305,6 +307,7 @@ func resourceEventGridEventSubscriptionRead(d *pluginsdk.ResourceData, meta inte

if filter := props.Filter; filter != nil {
d.Set("included_event_types", filter.IncludedEventTypes)
d.Set("advanced_filtering_on_arrays_enabled", filter.EnableAdvancedFilteringOnArrays)
if err := d.Set("subject_filter", flattenEventGridEventSubscriptionSubjectFilter(filter)); err != nil {
return fmt.Errorf("Error setting `subject_filter` for EventGrid Event Subscription %q (Scope %q): %s", id.Name, id.Scope, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func TestAccEventGridEventSubscription_filter(t *testing.T) {
check.That(data.ResourceName).Key("included_event_types.1").HasValue("Microsoft.Storage.BlobDeleted"),
check.That(data.ResourceName).Key("subject_filter.0.subject_ends_with").HasValue(".jpg"),
check.That(data.ResourceName).Key("subject_filter.0.subject_begins_with").HasValue("test/test"),
check.That(data.ResourceName).Key("advanced_filtering_on_arrays_enabled").HasValue("true"),
),
},
data.ImportStep(),
Expand Down Expand Up @@ -489,6 +490,8 @@ resource "azurerm_eventgrid_event_subscription" "test" {
queue_name = azurerm_storage_queue.test.name
}

advanced_filtering_on_arrays_enabled = true

included_event_types = ["Microsoft.Storage.BlobCreated", "Microsoft.Storage.BlobDeleted"]

subject_filter {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ func resourceEventGridSystemTopicEventSubscription() *pluginsdk.Resource {
"retry_policy": eventSubscriptionSchemaRetryPolicy(),

"labels": eventSubscriptionSchemaLabels(),

"advanced_filtering_on_arrays_enabled": eventSubscriptionSchemaEnableAdvancedFilteringOnArrays(),
},
}
}
Expand Down Expand Up @@ -277,6 +279,7 @@ func resourceEventGridSystemTopicEventSubscriptionRead(d *pluginsdk.ResourceData

if filter := props.Filter; filter != nil {
d.Set("included_event_types", filter.IncludedEventTypes)
d.Set("advanced_filtering_on_arrays_enabled", filter.EnableAdvancedFilteringOnArrays)
if err := d.Set("subject_filter", flattenEventGridEventSubscriptionSubjectFilter(filter)); err != nil {
return fmt.Errorf("Error setting `subject_filter` for EventGrid System Topic Event Subscription %q (System Topic %q): %s", id.Name, id.SystemTopic, err)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func TestAccEventGridSystemTopicEventSubscription_filter(t *testing.T) {
check.That(data.ResourceName).Key("included_event_types.1").HasValue("Microsoft.Storage.BlobDeleted"),
check.That(data.ResourceName).Key("subject_filter.0.subject_ends_with").HasValue(".jpg"),
check.That(data.ResourceName).Key("subject_filter.0.subject_begins_with").HasValue("test/test"),
check.That(data.ResourceName).Key("advanced_filtering_on_arrays_enabled").HasValue("true"),
),
},
data.ImportStep(),
Expand Down Expand Up @@ -554,6 +555,8 @@ resource "azurerm_eventgrid_system_topic_event_subscription" "test" {
queue_name = azurerm_storage_queue.test.name
}

advanced_filtering_on_arrays_enabled = true

included_event_types = ["Microsoft.Storage.BlobCreated", "Microsoft.Storage.BlobDeleted"]

subject_filter {
Expand Down
1 change: 1 addition & 0 deletions website/docs/r/eventgrid_event_subscription.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ The following arguments are supported:

* `labels` - (Optional) A list of labels to assign to the event subscription.

* `advanced_filtering_on_arrays_enabled` - (Optional) Specifies whether advanced filters should be evaluated against an array of values instead of expecting a singular value. Defaults to `false`.
---

A `storage_queue_endpoint` supports the following:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ The following arguments are supported:

* `labels` - (Optional) A list of labels to assign to the event subscription.

* `advanced_filtering_on_arrays_enabled` - (Optional) Specifies whether advanced filters should be evaluated against an array of values instead of expecting a singular value. Defaults to `false`.

---

A `storage_queue_endpoint` supports the following:
Expand Down