Restoring ElastiCache Clustered Redis Snapshot with Terraform

amazon-elasticacheterraform

Is it possible to create a ElastiCache Clustered Redis cluster from a snapshot using Terraform?

I don't see a Terraform option similar to the create-replication-group --node-group-configuration cli option.

Error:

Error creating Elasticache Replication Group: InvalidParameterCombination: Slots must be provided when restoring from snapshot ARNs with cluster mode enabled

Terraform:

resource "aws_elasticache_replication_group" "test-cluster" {
  replication_group_id          = "test-cluster"
  replication_group_description = "test cluster"
  node_type                     = "cache.r3.xlarge"
  parameter_group_name          = "default.redis3.2.cluster.on"
  port                          = 6379
  automatic_failover_enabled    = true
  subnet_group_name             = "${var.subnet_group_name}"
  security_group_ids            = ["${var.security_group_id}"]
  cluster_mode {
    replicas_per_node_group     = 3
    num_node_groups             = 3
  }
  snapshot_arns                 = ["${var.snapshot_arns}"]
}

Best Answer

Just got an answer from AWS , its not yet possible with terraform , you need to use sdk or cli or console to do that as this feature was added in last2016. https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/Replication.CreatingReplGroup.NoExistingCluster.Cluster.html#Replication.CreatingReplGroup.NoExistingCluster.Cluster.API

aws elasticache create-replication-group ^
  --replication-group-id rc-rg ^
  --replication-group-description "Sharded replication group" ^
  --engine redis ^
  --engine-version 3.2.4 ^
  --cache-parameter-group default.redis3.2.cluster.on ^
  --snapshot-retention-limit 8 ^
  --cache-node-type cache.m4.medium ^
  --num-node-groups 2 ^
  --node-group-configuration \
      "ReplicaCount=1,Slots=0-8999,PrimaryAvailabilityZone='us-east-1c',ReplicaAvailabilityZones='us-east-1b'" \
      "ReplicaCount=2,Slots=9000-16383,PrimaryAvailabilityZone='us-east-1a',ReplicaAvailabilityZones='us-east-1a','us-east-1c'"