Skip to main content
Latest Documentation
This is the latest documentation for the Cloud Posse Reference Architecture. To determine which version you're currently using, please see Version Identification.

elasticache-redis

This component provisions AWS ElastiCache Redis clusters. The engine can either be redis or valkey. For more information, see why aws supports valkey.

Usage

Stack Level: Regional

Here's an example snippet for how to use this component.

stacks/catalog/elasticache/elasticache-redis/defaults.yaml file (default settings for all Redis clusters):

components:
terraform:
elasticache-redis:
vars:
enabled: true
name: "elasticache-redis"
family: redis7.x
egress_cidr_blocks: ["0.0.0.0/0"]
port: 6379
at_rest_encryption_enabled: true
transit_encryption_enabled: false
apply_immediately: false
automatic_failover_enabled: false
cloudwatch_metric_alarms_enabled: false
snapshot_retention_limit: 1
snapshot_window: "06:00-07:00"
maintenance_window: "tue:08:00-tue:09:00"
# Global defaults for all redis_clusters (can be overridden per cluster)
engine: "redis"
num_replicas: 1
num_shards: 0
replicas_per_shard: 0
create_parameter_group: true
parameters: []
redis_clusters:
redis-main:
engine_version: "7.0"
instance_type: cache.t4g.small
parameters:
- name: notify-keyspace-events
value: "lK"

stacks/org/ou/account/region.yaml file (imports defaults and overrides per-cluster settings):

import:
- catalog/elasticache/elasticache-redis/defaults.yaml

components:
terraform:
elasticache-redis:
vars:
enabled: true
redis_clusters:
redis-main:
engine_version: "7.0"
instance_type: cache.t4g.small
# Per-cluster overrides of the global defaults
num_replicas: 2 # override global default of 1
num_shards: 3 # override global default of 0 (enables cluster mode)
replicas_per_shard: 1 # override global default of 0
parameters:
- name: notify-keyspace-events
value: lK

Alternatively, if any per-cluster defaults are not covered by component-level variables, use YAML anchors to define shared values once and merge them into each cluster entry:

# stacks/catalog/elasticache/elasticache-redis/defaults.yaml
anchors:
default_redis: &default_redis
engine: "redis"
engine_version: "7.0"
instance_type: cache.t4g.small
num_replicas: 1
num_shards: 0
replicas_per_shard: 0

components:
terraform:
elasticache-redis:
vars:
enabled: true
name: "elasticache-redis"
family: redis7.x
port: 6379
at_rest_encryption_enabled: true
transit_encryption_enabled: false
apply_immediately: false
automatic_failover_enabled: false
cloudwatch_metric_alarms_enabled: false
snapshot_retention_limit: 1
redis_clusters:
redis-main:
<<: *default_redis # merge anchor defaults
num_replicas: 2 # override anchor value
redis-valkey:
<<: *default_redis
engine: "valkey" # override engine to valkey
num_shards: 3 # enable cluster mode
replicas_per_shard: 1
redis-cache:
<<: *default_redis # all anchor defaults apply

Variables

Required Variables

apply_immediately (bool) required

Apply changes immediately

at_rest_encryption_enabled (bool) required

Enable encryption at rest

automatic_failover_enabled (bool) required

Enable automatic failover

cloudwatch_metric_alarms_enabled (bool) required

Boolean flag to enable/disable CloudWatch metrics alarms

family (string) required

Redis family

port (number) required

Port number

redis_clusters (map(any)) required

Redis cluster configuration

region (string) required

AWS region

transit_encryption_enabled (bool) required

Enable TLS

Optional Variables

alarm_actions (list(string)) optional

Alarm action list


Default value: [ ]

alarm_cpu_threshold_percent (number) optional

CPU threshold alarm level


Default value: 75

alarm_memory_threshold_bytes (number) optional

Ram threshold alarm level


Default value: 10000000

allow_all_egress (bool) optional

If true, the created security group will allow egress on all ports and protocols to all IP address.
If this is false and no egress rules are otherwise specified, then no egress will be allowed.



Default value: true

allow_ingress_from_this_vpc (bool) optional

If set to true, allow ingress from the VPC CIDR for this account


Default value: true

allow_ingress_from_vpc_stages (list(string)) optional

List of stages to pull VPC ingress cidr and add to security group


Default value: [ ]

auth_token_enabled (bool) optional

Enable auth token


Default value: true

auth_token_update_strategy (string) optional

Strategy to use when updating the auth_token. Valid values are SET, ROTATE, and DELETE. Defaults to ROTATE.


Default value: "ROTATE"

auto_minor_version_upgrade (bool) optional

Specifies whether minor version engine upgrades will be applied automatically to the underlying Cache Cluster instances during the maintenance window. Only supported if the engine version is 6 or higher.


Default value: false

availability_zones (list(string)) optional

Availability zone IDs


Default value: [ ]

create_parameter_group (bool) optional

Default setting for whether a new parameter group should be created for all Redis clusters. Set to false to use an existing parameter group. Can be overridden per cluster in redis_clusters.


Default value: true

data_tiering_enabled (bool) optional

Enables data tiering. Data tiering is only supported for replication groups using the r6gd node type.


Default value: false

description (string) optional

Default description for all Redis replication groups. Can be overridden per cluster in redis_clusters.


Default value: null

dns_delegated_component_name (string) optional

The name of the Delegated DNS component


Default value: "dns-delegated"

eks_component_names (set(string)) optional

The names of the eks components


Default value: [ ]

eks_security_group_enabled (bool) optional

Use the eks default security group


Default value: false

elasticache_subnet_group_name (string) optional

Subnet group name for the ElastiCache instance


Default value: ""

engine (string) optional

Default cache engine for all Redis clusters. Valid values: redis or valkey. Can be overridden per cluster in redis_clusters.


Default value: "redis"

final_snapshot_identifier (string) optional

Default name of the final snapshot to create before deleting all Redis clusters. If null, no final snapshot is created. Can be overridden per cluster in redis_clusters.


Default value: null

global_replication_group_id (string) optional

The ID of the global replication group to which this replication group should belong. If this parameter is specified, the replication group is added to the specified global replication group as a secondary replication group; otherwise, the replication group is not part of any global replication group. If global_replication_group_id is set, the num_node_groups parameter cannot be set.


Default value: null

ingress_cidr_blocks (list(string)) optional

CIDR blocks for permitted ingress


Default value: [ ]

kms_key_id (string) optional

The ARN of the key that you wish to use if encrypting at rest. If not supplied, uses service managed encryption. at_rest_encryption_enabled must be set to true


Default value: null

log_delivery_configuration (list(map(any))) optional

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.


Default value: [ ]

maintenance_window (string) optional

Maintenance window. Format: ddd:hh:mm-ddd:hh:mm (UTC). Defaults to null (AWS chooses the window).


Default value: null

multi_az_enabled (bool) optional

Multi AZ (Automatic Failover must also be enabled. If Cluster Mode is enabled, Multi AZ is on by default, and this setting is ignored)


Default value: false

network_type (string) optional

The network type of the cluster. Valid values: ipv4, ipv6, dual_stack.


Default value: "ipv4"

notification_topic_arn (string) optional

Notification topic arn


Default value: ""

num_replicas (number) optional

Default number of replicas in the replica set for all Redis clusters. Can be overridden per cluster in redis_clusters.


Default value: 1

num_shards (number) optional

Default number of shards (node groups) for Redis clusters. Value > 0 enables cluster mode. Can be overridden per cluster in redis_clusters.


Default value: 0

ok_actions (list(string)) optional

The list of actions to execute when this alarm transitions into an OK state from any other state. Each action is specified as an Amazon Resource Number (ARN)


Default value: [ ]

parameter_group_description (string) optional

Managed by Terraform


Default value: null

parameter_group_name (string) optional

Default override parameter group name for all Redis clusters. Can be overridden per cluster in redis_clusters.


Default value: null

parameters optional

Default list of Redis parameters to configure for all clusters. Can be overridden per cluster in redis_clusters.


Type:

list(object({
name = string
value = string
}))

Default value: [ ]

replicas_per_shard (number) optional

Default number of replica nodes per shard for Redis clusters. Valid values are 0 to 5. Can be overridden per cluster in redis_clusters.


Default value: 0

replication_group_id (string) optional

Default replication group ID for all Redis clusters. Must be 1-20 alphanumeric characters or hyphens, start with a letter, and not end with or contain consecutive hyphens. Can be overridden per cluster in redis_clusters.


Default value: ""

serverless_cache_usage_limits (map(any)) optional

The usage limits for the serverless cache. Expected keys are data_storage (with maximum, minimum, unit) and ecpu_per_second (with maximum, minimum).


Default value: { }

serverless_enabled (bool) optional

Flag to enable/disable creation of a serverless redis cluster


Default value: false

serverless_major_engine_version (string) optional

The major version of the engine to use for the serverless cluster


Default value: "7"

serverless_snapshot_arns_to_restore (list(string)) optional

The list of ARN(s) of the snapshot that the new serverless cache will be created from. Available for Redis only.


Default value: [ ]

serverless_snapshot_time (string) optional

The daily time (in UTC, format HH:MM) that snapshots will be created from the serverless cache.


Default value: "06:00"

serverless_user_group_id (string) optional

User Group ID to associate with the serverless replication group


Default value: null

snapshot_arns (list(string)) optional

Default list of ARNs of Redis RDB snapshot files in S3 to restore into all new clusters. Can be overridden per cluster in redis_clusters.


Default value: [ ]

snapshot_name (string) optional

Default name of a snapshot to restore into all new Redis clusters. Changing this forces a new resource. Can be overridden per cluster in redis_clusters.


Default value: null

snapshot_retention_limit (number) optional

The number of days for which ElastiCache will retain automatic cache cluster snapshots before deleting them.


Default value: 0

snapshot_window (string) optional

The daily time range (in UTC) during which ElastiCache begins taking a daily snapshot. Format: hh:mm-hh:mm. Defaults to null (AWS chooses the window). Has no effect when snapshot_retention_limit is 0.


Default value: null

transit_encryption_mode (string) optional

Transit encryption mode. Valid values are 'preferred' and 'required'


Default value: null

user_group_ids (list(string)) optional

User Group ID to associate with the replication group


Default value: null

vpc_component_name (string) optional

The name of a VPC component


Default value: "vpc"

vpc_ingress_component_name (string) optional

The name of a Ingress VPC component


Default value: "vpc"

Context Variables

The following variables are defined in the context.tf file of this module and part of the terraform-null-label pattern.

additional_tag_map (map(string)) optional

Additional key-value pairs to add to each map in tags_as_list_of_maps. Not added to tags or id.
This is for some rare cases where resources want additional configuration of tags
and therefore take a list of maps with tag key, value, and additional configuration.


Required: No

Default value: { }

attributes (list(string)) optional

ID element. Additional attributes (e.g. workers or cluster) to add to id,
in the order they appear in the list. New attributes are appended to the
end of the list. The elements of the list are joined by the delimiter
and treated as a single ID element.


Required: No

Default value: [ ]

context (any) optional

Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as null to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional_tag_map, which are merged.


Required: No

Default value:

{
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"descriptor_formats": {},
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_key_case": null,
"label_order": [],
"label_value_case": null,
"labels_as_tags": [
"unset"
],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {},
"tenant": null
}
delimiter (string) optional

Delimiter to be used between ID elements.
Defaults to - (hyphen). Set to &#34;&#34; to use no delimiter at all.


Required: No

Default value: null

descriptor_formats (any) optional

Describe additional descriptors to be output in the descriptors output map.
Map of maps. Keys are names of descriptors. Values are maps of the form
\{<br/> format = string<br/> labels = list(string)<br/> \}
(Type is any so the map values can later be enhanced to provide additional options.)
format is a Terraform format string to be passed to the format() function.
labels is a list of labels, in order, to pass to format() function.
Label values will be normalized before being passed to format() so they will be
identical to how they appear in id.
Default is {} (descriptors output will be empty).


Required: No

Default value: { }

enabled (bool) optional

Set to false to prevent the module from creating any resources
Required: No

Default value: null

environment (string) optional

ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT'
Required: No

Default value: null

id_length_limit (number) optional

Limit id to this many characters (minimum 6).
Set to 0 for unlimited length.
Set to null for keep the existing setting, which defaults to 0.
Does not affect id_full.


Required: No

Default value: null

label_key_case (string) optional

Controls the letter case of the tags keys (label names) for tags generated by this module.
Does not affect keys of tags passed in via the tags input.
Possible values: lower, title, upper.
Default value: title.


Required: No

Default value: null

label_order (list(string)) optional

The order in which the labels (ID elements) appear in the id.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present.


Required: No

Default value: null

label_value_case (string) optional

Controls the letter case of ID elements (labels) as included in id,
set as tag values, and output by this module individually.
Does not affect values of tags passed in via the tags input.
Possible values: lower, title, upper and none (no transformation).
Set this to title and set delimiter to &#34;&#34; to yield Pascal Case IDs.
Default value: lower.


Required: No

Default value: null

labels_as_tags (set(string)) optional

Set of labels (ID elements) to include as tags in the tags output.
Default is to include all labels.
Tags with empty values will not be included in the tags output.
Set to [] to suppress all generated tags.
Notes:
The value of the name tag, if included, will be the id, not the name.
Unlike other null-label inputs, the initial setting of labels_as_tags cannot be
changed in later chained modules. Attempts to change it will be silently ignored.


Required: No

Default value:

[
"default"
]
name (string) optional

ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
This is the only ID element not also included as a tag.
The "name" tag is set to the full id string. There is no tag with the value of the name input.


Required: No

Default value: null

namespace (string) optional

ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique
Required: No

Default value: null

regex_replace_chars (string) optional

Terraform regular expression (regex) string.
Characters matching the regex will be removed from the ID elements.
If not set, &#34;/[^a-zA-Z0-9-]/&#34; is used to remove all characters other than hyphens, letters and digits.


Required: No

Default value: null

stage (string) optional

ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release'
Required: No

Default value: null

tags (map(string)) optional

Additional tags (e.g. {&#39;BusinessUnit&#39;: &#39;XYZ&#39;}).
Neither the tag keys nor the tag values will be modified by this module.


Required: No

Default value: { }

tenant (string) optional

ID element (Rarely used, not included by default). A customer identifier, indicating who this instance of a resource is for
Required: No

Default value: null

Outputs

redis_clusters

Redis cluster objects

security_group_id

The security group ID of the ElastiCache Redis cluster

transit_encryption_mode

TLS in-transit encryption mode for Redis cluster

Dependencies

Requirements

  • terraform, version: >= 1.0.0
  • aws, version: >= 5.73.0, < 6.0.0

Modules

NameVersionSourceDescription
dns_delegated1.8.0cloudposse/stack-config/yaml//modules/remote-staten/a
eks1.8.0cloudposse/stack-config/yaml//modules/remote-staten/a
iam_roleslatest../account-map/modules/iam-rolesn/a
redis_clusterslatest./modules/redis_clustern/a
this0.25.0cloudposse/label/nulln/a
vpc1.8.0cloudposse/stack-config/yaml//modules/remote-staten/a
vpc_ingress1.8.0cloudposse/stack-config/yaml//modules/remote-staten/a