Skip to content

avidhara/terraform-aws-elasticache

Repository files navigation

Terraform module for for AWS ElastiCache

Usage

module "redis" {
  source = "../../"
  name = "example"
  replication_group_description = "Example Redis Replication Group"
  availability_zones               = ["us-west-1b", "us-west-1c"]
  vpc_id                           = "vpc-xxxx"
  allowed_security_groups          = []
  subnet_ids                          = ["subnet-xxx", "subnet-xxxx"]
  cluster_size                     = 1
  node_type                    = "cache.t3.micro"
  apply_immediately                = true
  automatic_failover_enabled       = false
  family = "redis6.x"
  at_rest_encryption_enabled       = false
  transit_encryption_enabled       = true
  parameter_group_name = "default.redis7"
  allowed_cidr_blocks = ["10.10.0.0/16"]
}

Requirements

Name Version
terraform >= 1.3.2
aws >= 5.40

Providers

Name Version
aws >= 5.40

Modules

No modules.

Resources

Name Type
aws_elasticache_parameter_group.this resource
aws_elasticache_replication_group.this resource
aws_elasticache_subnet_group.this resource
aws_security_group.this resource
aws_security_group_rule.egress resource
aws_security_group_rule.ingress_cidr_blocks resource
aws_security_group_rule.ingress_security_groups resource

Inputs

Name Description Type Default Required
allowed_cidr_blocks List of CIDR blocks that are allowed ingress to the cluster's Security Group created in the module list(string) [] no
allowed_security_groups List of Security Group IDs that are allowed ingress to the cluster's Security Group created in the module list(string) [] no
apply_immediately (Optional) Specifies whether any modifications are applied immediately, or during the next maintenance window. Default is false. bool false no
at_rest_encryption_enabled (Optional) Whether to enable encryption at rest. bool false no
auth_token (Optional) The password used to access a password protected server. Can be specified only if transit_encryption_enabled = true string null no
auth_token_update_strategy (Optional) Strategy to use when updating the auth_token. Valid values are SET, ROTATE, and DELETE. Defaults to ROTATE. string "ROTATE" no
auto_minor_version_upgrade (Optional) Specifies whether a minor engine upgrades will be applied automatically to the underlying Cache Cluster instances during the maintenance window. Defaults to true bool true no
automatic_failover_enabled (Optional) Specifies whether a read-only replica will be automatically promoted to read/write primary if the existing primary fails. If true, Multi-AZ is enabled for this replication group. If false, Multi-AZ is disabled for this replication group. Must be enabled for Redis (cluster mode enabled) replication groups. Defaults to false bool false no
availability_zones (Optional) A list of EC2 availability zones in which the replication group's cache clusters will be created. The order of the availability zones in the list is not important. list(string) [] no
cluster_mode_enabled (Optional) Flag to enable/disable creation of a native redis cluster. automatic_failover_enabled must be set to true. Only 1 cluster_mode block is allowed bool false no
cluster_size Number of nodes in cluster. Ignored when cluster_mode_enabled == true number 1 no
create (Optional) Do you want to create elastic cache service default is true bool true no
create_parameter_group (Optional) Do you want to create a parameter group for the ElastiCache cluster. Defaults to true. bool false no
create_vpc_endpoint (optional) Do you want to create VPC endpoint for ElastiCache default is false bool false no
data_tiering_enabled (Optional) Enables data tiering. Data tiering is only supported for replication groups using the r6gd node type. This parameter must be set to true when using r6gd nodes. bool false no
engine (Optional) The name of the cache engine to be used for the clusters in this replication group. e.g. redis string "redis" no
engine_version (Optional) The version number of the cache engine to be used for the cache clusters in this replication group. string null no
existing_security_groups List of existing Security Group IDs to place the cluster into. Set use_existing_security_groups to true to enable using existing_security_groups as Security Groups for the cluster list(string) [] no
family The family of the ElastiCache parameter group. string n/a yes
final_snapshot_identifier (Optional) The name of your final node group (shard) snapshot. ElastiCache creates the snapshot from the primary node in the cluster. If omitted, no final snapshot will be made. string null no
global_replication_group_id (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. string null no
ip_discovery (Optional) The IP version to advertise in the discovery protocol. Valid values are ipv4 or ipv6. string "ipv4" no
kms_key_id Optional) The ARN of the key that you wish to use if encrypting at rest. If not supplied, uses service managed encryption. Can be specified only if at_rest_encryption_enabled = true string null no
log_delivery_configuration A list of log delivery configurations for the replication group.
- destination: The name of the S3 bucket to which the log data is written.
- destination_type: The type of destination (currently only S3 is supported).
- log_format: The log format to use. Valid values are json or text.
- log_type: The type of log to deliver. Valid values are slowlog or error.
list(object({
destination = string
destination_type = string
log_format = string
log_type = string
}))
[] no
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 string "wed:03:00-wed:04:00" no
multi_az_enabled (Optional) Specifies whether to enable Multi-AZ Support for the replication group. If true, automatic_failover_enabled must also be enabled. Defaults to false. bool false no
name Name of the cluster string n/a yes
network_type (Optional) The IP versions for cache cluster connections. Valid values are ipv4, ipv6 or dual_stack. string "ipv4" no
node_type (Optional) Instance class to be used. See AWS documentation for information on supported node types and guidance on selecting node types. Required unless global_replication_group_id is set. Cannot be set if global_replication_group_id is set. string null no
notification_topic_arn (Optional) An Amazon Resource Name (ARN) of an SNS topic to send ElastiCache notifications to. Example: arn:aws:sns:us-east-1:012345678999:my_sns_topic string null no
num_cache_clusters (Optional) Number of cache clusters (primary and replicas) this replication group will have. If Multi-AZ is enabled, the value of this parameter must be at least 2. Updates will occur before other modifications. Conflicts with num_node_groups. Defaults to 1. number 1 no
num_node_groups (Optional) Number of node groups (shards) for this Redis replication group. Changing this number will trigger a resizing operation before other settings modifications. number null no
number_cache_clusters (Required for Cluster Mode Disabled) The number of cache clusters (primary and replicas) this replication group will have. If Multi-AZ is enabled, the value of this parameter must be at least 2. Updates will occur before other modifications. number 0 no
parameter_group_description (Optional) The description of the ElastiCache parameter group. Defaults to 'Managed by Terraform'. string "Managed by Terraform" no
parameter_group_name (Optional) The name of the parameter group to associate with this replication group. If this argument is omitted, the default cache parameter group for the specified engine is used. string "" no
parameter_group_parameters A list of parameter names and values that will be used in the parameter group.
- name: The name of the parameter.
- value: The value of the parameter.
list(object({
name = string
value = string
}))
[] no
port (Optional) The port number on which each of the cache nodes will accept connections. For Memcache the default is 11211, and for Redis the default port is 6379. number 6379 no
replicas_per_node_group (Optional) Number of replica nodes in each node group. Changing this number will trigger a resizing operation before other settings modifications. Valid values are 0 to 5. number null no
replication_group_description Required) User-created description for the replication group. Must not be empty. string n/a yes
security_group_ids (Optional) One or more Amazon VPC security groups associated with this replication group. Use this parameter only when you are creating a replication group in an Amazon Virtual Private Cloud list(string) [] no
snapshot_arns (Optional) A single-element string list containing an Amazon Resource Name (ARN) of a Redis RDB snapshot file stored in Amazon S3. Example: arn:aws:s3:::my_bucket/snapshot1.rdb list(string) null no
snapshot_name (Optional) The name of a snapshot from which to restore data into the new node group. Changing the snapshot_name forces a new resource. string null no
snapshot_retention_limit The number of days for which ElastiCache will retain automatic cache cluster snapshots before deleting them. number 0 no
snapshot_window The daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your cache cluster. string "06:30-07:30" no
subnet_group_description (Optional) Description for the cache subnet group. Defaults to 'Managed by Terraform'. string "Managed by Terraform" no
subnet_group_name (Optional) The name of the cache subnet group to be used for the replication group. string "" no
subnet_ids (Required) List of VPC Subnet IDs for the cache subnet group list(string) n/a yes
tags A map of tags to assign to the resource. map(string) {} no
transit_encryption_enabled (Optional) Whether to enable encryption in transit bool false no
use_existing_security_groups description bool false no
user_group_ids (Optional) User Group ID to associate with the replication group. Only a maximum of one (1) user group ID is valid. NOTE: This argument is a set because the AWS specification allows for multiple IDs. However, in practice, AWS only allows a maximum size of one. list(string) null no
vpc_id (Optional, Forces new resource) The VPC ID. string null no

Outputs

Name Description
cluster_enabled Indicates if cluster mode is enabled.
configuration_endpoint_address The address of the replication group configuration endpoint when cluster mode is enabled.
engine_version_actual Because ElastiCache pulls the latest minor or patch for a version, this attribute returns the running version of the cache engine.
id The ID of the ElastiCache Replication Group
parameter_group_id The ElastiCache parameter group name.
primary_endpoint_address (Redis only) The address of the endpoint for the primary node in the replication group, if the cluster mode is disabled.
security_group_id Security group ID for the ElastiCache Replication Group
subnet_group_id Subnet group ID for the ElastiCache Replication Group