Consul Data Provider filter by multiple tags

Hi,

i am currently having a hard time using the terraform consul provider, to fetch information of registered services from consul.

My goal is to filter the services with using multiple tags.

The current approach includes to first gather a list of services by using the consul_services (plural) datasource to get a list of all available services.

Unfortunately this list also sometimes returns empty service maps that canot be processed so I have to perform some manual cleanup. I also have better results with using allow_stale and require_consistent (not confident if this is the right way).

Then I try to use the consul_service with using for_each to gather further details of a service.

I want to distinguish by three service tiers and the stage and also named them frontend, backend, db.

This means I query by tier and by stage.

Unfortunately the consul_service ds only supports a single tag and it seems to perform no filtering at all.

Using the filter option mentioned in the documentation within the query_options fails with an error message:

│ Error: Unsupported argument

│ on main.tf line 20, in data “consul_service” “filter”:
│ 20: filter = “’{var.stage}' in tags and '{var.tier}’ in tags”

│ An argument named “filter” is not expected here.

My idea is to use the result and feed another ds resource block.

The code I am using:

data "consul_services" "all" {
  query_options {
    allow_stale = false
    require_consistent = true
  }
}

## using tag does not perform any filtering
#data consul_service stage {
#  for_each = toset(data.consul_services.all.names)
#  name = each.key
#  tag = var.stage
#}

# error message
data consul_service filtered {
  for_each = toset(data.consul_services.all.names)

  name = each.key
  query_options {
    filter = "'${var.stage}' in tags and '${var.tier}' in tags"
  }
}

output services {
  value = data.consul_service.filtered
  sensitive = true
}