Locals seems to be evaluated before the resource they are leaning on

Hi,
I made locals that get aws_instances output from another module.
the instances module:

resource "aws_instance" "aws_instances" {
	count                  = 2

	...

	tags = {
		Name = "${var.one}-${var.two}-${count.index + 1}"
        }
}

output "aws_instances" {
  value = aws_instance.aws_instances
}

the module the locals are in:

locals {
  map_tag_name_to_private_ip = {
    for instance in var.aws_instances:
    split("-", instance.tags.Name)[1] => instance.private_ip
  }
}

when i changed in the locals:

    split("-", instance.tags.Name)[1] => instance.private_ip

to

    split("-", instance.tags.Name)[0] => instance.private_ip

and also in response changed in the resource tags:

		Name = "${var.emphasized textone}-${var.two}-${count.index + 1}"

to

		Name = "${var.two}-${var.one}-${count.index + 1}"

i get an error of key duplication. terraform did not changed the tags of the instances and thus get key duplication from var.two, but i had expected for terraform to first change the resource tags and later on evaluate the locals.

any thoughts? help?

thanks

(ps IDK why there is a weird formatting, i tried to copy from plain text app and edit without success)