Hi!
I am trying to find a way to apply advanced filters to event subscription. I need to create 3 event subscription for that I have used for each and for advanced filter I have used nested dynamic block. below is my code snippet.
resource "azurerm_eventgrid_system_topic_event_subscription" "subscription" {
for_each = var.event_sub_name
name = each.key
system_topic = each.value.system_topic
resource_group_name = "test-grp"
event_delivery_schema = "EventGridSchema"
advanced_filtering_on_arrays_enabled = true
service_bus_queue_endpoint_id = try(each.value.service_bus_queue_endpoint_id, null)
included_event_types = each.value.included_event_types
dynamic "advanced_filter" {
#for_each = length(try(var.event_sub_name[1].advanced_filter[0], [])) != 0 ? [var.event_sub_name[1].advanced_filter] : []
for_each = var.event_sub_name[each.key].advanced_filter != null ? ["advanced_filter"] : []
content {
dynamic "string_contains" {
#for_each = lookup(var.event_sub_name[each.key].advanced_filter, "string_contains", {}) != {} ? ["string_contains"] : []
for_each = lookup(var.event_sub_name[each.key].advanced_filter, "string_contains", {}) != {} ? ["string_contains"] : []
content {
key = lookup(var.event_sub_name.advanced_filter, "string_contains.key", null)
values = lookup(var.event_sub_name.advanced_filters, "string_contains.values", null)
}
}
}
}
I have passed values in yml file as mentioned below:
event_subscription:
event_sub:
"test-evt":
system_topic : "systemtopic2"
service_bus_queue_endpoint_id : "/subscriptions/subscription_id/resourceGroups/test-grp/providers/Microsoft.ServiceBus/namespaces/cru-sub/queues/crudocroutinginboundqueuedev"
storage_queue_endpoint : null
included_event_types : ["Microsoft.Storage.BlobCreated", "Microsoft.Storage.BlobDeleted" ]
retry_policy : [
{
"event_time_to_live": "1000",
"max_delivery_attempts": "3"
}
]
advanced_filter:
{
"string_contains" : {
key : "subject",
values : ["scan-poor"]
}
}
I am getting below error:
Error: Unsupported attribute
│
│ on .terraform\modules\event_subscription\eventgrid.tf line 46, in resource "azurerm_eventgrid_system_topic_event_subscription" "subscription":
│ 46: values = lookup(var.event_sub_name.advanced_filters, "string_contains.values", null)
│ ├────────────────
│ │ var.event_sub_name is object with 3 attributes
│
│ This object does not have an attribute named "advanced_filters".