Skip to content

Resource: awsElasticacheGlobalReplicationGroup

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.

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const awsElasticacheReplicationGroupPrimary =
  new aws.elasticacheReplicationGroup.ElasticacheReplicationGroup(
    this,
    "primary",
    {
      engine: "redis",
      engineVersion: "5.0.6",
      nodeType: "cache.m5.large",
      numberCacheClusters: 1,
      replicationGroupDescription: "primary replication group",
      replicationGroupId: "example-primary",
    }
  );
const awsElasticacheGlobalReplicationGroupExample =
  new aws.elasticacheGlobalReplicationGroup.ElasticacheGlobalReplicationGroup(
    this,
    "example",
    {
      globalReplicationGroupIdSuffix: "example",
      primaryReplicationGroupId: awsElasticacheReplicationGroupPrimary.id,
    }
  );
new aws.elasticacheReplicationGroup.ElasticacheReplicationGroup(
  this,
  "secondary",
  {
    globalReplicationGroupId:
      awsElasticacheGlobalReplicationGroupExample.globalReplicationGroupId,
    numberCacheClusters: 1,
    provider: "${aws.other_region}",
    replicationGroupDescription: "secondary replication group",
    replicationGroupId: "example-secondary",
  }
);

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 lifecycleIgnoreChanges[engineVersion] 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.

/*Provider bindings are generated by running cdktf get.
See https://cdk.tf/provider-generation for more details.*/
import * as aws from "./.gen/providers/aws";
const awsElasticacheReplicationGroupPrimary =
  new aws.elasticacheReplicationGroup.ElasticacheReplicationGroup(
    this,
    "primary",
    {
      engine: "redis",
      engineVersion: "6.0",
      nodeType: "cache.m5.large",
      numberCacheClusters: 1,
      replicationGroupDescription: "primary replication group",
      replicationGroupId: "example-primary",
    }
  );
awsElasticacheReplicationGroupPrimary.addOverride("lifecycle", [
  {
    ignore_changes: ["${engine_version}"],
  },
]);
const awsElasticacheGlobalReplicationGroupExample =
  new aws.elasticacheGlobalReplicationGroup.ElasticacheGlobalReplicationGroup(
    this,
    "example",
    {
      engineVersion: "6.2",
      globalReplicationGroupIdSuffix: "example",
      primaryReplicationGroupId: awsElasticacheReplicationGroupPrimary.id,
    }
  );
const awsElasticacheReplicationGroupSecondary =
  new aws.elasticacheReplicationGroup.ElasticacheReplicationGroup(
    this,
    "secondary",
    {
      globalReplicationGroupId:
        awsElasticacheGlobalReplicationGroupExample.globalReplicationGroupId,
      numberCacheClusters: 1,
      provider: "${aws.other_region}",
      replicationGroupDescription: "secondary replication group",
      replicationGroupId: "example-secondary",
    }
  );
awsElasticacheReplicationGroupSecondary.addOverride("lifecycle", [
  {
    ignore_changes: ["${engine_version}"],
  },
]);

Argument Reference

The following arguments are supported:

  • automaticFailoverEnabled - (Optional) Specifies whether read-only replicas will be automatically promoted to read/write primary if the existing primary fails. When creating, by default the Global Replication Group inherits the automatic failover setting of the primary replication group.
  • cacheNodeType - (Optional) The instance class used. See AWS documentation for information on supported node types and guidance on selecting node types. When creating, by default the Global Replication Group inherits the node type of the primary replication group.
  • engineVersion - (Optional) Redis version to use for the Global Replication Group. When creating, by default the Global Replication Group inherits the version of the primary replication group. If a version is specified, the Global Replication Group and all member replication groups will be upgraded to this version. Cannot be downgraded without replacing the Global Replication Group and all member replication groups. If the version is 6 or higher, the major and minor version can be set, e.g., 62, or the minor version can be unspecified which will use the latest version at creation time, e.g., 6X. The actual engine version used is returned in the attribute engineVersionActual, see Attributes Reference below.
  • globalReplicationGroupIdSuffix – (Required) The suffix name of a Global Datastore. If globalReplicationGroupIdSuffix is changed, creates a new resource.
  • primaryReplicationGroupId – (Required) The ID of the primary cluster that accepts writes and will replicate updates to the secondary cluster. If primaryReplicationGroupId is changed, creates a new resource.
  • globalReplicationGroupDescription – (Optional) A user-created description for the global replication group.
  • numNodeGroups - (Optional) The number of node groups (shards) on the global replication group.
  • parameterGroupName - (Optional) An ElastiCache Parameter Group to use for the Global Replication Group. Required when upgrading a major engine version, but will be ignored if left configured after the upgrade is complete. Specifying without a major version upgrade will fail. Note that ElastiCache creates a copy of this parameter group for each member replication group.

Attributes Reference

In addition to all arguments above, the following attributes are exported:

  • id - The ID of the ElastiCache Global Replication Group.
  • arn - The ARN of the ElastiCache Global Replication Group.
  • engineVersionActual - The full version number of the cache engine running on the members of this global replication group.
  • atRestEncryptionEnabled - A flag that indicate whether the encryption at rest is enabled.
  • authTokenEnabled - A flag that indicate whether AuthToken (password) is enabled.
  • clusterEnabled - Indicates whether the Global Datastore is cluster enabled.
  • engine - The name of the cache engine to be used for the clusters in this global replication group.
  • globalReplicationGroupId - The full ID of the global replication group.
  • globalNodeGroups - Set of node groups (shards) on the global replication group. Has the values:
  • globalNodeGroupId - The ID of the global node group.
  • slots - The keyspace for this node group.
  • transitEncryptionEnabled - A flag that indicates whether the encryption in transit is enabled.

Timeouts

Configuration options:

  • create - (Default 60M)
  • update - (Default 60M)
  • delete - (Default 20M)

Import

ElastiCache Global Replication Groups can be imported using the globalReplicationGroupId, e.g.,

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