Get matching element

Hi - This is my remote state file output. How can I find value matching the string ‘APPGATEWAYS’. Any help is appreciated.

   "vnet_subnet_ids": {
      "value": [
      "type": [

I tried to use lookup but getting the following error
Invalid value for "inputMap" parameter: lookup() requires a map as the first argument

Hi @KalyanSista,

With the information you shared I can’t give a complete example, but I think you could get the result you are looking for by using a for expression with an if clause for filtering:

  for v in data.terraform_remote_state.example.vnet_subnet_ids : v
  if split("/", v)[10] == "APPGATEWAYS"

Alternatively, you could transform the list into a map and then access it by key:

locals {
  subnet_ids = {
    for v in data.terraform_remote_state.example.vnet_subnet_ids :
    split("/", v)[10] => v

The above should produce a map like this:

  "APPGATEWAYS": "/subscriptions/redacted/resourceGroups/redacted/providers/Microsoft.Network/virtualNetworks/sample-vnet-1/subnets/APPGATEWAYS",
  "SUB-2": "/subscriptions/redacted/resourceGroups/redacted/providers/Microsoft.Network/virtualNetworks/sample-vnet-2/subnets/SUB-2"

…so you could then write local.subnet_ids["APPGATEWAYS"] elsewhere in your module to find the full id string.