Allow_overwrite route 53 record causes an error

With this config, Idea is to overwrite the existing route 53 record if the environment needs a DR . But I am getting this error -

RRSet with DNS name <dns_name>., type A, SetIdentifier dev-dr-primary, and marked as primary cannot be created because a non-failover RRSet with the same name and type already exists.

by default the first route53 record will be created and I am trying to overwrite the record conditionally

resource "aws_route53_record" "domain" {
  zone_id = var.route_53_zone
  name    = var.api_sub_domain
  type    = "A"

  alias {
    name                   = module.nlb.lb_dns_name
    zone_id                = module.nlb.lb_zone_id
    evaluate_target_health = false
  }
}


resource "aws_route53_health_check" "primary_health_check" {
    count           = var.create_dr_routing ? 1 : 0
  fqdn              = var.elb_domain
  port              = 443
  type              = "HTTPS"
  resource_path     = "/actuator/health"
  failure_threshold = "3"
  request_interval  = "30"

  tags = {
    Name = "dev-health-check"
  }
}

resource "aws_route53_record" "domain_primary" {
  count           = var.create_dr_routing ? 1 : 0
  zone_id         = var.route_53_zone
  name            = var.domain
  type            = "A"
  allow_overwrite = true
  health_check_id = aws_route53_health_check.primary_health_check[0].id

  alias {
    name                   = var.primary_domain
    zone_id                = var.primary_elb_zone_id
    evaluate_target_health = true
  }

    failover_routing_policy {
    type = "PRIMARY"
  }
  set_identifier = "dev-dr-primary"
  depends_on = [ aws_route53_health_check.primary_health_check ]
}

resource "aws_route53_record" "domain_secondary" {
  count           = var.create_dr_routing ? 1 : 0
  zone_id         = var.route_53_zone
  name            = var.domain
  type            = "A"
  alias {
    name                   = var.secondary_domain
    zone_id                = var.secondary_elb_zone_id
    evaluate_target_health = true
  }

    failover_routing_policy {
    type = "SECONDARY"
  }
  set_identifier = "dev-dr-secondary"
}```