Provides an ElastiCache Cluster resource, which manages either a Memcached cluster, a single-node Redis instance, or a [read replica in a Redis (Cluster Mode Enabled) replication group].
For working with Redis (Cluster Mode Enabled) replication groups, see the
aws_elasticache_replication_group
resource.
resource "aws_elasticache_cluster" "example" {
cluster_id = "cluster-example"
engine = "memcached"
node_type = "cache.m4.large"
num_cache_nodes = 2
parameter_group_name = "default.memcached1.4"
port = 11211
}
resource "aws_elasticache_cluster" "example" {
cluster_id = "cluster-example"
engine = "redis"
node_type = "cache.m4.large"
num_cache_nodes = 1
parameter_group_name = "default.redis3.2"
engine_version = "3.2.10"
port = 6379
}
These inherit their settings from the replication group.
resource "aws_elasticache_cluster" "replica" {
cluster_id = "cluster-example"
replication_group_id = aws_elasticache_replication_group.example.id
}
resource "aws_elasticache_cluster" "test" {
cluster_id = "mycluster"
engine = "redis"
node_type = "cache.t3.micro"
num_cache_nodes = 1
port = 6379
apply_immediately = true
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"
}
}
data "aws_outposts_outposts" "example" {}
data "aws_outposts_outpost" "example" {
id = tolist(data.aws_outposts_outposts.example.ids)[0]
}
resource "aws_vpc" "example" {
cidr_block = "10.0.0.0/16"
}
resource "aws_subnet" "example" {
vpc_id = aws_vpc.example.id
cidr_block = "10.0.1.0/24"
tags = {
Name = "my-subnet"
}
}
resource "aws_elasticache_subnet_group" "example" {
name = "my-cache-subnet"
subnet_ids = [aws_subnet.example.id]
}
resource "aws_elasticache_cluster" "example" {
cluster_id = "cluster-example"
# Note that ElastiCache for Outposts only supports `single-outpost` currently
outpost_mode = "single-outpost"
preferred_outpost_arn = data.aws_outposts_outpost.example.arn
engine = "memcached"
# Note that ElastiCache for Outposts only supports M5 and R5 node families currently
node_type = "cache.r5.large"
num_cache_nodes = 2
parameter_group_name = "default.memcached1.4"
port = 11211
subnet_group_name = aws_elasticache_subnet_group.example.name
}
The following arguments are required:
cluster_id
– (Required) Group identifier. ElastiCache converts this name to lowercase. Changing this value will re-create the resource.engine
– (Optional, Required if replication_group_id
is not specified) Name of the cache engine to be used for this cache cluster. Valid values are memcached
or redis
.node_type
– (Required unless replication_group_id
is provided) The instance class used. See AWS documentation for information on supported node types for Redis and guidance on selecting node types for Redis. See AWS documentation for information on supported node types for Memcached and guidance on selecting node types for Memcached. For Memcached, changing this value will re-create the resource.num_cache_nodes
– (Required unless replication_group_id
is provided) The initial number of cache nodes that the cache cluster will have. For Redis, this value must be 1. For Memcached, this value must be between 1 and 40. If this number is reduced on subsequent runs, the highest numbered nodes will be removed.parameter_group_name
– (Required unless replication_group_id
is provided) The name of the parameter group to associate with this cache cluster.The following arguments are optional:
apply_immediately
- (Optional) Whether any database modifications are applied immediately, or during the next maintenance window. Default is false
. See Amazon ElastiCache Documentation for more information..auto_minor_version_upgrade
- (Optional) Specifies whether minor version engine upgrades will be applied automatically to the underlying Cache Cluster instances during the maintenance window.
Only supported for engine type "redis"
and if the engine version is 6 or higher.
Defaults to true
.availability_zone
- (Optional) Availability Zone for the cache cluster. If you want to create cache nodes in multi-az, use preferred_availability_zones
instead. Default: System chosen Availability Zone. Changing this value will re-create the resource.az_mode
- (Optional, Memcached only) Whether the nodes in this Memcached node group are created in a single Availability Zone or created across multiple Availability Zones in the cluster's region. Valid values for this parameter are single-az
or cross-az
, default is single-az
. If you want to choose cross-az
, num_cache_nodes
must be greater than 1
.engine_version
– (Optional) Version number of the cache engine to be used.
If not set, defaults to the latest version.
See Describe Cache Engine Versions in the AWS Documentation for supported versions.
When engine
is redis
and the version is 7 or higher, the major and minor version should be set, e.g., 7.2
.
When the version is 6, the major and minor version can be set, e.g., 6.2
,
or the minor version can be unspecified which will use the latest version at creation time, e.g., 6.x
.
Otherwise, specify the full version desired, e.g., 5.0.6
.
The actual engine version used is returned in the attribute engine_version_actual
, see Attribute Reference below. Cannot be provided with replication_group_id.
final_snapshot_identifier
- (Optional, Redis only) Name of your final cluster snapshot. If omitted, no final snapshot will be made.ip_discovery
- (Optional) The IP version to advertise in the discovery protocol. Valid values are ipv4
or ipv6
.log_delivery_configuration
- (Optional, Redis only) Specifies the destination and format of Redis SLOWLOG or Redis Engine Log. See the documentation on Amazon ElastiCache. See Log Delivery Configuration below for more details.maintenance_window
– (Optional) Specifies the weekly time range for when maintenance
on the cache cluster is performed. The format is ddd:hh24:mi-ddd:hh24:mi
(24H Clock UTC).
The minimum maintenance window is a 60 minute period. Example: sun:05:00-sun:09:00
.network_type
- (Optional) The IP versions for cache cluster connections. IPv6 is supported with Redis engine 6.2
onword or Memcached version 1.6.6
for all Nitro system instances. Valid values are ipv4
, ipv6
or dual_stack
.notification_topic_arn
– (Optional) ARN of an SNS topic to send ElastiCache notifications to. Example: arn:aws:sns:us-east-1:012345678999:my_sns_topic
.outpost_mode
- (Optional) Specify the outpost mode that will apply to the cache cluster creation. Valid values are "single-outpost"
and "cross-outpost"
, however AWS currently only supports "single-outpost"
mode.port
– (Optional) The port number on which each of the cache nodes will accept connections. For Memcached the default is 11211, and for Redis the default port is 6379. Cannot be provided with replication_group_id
. Changing this value will re-create the resource.preferred_availability_zones
- (Optional, Memcached only) List of the Availability Zones in which cache nodes are created. If you are creating your cluster in an Amazon VPC you can only locate nodes in Availability Zones that are associated with the subnets in the selected subnet group. The number of Availability Zones listed must equal the value of num_cache_nodes
. If you want all the nodes in the same Availability Zone, use availability_zone
instead, or repeat the Availability Zone multiple times in the list. Default: System chosen Availability Zones. Detecting drift of existing node availability zone is not currently supported. Updating this argument by itself to migrate existing node availability zones is not currently supported and will show a perpetual difference.preferred_outpost_arn
- (Optional, Required if outpost_mode
is specified) The outpost ARN in which the cache cluster will be created.replication_group_id
- (Optional, Required if engine
is not specified) ID of the replication group to which this cluster should belong. If this parameter is specified, the cluster is added to the specified replication group as a read replica; otherwise, the cluster is a standalone primary that is not part of any replication group.security_group_ids
– (Optional, VPC only) One or more VPC security groups associated with the cache cluster. Cannot be provided with replication_group_id.
snapshot_arns
– (Optional, Redis only) Single-element string list containing an Amazon Resource Name (ARN) of a Redis RDB snapshot file stored in Amazon S3. The object name cannot contain any commas. Changing snapshot_arns
forces a new resource.snapshot_name
- (Optional, Redis only) Name of a snapshot from which to restore data into the new node group. Changing snapshot_name
forces a new resource.snapshot_retention_limit
- (Optional, Redis only) Number of days for which ElastiCache will retain automatic cache cluster snapshots before deleting them. For example, if you set SnapshotRetentionLimit to 5, then a snapshot that was taken today will be retained for 5 days before being deleted. If the value of SnapshotRetentionLimit is set to zero (0), backups are turned off. Please note that setting a snapshot_retention_limit
is not supported on cache.t1.micro cache nodessnapshot_window
- (Optional, Redis only) Daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your cache cluster. Example: 05:00-09:00subnet_group_name
– (Optional, VPC only) Name of the subnet group to be used for the cache cluster. Changing this value will re-create the resource. Cannot be provided with replication_group_id.
tags
- (Optional) Map of tags to assign to the resource. If configured with a provider default_tags
configuration block present, tags with matching keys will overwrite those defined at the provider-level.transit_encryption_enabled
- (Optional) Enable encryption in-transit. Supported only with Memcached versions 1.6.12
and later, running in a VPC. See the ElastiCache in-transit encryption documentation for more details.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.
destination
- Name of either the CloudWatch Logs LogGroup or Kinesis Data Firehose resource.destination_type
- For CloudWatch Logs use cloudwatch-logs
or for Kinesis Data Firehose use kinesis-firehose
.log_format
- Valid values are json
or text
log_type
- Valid values are slow-log
or engine-log
. Max 1 of each.This resource exports the following attributes in addition to the arguments above:
arn
- The ARN of the created ElastiCache Cluster.engine_version_actual
- Because ElastiCache pulls the latest minor or patch for a version, this attribute returns the running version of the cache engine.cache_nodes
- List of node objects including id
, address
, port
and availability_zone
.cluster_address
- (Memcached only) DNS name of the cache cluster without the port appended.configuration_endpoint
- (Memcached only) Configuration endpoint to allow host discovery.tags_all
- Map of tags assigned to the resource, including those inherited from the provider default_tags
configuration block.create
- (Default 40m
)update
- (Default 80m
)delete
- (Default 40m
)In Terraform v1.5.0 and later, use an import
block to import ElastiCache Clusters using the cluster_id
. For example:
import {
to = aws_elasticache_cluster.my_cluster
id = "my_cluster"
}
Using terraform import
, import ElastiCache Clusters using the cluster_id
. For example:
% terraform import aws_elasticache_cluster.my_cluster my_cluster