Flattern or setproduct

Hi I am trying to associate the route53 resolver rules id from other module to the vpc’s.

below is the code. it runs fine in the first run, but it tries to recreate the resolver_rule_associations, this happens when a new rule is added.

can i ask some guidance on this.
below is my code to flattern the resolver rule id’s and vpc ids

data “aws_vpcs” “selected” {
provider = aws.alternate
filter {
name = “tag:${var.vpc_tags.key}”
values = [var.vpc_tags.value]
}
}
output “vpc_id” {

value = data.aws_vpcs.selected.*.id

}

locals {
vpc_associations = flatten([
for vpc_id in data.aws_vpcs.selected.ids :
[for resolver_rule_id in var.resolver_rule_ids : {
resolver_rule_id = resolver_rule_id
vpc_id = vpc_id
}]
])
}

resource “aws_route53_resolver_rule_association” “dev” {
provider = aws.alternate

for_each = { for idx, assoc in local.vpc_associations : idx => assoc }

resolver_rule_id = each.value.resolver_rule_id
vpc_id = each.value.vpc_id

}