cisco-open / terraform-provider-meraki

A Terraform Provider for Cisco Meraki
Mozilla Public License 2.0
15 stars 6 forks source link

Add in filter block option for data lookups #68

Open finkjordanj opened 3 months ago

finkjordanj commented 3 months ago

Is your feature request related to a problem? Please describe. Add in an option of filter blocks within terraform so that I can do a data lookup on an object with multiple returns but only have it return based on a filter options. This would help when needing to lookup a network id based on a tag/name/other value.

Currently if i need to lookup a existing network id. i must do a data lookup on all my networks and then using a terraform loop i can loop through and set a local value of what I am trying to get.

For me to get one network id i must first pull in all the networks and then loop through until i can find the one with the correct name. While it works it does make my state file much larger than it needs due to the data lookup ultimately returning all networks instead of just the one.

data "meraki_networks" "dev_networks" {
  organization_id = local.organization_id
}

locals {
  this_network = [for network in data.meraki_networks.dev_networks.items : network if network.name == "750-comm-meraki-lab"][0]
}

Describe the solution you'd like If we can add in a filter block similar to the AWS's registery filter block on their data lookups.

data "meraki_networks" "dev_networks" {
  organization_id = local.organization_id
  filter {
    name = "name"
    value = "750-comm-meraki-lab"
  }
}

If this works then the name would equal the key in the returned and value would be the value on the lookup. This would ideally then do the loop for me ahead of actually storing anything in state and only store the returned value of the one ID.

Describe alternatives you've considered The current workaround does work, but each site will essentially be storing all sites ids rather than just their own.

Additional context I am not familiar enough with Go to know exactly how AWS Terraform base code does their filter as their registry is quite extensive.