Cannot set Elasticache configuration_endpoint into route53_records

Hi

I tried to set aws_elasticache_replication_group configuration_endpoint_address into route53_record, but it returns following error.

Code

resource "aws_elasticache_replication_group" "this" {
  ...
  cluster_mode {
    replicas_per_node_group = var.replicas_per_node_group
    num_node_groups         = var.num_node_groups
  }
  automatic_failover_enabled = var.cluster_mode ? true : var.automatic_failover_enabled
}


resource "aws_route53_record" "primary" {
  count   = var.cluster_mode ? 1 : 0
  zone_id = "xxx"
  name    = "xxx"
  type    = "CNAME"
  ttl     = "60"
  records = [aws_elasticache_replication_group.this.configuration_endpoint_address]
  depends_on = [
    aws_elasticache_replication_group.this
  ]
}

resource "aws_route53_record" "single_primary" {
  count   = var.cluster_mode ? 0 : 1
  zone_id = "xxx"
  name    = "xxx"
  type    = "CNAME"
  ttl     = "60"
  records = [aws_elasticache_replication_group.this.primary_endpoint_address]
  depends_on = [
    aws_elasticache_replication_group.this
  ]
}

Error

│ Error: Null value found in list
│ 
│   with aws_route53_record.primary[0],
│   on main.tf line xx, in resource "aws_route53_record" "primary":
│   xx:   records = [aws_elasticache_replication_group.this.configuration_endpoint_address]
│ 
│ Null values are not allowed for this attribute value.

Wloud you know how to fix it ?