Skip to content

oozou/terraform-aws-elasticache

Repository files navigation

AWS Elasticache Cluster

ElastiCache is a fully managed in-memory data store and cache service. This component creates an elasticache cluster with encryption enabled. Read more

It creates:

  • Elasticache replication group: Redis with Elasticache Cluster Mode Enabled.
  • High Availability elasticache cluster with automatic failover and auto minor version upgrade
  • Automatic backup and maintenance
  • Encryption enabled at rest and transit by default

Architecture

Arch

Run-Book

Pre-requisites

IMPORTANT NOTE

  1. Required version of Terraform is mentioned in versions.tf.
  2. Go through variables.tf for understanding each terraform variable before running this component.

Resources needed before deploying this component

  1. VPC with Private Subnets

AWS Accounts

Needs the following accounts:

  1. Any AWS Account where Elasticache needs to be deployed

Getting Started

How to use this component in a blueprint

IMPORTANT: We periodically release versions for the components. Since, master branch may have on-going changes, best practice would be to use a released version in form of a tag (e.g. ?ref=x.y.z)

module "elasticache_cluster" {
  source         = "git::https://<YOUR_VCS_URL>/components/terraform-aws-elasticache.git?ref=v4.0.0"
  base_name         = "${var.base_name}--redis-"
  vpc_config        = {
    vpc_id = module.vpc.vpc_id
    private_subnets = [module.vpc.private_subnet_ids]
  }

  redis_cluster_config = {
    instance_type  = var.elasticache["instance_type"]
    node_count     = var.elasticache["node_count"]
    engine_version = "5.0.6"

  }

  auth_token     = var.elasticache["redis_auth_token"]
  multi_az_enabled = var.multi_az_enabled
}

Requirements

Name Version
terraform >= 1.0.0
aws >= 5.0.0, < 6.0.0

Providers

Name Version
aws >= 5.0.0, < 6.0.0
null n/a

Modules

Name Source Version
custom_elasticache_alarms oozou/cloudwatch-alarm/aws 2.0.1

Resources

Name Type
aws_cloudwatch_metric_alarm.redis_cpu_alarm resource
aws_cloudwatch_metric_alarm.redis_memory_alarm resource
aws_elasticache_replication_group.elasticache resource
aws_elasticache_serverless_cache.elasticache resource
aws_elasticache_subnet_group.elasticache resource
aws_security_group.client resource
aws_security_group.elasticache resource
aws_security_group_rule.additional_cluster_ingress resource
aws_security_group_rule.egress resource
aws_security_group_rule.ingress resource
null_resource.validate_config resource
aws_subnet.subnets data source

Inputs

Name Description Type Default Required
additional_cluster_security_group_ingress_rules Additional ingress rule for cluster security group.
list(object({
from_port = number
to_port = number
protocol = string
cidr_blocks = list(string)
source_security_group_id = string
description = string
}))
[] no
auth_token Auth token for the Elasticache redis/valkey auth. Reference: https://docs.aws.amazon.com/AmazonElastiCache/latest/red-ug/auth.html string null no
cache_type Type of cache to create. Valid values: redis, valkey, redis-serverless, valkey-serverless string "redis" no
custom_elasticache_alarms_configure custom_elasticache_alarms_configure = {
cpu_utilization_too_high = {
metric_name = "EngineCPUUtilization"
statistic = "Average"
comparison_operator = ">="
threshold = "85"
period = "300"
evaluation_periods = "1"
alarm_actions = [sns_topic_arn]
ok_actions = [sns_topic_arn]
}
}
any {} no
default_alarm_actions The list of actions to execute when this alarm transitions into an ALARM state from any other state. Each action is specified as an Amazon Resource Name (ARN). list(string) [] no
default_ok_actions 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 Name (ARN). list(string) [] no
environment Environment Variable used as a prefix string n/a yes
is_enable_default_alarms if enable the default alarms bool false no
maintenance_window Snapshot Retention Limit string "mon:00:00-mon:03:00" no
multi_az_enabled Specifies whether to enable Multi-AZ Support for the replication group (traditional clusters only) bool false no
name Name of the ElastiCache cluster to create string n/a yes
prefix The prefix name of customer to be displayed in AWS console and resource string n/a yes
redis_cluster_config Configuration for traditional redis/valkey cluster (not used for serverless)
object({
port = number
instance_type = string
engine_version = string
node_count = number
})
null no
serverless_config Configuration for serverless cache
object({
engine_version = string
major_engine_version = optional(string)
cache_usage_limits = optional(object({
data_storage = optional(object({
maximum = number
unit = string
}))
ecpu_per_second = optional(object({
maximum = number
}))
}))
daily_snapshot_time = optional(string)
description = optional(string)
kms_key_id = optional(string)
snapshot_arns_to_restore = optional(list(string))
snapshot_retention_limit = optional(number)
user_group_id = optional(string)
})
null no
serverless_security_group_ids List of security group IDs for serverless cache (required for serverless caches) list(string) [] no
snapshot_config (optional) Snapshot config to retain and create backup
object({
snapshot_window = string
snapshot_retention_limit = number
})
{
"snapshot_retention_limit": 3,
"snapshot_window": "03:00-05:00"
}
no
tags Custom tags which can be passed on to the AWS resources. They should be key value pairs having distinct keys. map(string) {} no
vpc_config VPC ID and private subnets for ElastiCache cluster
object({
vpc_id = string
private_subnets = list(string)
})
n/a yes

Outputs

Name Description
cache_engine Cache engine (redis or valkey).
cache_host Hostname of the cache endpoint (traditional cluster primary endpoint or serverless endpoint).
cache_port Port of the cache endpoint.
cache_type Type of cache created (redis, valkey, redis-serverless, valkey-serverless).
client_security_group_id Security group id for the elasticache clients.
is_serverless Whether the cache is serverless.
redis_host Hostname of the redis/valkey host in the replication group (traditional clusters only).
replication_group_id ID of the ElastiCache replication group (traditional clusters only).
security_group_id Security group id for the elasticache.
serverless_cache_arn ARN of the serverless cache (serverless caches only).
serverless_cache_name Name of the serverless cache (serverless caches only).

About

Terraform Module to define an elasticcache

Topics

Resources

License

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors 6