Resource: aws_elasticache_global_replication_group

Provides an ElastiCache Global Replication Group resource, which manages replication between two or more Replication Groups in different regions. For more information, see the ElastiCache User Guide.

Example Usage

Global replication group with one secondary replication group

The global replication group depends on the primary group existing. Secondary replication groups depend on the global replication group. Terraform dependency management will handle this transparently using resource value references.

resource "aws_elasticache_global_replication_group" "example" {
  global_replication_group_id_suffix = "example"
  primary_replication_group_id       = aws_elasticache_replication_group.primary.id
}

resource "aws_elasticache_replication_group" "primary" {
  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
}

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

  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
}

Managing Redis Engine Versions

The initial Redis version is determined by the version set on the primary replication group. However, once it is part of a Global Replication Group, the Global Replication Group manages the version of all member replication groups.

The member replication groups must have lifecycle.ignore_changes[engine_version] set, or Terraform will always return a diff.

In this example, the primary replication group will be created with Redis 6.0, and then upgraded to Redis 6.2 once added to the Global Replication Group. The secondary replication group will be created with Redis 6.2.

resource "aws_elasticache_global_replication_group" "example" {
  global_replication_group_id_suffix = "example"
  primary_replication_group_id       = aws_elasticache_replication_group.primary.id

  engine_version = "6.2"
}

resource "aws_elasticache_replication_group" "primary" {
  replication_group_id = "example-primary"
  description          = "primary replication group"

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

  num_cache_clusters = 1

  lifecycle {
    ignore_changes = [engine_version]
  }
}

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

  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

  lifecycle {
    ignore_changes = [engine_version]
  }
}

Argument Reference

This resource supports the following arguments:

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 Global Replication Groups using the global_replication_group_id. For example:

import {
  to = aws_elasticache_global_replication_group.my_global_replication_group
  id = "okuqm-global-replication-group-1"
}

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

% terraform import aws_elasticache_global_replication_group.my_global_replication_group okuqm-global-replication-group-1