ElasticCache Module
This module creates an ElastiCache cluster, which manages either a Memcached cluster, a single-node Redis instance.
How do you connect to the ElasticCache cluster?
This module outputs a Terraform output variable that
contains a comma-separated list of addresses of the ElasticCache nodes. You can programmatically extract this variable in
your Terraform templates and pass it to other resources (e.g. as an environment variable in an EC2 instance). You'll
also see the variable at the end of each terraform apply
call or if you run terraform output
.
How do you scale this ElasticCache cluster?
- To scale vertically, increase the size of the nodes using the
instance_type
parameter (see here for valid values). - To scale horizontally, increase the number of nodes using the
num_cache_nodes
parameter.
For more info, see Scaling Memcached.
Sample Usage
- Terraform
- Terragrunt
# ------------------------------------------------------------------------------------------------------
# DEPLOY GRUNTWORK'S ELASTIC-CACHE MODULE
# ------------------------------------------------------------------------------------------------------
module "elastic_cache" {
source = "git::git@github.com:gruntwork-io/terraform-aws-cache.git//modules/elastic-cache?ref=v0.23.0"
# ----------------------------------------------------------------------------------------------------
# REQUIRED VARIABLES
# ----------------------------------------------------------------------------------------------------
# A list of CIDR-formatted IP address ranges that can connect to this
# ElastiCache cluster. For the standard Gruntwork VPC setup, these should be
# the CIDR blocks of the private app subnet in this VPC plus the private
# subnet in the mgmt VPC.
allow_connections_from_cidr_blocks = <list(string)>
# Name of the cache engine to be used for this cache cluster. Valid values are
# memcached, redis, or valkey.
engine = <string>
# Version number of ElasticCache cluster to use.
engine_version = <string>
# The compute and memory capacity of the nodes (e.g. cache.m3.medium).
instance_type = <string>
# The name used to namespace all resources created by these templates,
# including the ElastiCache cluster itself (e.g. mycache). Must be unique in
# this region. Must be a lowercase string.
name = <string>
# The initial number of cache nodes that the cache cluster will have. Must be
# between 1 and 20.
num_cache_nodes = <number>
# A list of subnet ids where the ElastiCache instances should be deployed. For
# the standard Gruntwork VPC setup, these should be the private peristence
# subnet ids.
subnet_ids = <list(string)>
# The id of the VPC in which the ElastiCache cluster should be deployed.
vpc_id = <string>
# ----------------------------------------------------------------------------------------------------
# OPTIONAL VARIABLES
# ----------------------------------------------------------------------------------------------------
# Specifies a list of Security Groups to allow connections from.
allow_connections_from_security_groups = []
# Specifies whether any database modifications are applied immediately, or
# during the next maintenance window.
apply_immediately = false
# 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
auto_minor_version_upgrade = true
# Specifies 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. If you want to choose cross-az, num_cache_nodes must be greater
# than 1.
az_mode = "single-az"
# Enable encryption in-transit. Supported only with Memcached versions 1.6.12
# and later, running in a VPC. Also only settable on cluster creation.
enable_transport_encryption = false
# Specifies the destination and format of Redis Engine Log. See the
# documentation on Amazon ElastiCache. See Log Delivery Configuration below
# for more details. You can find more information here
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_replication_group#log-delivery-configuration.
engine_log_delivery_configuration = null
# Specifies the weekly time range for when maintenance on the cache cluster is
# performed (e.g. sun:05:00-sun:09:00). The format is ddd:hh24:mi-ddd:hh24:mi
# (24H Clock UTC). The minimum maintenance window is a 60 minute period.
maintenance_window = "sat:07:00-sat:08:00"
# Name of the parameter group to associate with this cache cluster. This can
# be used to configure custom settings for the cluster.
parameter_group_name = null
# The port number on which each of the cache nodes will accept connections
# (e.g. 6379).
port = 11211
# A set of tags to set for the Security Group created as part of this module.
security_group_tags = {}
# Specifies the destination and format of Redis SLOWLOG. See the documentation
# on Amazon ElastiCache. See Log Delivery Configuration below for more
# details. You can find more information here
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_replication_group#log-delivery-configuration.
slow_log_delivery_configuration = null
# A set of tags to set for the ElastiCache Cluster.
tags = {}
}
# ------------------------------------------------------------------------------------------------------
# DEPLOY GRUNTWORK'S ELASTIC-CACHE MODULE
# ------------------------------------------------------------------------------------------------------
terraform {
source = "git::git@github.com:gruntwork-io/terraform-aws-cache.git//modules/elastic-cache?ref=v0.23.0"
}
inputs = {
# ----------------------------------------------------------------------------------------------------
# REQUIRED VARIABLES
# ----------------------------------------------------------------------------------------------------
# A list of CIDR-formatted IP address ranges that can connect to this
# ElastiCache cluster. For the standard Gruntwork VPC setup, these should be
# the CIDR blocks of the private app subnet in this VPC plus the private
# subnet in the mgmt VPC.
allow_connections_from_cidr_blocks = <list(string)>
# Name of the cache engine to be used for this cache cluster. Valid values are
# memcached, redis, or valkey.
engine = <string>
# Version number of ElasticCache cluster to use.
engine_version = <string>
# The compute and memory capacity of the nodes (e.g. cache.m3.medium).
instance_type = <string>
# The name used to namespace all resources created by these templates,
# including the ElastiCache cluster itself (e.g. mycache). Must be unique in
# this region. Must be a lowercase string.
name = <string>
# The initial number of cache nodes that the cache cluster will have. Must be
# between 1 and 20.
num_cache_nodes = <number>
# A list of subnet ids where the ElastiCache instances should be deployed. For
# the standard Gruntwork VPC setup, these should be the private peristence
# subnet ids.
subnet_ids = <list(string)>
# The id of the VPC in which the ElastiCache cluster should be deployed.
vpc_id = <string>
# ----------------------------------------------------------------------------------------------------
# OPTIONAL VARIABLES
# ----------------------------------------------------------------------------------------------------
# Specifies a list of Security Groups to allow connections from.
allow_connections_from_security_groups = []
# Specifies whether any database modifications are applied immediately, or
# during the next maintenance window.
apply_immediately = false
# 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
auto_minor_version_upgrade = true
# Specifies 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. If you want to choose cross-az, num_cache_nodes must be greater
# than 1.
az_mode = "single-az"
# Enable encryption in-transit. Supported only with Memcached versions 1.6.12
# and later, running in a VPC. Also only settable on cluster creation.
enable_transport_encryption = false
# Specifies the destination and format of Redis Engine Log. See the
# documentation on Amazon ElastiCache. See Log Delivery Configuration below
# for more details. You can find more information here
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_replication_group#log-delivery-configuration.
engine_log_delivery_configuration = null
# Specifies the weekly time range for when maintenance on the cache cluster is
# performed (e.g. sun:05:00-sun:09:00). The format is ddd:hh24:mi-ddd:hh24:mi
# (24H Clock UTC). The minimum maintenance window is a 60 minute period.
maintenance_window = "sat:07:00-sat:08:00"
# Name of the parameter group to associate with this cache cluster. This can
# be used to configure custom settings for the cluster.
parameter_group_name = null
# The port number on which each of the cache nodes will accept connections
# (e.g. 6379).
port = 11211
# A set of tags to set for the Security Group created as part of this module.
security_group_tags = {}
# Specifies the destination and format of Redis SLOWLOG. See the documentation
# on Amazon ElastiCache. See Log Delivery Configuration below for more
# details. You can find more information here
# https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_replication_group#log-delivery-configuration.
slow_log_delivery_configuration = null
# A set of tags to set for the ElastiCache Cluster.
tags = {}
}
Reference
- Inputs
- Outputs
Required
allow_connections_from_cidr_blocks
list(string)A list of CIDR-formatted IP address ranges that can connect to this ElastiCache cluster. For the standard Gruntwork VPC setup, these should be the CIDR blocks of the private app subnet in this VPC plus the private subnet in the mgmt VPC.
engine
stringName of the cache engine to be used for this cache cluster. Valid values are memcached, redis, or valkey.
engine_version
stringVersion number of ElasticCache cluster to use.
instance_type
stringThe compute and memory capacity of the nodes (e.g. cache.m3.medium).
name
stringThe name used to namespace all resources created by these templates, including the ElastiCache cluster itself (e.g. mycache). Must be unique in this region. Must be a lowercase string.
num_cache_nodes
numberThe initial number of cache nodes that the cache cluster will have. Must be between 1 and 20.
subnet_ids
list(string)A list of subnet ids where the ElastiCache instances should be deployed. For the standard Gruntwork VPC setup, these should be the private peristence subnet ids.
vpc_id
stringThe id of the VPC in which the ElastiCache cluster should be deployed.
Optional
allow_connections_from_security_groups
list(string)Specifies a list of Security Groups to allow connections from.
[]
Specifies whether any database modifications are applied immediately, or during the next maintenance window.
false
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
true
az_mode
stringSpecifies 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. If you want to choose cross-az, num_cache_nodes must be greater than 1.
"single-az"
Enable encryption in-transit. Supported only with Memcached versions 1.6.12 and later, running in a VPC. Also only settable on cluster creation.
false
engine_log_delivery_configuration
object(…)Specifies the destination and format of Redis Engine Log. See the documentation on Amazon ElastiCache. See Log Delivery Configuration below for more details. You can find more information here https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_replication_group#log-delivery-configuration.
object({
destination = string
destination_type = string
log_format = string
})
null
maintenance_window
stringSpecifies the weekly time range for when maintenance on the cache cluster is performed (e.g. sun:05:00-sun:09:00). The format is ddd:hh24:mi-ddd:hh24:mi (24H Clock UTC). The minimum maintenance window is a 60 minute period.
"sat:07:00-sat:08:00"
parameter_group_name
stringName of the parameter group to associate with this cache cluster. This can be used to configure custom settings for the cluster.
null
port
numberThe port number on which each of the cache nodes will accept connections (e.g. 6379).
11211
security_group_tags
map(string)A set of tags to set for the Security Group created as part of this module.
{}
slow_log_delivery_configuration
object(…)Specifies the destination and format of Redis SLOWLOG. See the documentation on Amazon ElastiCache. See Log Delivery Configuration below for more details. You can find more information here https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_replication_group#log-delivery-configuration.
object({
destination = string
destination_type = string
log_format = string
})
null
tags
map(string)A set of tags to set for the ElastiCache Cluster.
{}