Skip to main content
Cache Modules 0.22.4Last updated in version 0.22.4

Memcached Module

View SourceRelease Notes

This module creates an ElastiCache cluster that runs Memcached.

How do you connect to the Memcached cluster?

This module outputs a Terraform output variable that contains a comma-separated list of addresses of the Memcached 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 Memcached 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

main.tf

# ------------------------------------------------------------------------------------------------------
# DEPLOY GRUNTWORK'S MEMCACHED MODULE
# ------------------------------------------------------------------------------------------------------

module "memcached" {

source = "git::git@github.com:gruntwork-io/terraform-aws-cache.git//modules/memcached?ref=v0.22.4"

# ----------------------------------------------------------------------------------------------------
# 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)>

# 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 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, can only be set on cluster creation.
enable_transport_encryption = false

# 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"

# Version number of memcached to use (e.g. 1.5.16).
memcached_version = "1.5.16"

# 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 = {}

# A set of tags to set for the ElastiCache Replication Group.
tags = {}

}


Reference

Required

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.

instance_typestringrequired

The compute and memory capacity of the nodes (e.g. cache.m3.medium).

namestringrequired

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.

num_cache_nodesnumberrequired

The initial number of cache nodes that the cache cluster will have. Must be between 1 and 20.

subnet_idslist(string)required

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_idstringrequired

The id of the VPC in which the ElastiCache cluster should be deployed.

Optional

Specifies a list of Security Groups to allow connections from.

[]
apply_immediatelybooloptional

Specifies whether any database modifications are applied immediately, or during the next maintenance window.

false
az_modestringoptional

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.

"single-az"

Enable Encryption in-transit, can only be set on cluster creation.

false
maintenance_windowstringoptional

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.

"sat:07:00-sat:08:00"
memcached_versionstringoptional

Version number of memcached to use (e.g. 1.5.16).

"1.5.16"
parameter_group_namestringoptional

Name of the parameter group to associate with this cache cluster. This can be used to configure custom settings for the cluster.

null
portnumberoptional

The port number on which each of the cache nodes will accept connections (e.g. 6379).

11211
security_group_tagsmap(string)optional

A set of tags to set for the Security Group created as part of this module.

{}
tagsmap(string)optional

A set of tags to set for the ElastiCache Replication Group.

{}