How to change the snapshotname and snapshotarns depending on value passed to create Redis Cache

We are creating Elastic Cache using terraform scripts on providing snapshotname as identifier. But with new requirement we need to create redis using snapshotarns as well. We need to modify existing code to take snapshotarns so that esixting should not break.

Can we have logic to create redis to accept the values and variable should change to snapshotname or snapshotarns depending on velue we pass. Below is code we look to modify

resource "aws_elasticache_replication_group" "primary" {
  count    = local.params.redis.clustered == true && var.global_replication_group_id == "NoValue" ? 1 : 0
  provider = aws.workload

  description          = "${local.name_prefix}-elasticache master with 2 replica shards"
  replication_group_id = local.name_prefix

  #num_cache_clusters = lookup(local.params.redis, "num_cache_clusters", 2) #Per AWS support discussion this parameter is used when cluster mode disabled
  node_type                  = lookup(local.params.redis, "node_type", "cache.t2.small")
  port                       = lookup(local.params.redis, "port", 6379)
  engine                     = lookup(local.params.redis, "engine", "redis")
  engine_version             = lookup(local.params.redis, "engine_version", "7.0")
  parameter_group_name       = aws_elasticache_parameter_group.pg.name
  automatic_failover_enabled = lookup(local.params.redis, "automatic_failover_enabled", true)
  subnet_group_name          = aws_elasticache_subnet_group.subg.name
  security_group_ids         = [aws_security_group.elasticache_sg.id]
  maintenance_window         = lookup(local.params.redis, "maintenance_window", "wed:08:30-wed:09:30")
  apply_immediately          = true

  replicas_per_node_group = lookup(local.params.redis, "replicas_count", 1)
  num_node_groups         = lookup(local.params.redis, "num_node_groups", 1) #Same shards will be applied for secondary clusters
  multi_az_enabled        = lookup(local.params.redis, "multi_az_enabled", false)
  snapshot_name = local.params.redis.snapshot_identifier != "NoValue" ? local.params.redis.snapshot_identifier : null


  dynamic "timeouts" {
    iterator = timeouts
    for_each = length(keys(local.params.redis.elasticache_replication_group_timeouts)) > 0 ? [local.params.redis.elasticache_replication_group_timeouts] : []

    content {
      create = lookup(timeouts.value, "create", null)
      update = lookup(timeouts.value, "update", null)
      delete = lookup(timeouts.value, "delete", null)
    }
  }