For_each Azure multiregion deployment

A little context on the environment I am wanting to deploy.
I am wanting to deploy to multiple regions based off of a variable region list. I have been trying the for_each command but keep getting "The “each” object can be used only in “module” or “resource” blocks, and only when the “for_each” argument is set.

I am just wanting to be able to set the regions in the variable list and have the location put to that list either through a for_each command or something that I’m missing.

variable “vm_regions” {
type = list(string)
description = “Location of the virtual machines”
default = [“japaneast”, “southcentralus”, “germanynorth”]

resource “azurerm_resource_group” “vm_regions” {
for_each = var.vm_regions
name = each.key
location = each.value

As the variable is of type list(string) you’d need some additional tweaks or just provide a map as input as the items have to be unique.
You could try:

resource "azurerm_resource_group" "vm_regions" {
  for_each = toset(var.vm_regions)
  name = each.key
  location = each.key