VPC rule association ids are getting recreated

I am trying to create multiple resolver rules in the central account and share the rule to the other accounts, and associate the shared rules with the VPC’s (it pulls teh vpc’id based on tag value). so my code creates the rule succesfully and share the rule to the other account. vpc association also work fine for the first run. but when add the new rule, vpc association code replace the association id. Can someone

We have two modules under root

  1. rule creation- Create resolver rule ID’s and share the rule to the other account
  2. vpc association - Associate the rule to the vpc ID’s based on the vpc tag values in the other account.

Issue - It runs fine fir the first run but VPC Association iD’s getting replaced when I add second rule.

Resolver rule id -

provider “aws” {
region = var.aws_region
}

locals {
resolver_rules_map = { for idx, rule in var.resolver_rules : idx => rule }
}

resource “aws_route53_resolver_rule” “rule” {
for_each = local.resolver_rules_map

name = each.value.name
domain_name = each.value.domain_name
rule_type = each.value.rule_type
resolver_endpoint_id = each.value.resolver_endpoint_id

target_ip {
ip = “10.1.1.1”
}

target_ip {
ip = “10.1.1.2”
}

tags = {
Environment = “Dev”
}
}

output “resolver_rule_ids” {

value = tomap ({
for k, rule in aws_route53_resolver_rule.rule : k=> rule.id
})

}

VPC_Association code
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.ids

}

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

}

From root module/main.tf

module “route53_resolver_rules” {

source = “./modules/resolver_rule_creation”

other configurations
}

module “resolver_associations” {

source = “./modules/vpc_association”

resolver_rule_ids = module.route53_resolver_rules.resolver_rule_ids

providers = {

aws.alternate = aws.alternate

}