Check if Resource ID contains specific word

I’m trying to figure how to check if an Azure subnet resource id contains a specific word. I’ve tried using contain/regex to no avail.

below are sample of what I’m doing:


variable "subnet_ids" {
    type = set(string)
    default = [
      "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Test-RG/providers/Microsoft.Network/virtualNetworks/mainVnet/subnets/subnet1",
      "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Test-RG/providers/Microsoft.Network/virtualNetworks/mainVnet/subnets/subnet2",
      "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Test-RG/providers/Microsoft.Network/virtualNetworks/mainVnet/subnets/subnet3",
      "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Test-RG/providers/Microsoft.Network/virtualNetworks/mainVnet/subnets/subnet4",
      "/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Test-RG/providers/Microsoft.Network/virtualNetworks/mainVnet/subnets/subnet5",
    ]
}

main.tf

resource "null_resource" "this" {
  for_each = var.subnet_ids
  triggers = {
    name = each.value    
  }
}
--# tried with below filters but doesn't seems to work
# name = can(regex("[subnet1|subnet2|subnet3]", each.value)) ? true : false
# name = contains(["subnet1",  "subnet2", "subnet3" ], each.value ) ? each.value : false

— output

# output "nic_ids" {
#     value = [
#         for i in null_resource.this : (contains(["subnet1",  "subnet2", "subnet3"], i )) ? i : null
#     ]
# }
# 

any thoughts on how to approach filtering, I just want to select specific ids from the list to operate only on those that meet the filter criteria?

Please look back at your post, and observe that the forum software has mangled it by interpreting characters as formatting.

You must enclose code blocks with lines containing only ``` before and after to avoid this.