Resource: aws_elasticache_replication_group

Provides an ElastiCache Replication Group resource.

For working with a Memcached cluster or a single-node Redis instance (Cluster Mode Disabled), see the aws_elasticache_cluster resource.

Example Usage

Redis Cluster Mode Disabled

To create a single shard primary with single read replica:

resource "aws_elasticache_replication_group" "example" {
  automatic_failover_enabled  = true
  preferred_cache_cluster_azs = ["us-west-2a", "us-west-2b"]
  replication_group_id        = "tf-rep-group-1"
  description                 = "example description"
  node_type                   = "cache.m4.large"
  num_cache_clusters          = 2
  parameter_group_name        = "default.redis3.2"
  port                        = 6379
}

You have two options for adjusting the number of replicas:

resource "aws_elasticache_replication_group" "example" {
  automatic_failover_enabled  = true
  preferred_cache_cluster_azs = ["us-west-2a", "us-west-2b"]
  replication_group_id        = "tf-rep-group-1"
  description                 = "example description"
  node_type                   = "cache.m4.large"
  num_cache_clusters          = 2
  parameter_group_name        = "default.redis3.2"
  port                        = 6379

  lifecycle {
    ignore_changes = [num_cache_clusters]
  }
}

resource "aws_elasticache_cluster" "replica" {
  count = 1

  cluster_id           = "tf-rep-group-1-${count.index}"
  replication_group_id = aws_elasticache_replication_group.example.id
}

Redis Cluster Mode Enabled

To create two shards with a primary and a single read replica each:

resource "aws_elasticache_replication_group" "baz" {
  replication_group_id       = "tf-redis-cluster"
  description                = "example description"
  node_type                  = "cache.t2.small"
  port                       = 6379
  parameter_group_name       = "default.redis3.2.cluster.on"
  automatic_failover_enabled = true

  num_node_groups         = 2
  replicas_per_node_group = 1
}

Redis Log Delivery configuration

resource "aws_elasticache_replication_group" "test" {
  replication_group_id       = "myreplicaciongroup"
  description                = "test description"
  node_type                  = "cache.t3.small"
  port                       = 6379
  apply_immediately          = true
  auto_minor_version_upgrade = false
  maintenance_window         = "tue:06:30-tue:07:30"
  snapshot_window            = "01:00-02:00"
  log_delivery_configuration {
    destination      = aws_cloudwatch_log_group.example.name
    destination_type = "cloudwatch-logs"
    log_format       = "text"
    log_type         = "slow-log"
  }
  log_delivery_configuration {
    destination      = aws_kinesis_firehose_delivery_stream.example.name
    destination_type = "kinesis-firehose"
    log_format       = "json"
    log_type         = "engine-log"
  }
}

Creating a secondary replication group for a global replication group

A Global Replication Group can have one one two secondary Replication Groups in different regions. These are added to an existing Global Replication Group.

resource "aws_elasticache_replication_group" "secondary" {
  replication_group_id        = "example-secondary"
  description                 = "secondary replication group"
  global_replication_group_id = aws_elasticache_global_replication_group.example.global_replication_group_id

  num_cache_clusters = 1
}

resource "aws_elasticache_global_replication_group" "example" {
  provider = aws.other_region

  global_replication_group_id_suffix = "example"
  primary_replication_group_id       = aws_elasticache_replication_group.primary.id
}

resource "aws_elasticache_replication_group" "primary" {
  provider = aws.other_region

  replication_group_id = "example-primary"
  description          = "primary replication group"

  engine         = "redis"
  engine_version = "5.0.6"
  node_type      = "cache.m5.large"

  num_cache_clusters = 1
}

Redis AUTH and In-Transit Encryption Enabled

resource "aws_elasticache_replication_group" "example" {
  replication_group_id = "example"
  description          = "example with authentication"
  node_type            = "cache.t2.micro"
  num_cache_clusters   = 1
  port                 = 6379
  subnet_group_name    = aws_elasticache_subnet_group.example.name
  security_group_ids   = [aws_security_group.example.id]
  parameter_group_name = "default.redis5.0"
  engine_version       = "5.0.6"

  transit_encryption_enabled = true
  auth_token                 = "abcdefgh1234567890"
  auth_token_update_strategy = "ROTATE"
}

Argument Reference

The following arguments are required:

The following arguments are optional:

Log Delivery Configuration

The log_delivery_configuration block allows the streaming of Redis SLOWLOG or Redis Engine Log to CloudWatch Logs or Kinesis Data Firehose. Max of 2 blocks.

Attribute Reference

This resource exports the following attributes in addition to the arguments above:

Timeouts

Configuration options:

Import

In Terraform v1.5.0 and later, use an import block to import ElastiCache Replication Groups using the replication_group_id. For example:

import {
  to = aws_elasticache_replication_group.my_replication_group
  id = "replication-group-1"
}

Using terraform import, import ElastiCache Replication Groups using the replication_group_id. For example:

% terraform import aws_elasticache_replication_group.my_replication_group replication-group-1