Terraform module which creates Elasticache clusters within existing VPC on AWS.
A choice of two types of elasticache backends are supported:
The following objects are created by the module:
- aws_elasticache_parameter_group
- aws_elasticache_cluster
- aws_elasticache_replication_group
- aws_security_group
- aws_security_group_rule
- aws_route53_record
Terraform 0.12. Pin module version to ~> v2.0
. Submit pull-requests to master
branch.
Terraform 0.11. Pin module version to ~> v1.0
. Submit pull-requests to terraform011
branch.
To create a Memcached cluster:
module "memcached-nonprod" {
source = "github.com/InnovateUKGitHub/terraform-module-elasticache"
enable_elasticache = var.enable_elasticache_nonprod
deploy_env = var.deploy_env
vpc_id = data.terraform_remote_state.vpc.vpc_id
local_dns_domain_zone_id = aws_route53_zone.local_private.zone_id
elasticache_clients_sgs = [aws_security_group.openshift-compute-node.id, aws_security_group.bastion.id]
subnet_group_name = data.terraform_remote_state.vpc.elasticache_subnet_group_name
purpose = "nonprod"
elasticache_multi_az = true
notification_topic_arn = aws_sns_topic.ElastiCache-Events.arn
elasticache_instance_type = var.elasticache_nonprod_instance_size
elasticache_family = "memcached1.4"
num_elasticache_instances = 2
}
output "elasticache_memcached_nonprod_cluster_address" {
value = module.memcached-nonprod.cluster_address
}
output "elasticache_memcached_nonprod_cluster_alias" {
value = module.memcached-nonprod.cluster_alias
}
To create a Redis cluster:
module "redis-nonprod" {
source = "github.com/InnovateUKGitHub/terraform-module-elasticache"
enable_elasticache = var.enable_elasticache_nonprod
deploy_env = var.deploy_env
vpc_id = data.terraform_remote_state.vpc.vpc_id
local_dns_domain_zone_id = aws_route53_zone.local_private.zone_id
elasticache_clients_sgs = [aws_security_group.openshift-compute-node.id, aws_security_group.bastion.id]
elasticache_family = "redis5.0"
elasticache_engine = "redis"
elasticache_engine_version = "5.0.5"
subnet_group_name = data.terraform_remote_state.vpc.elasticache_subnet_group_name
purpose = "nonprod-redis"
elasticache_multi_az = false
notification_topic_arn = aws_sns_topic.ElastiCache-Events.arn
elasticache_instance_type = var.elasticache_prod_instance_size
num_elasticache_instances = 2
elasticache_password = "Password for the service goes here?"
}
output "elasticache_redis_nonprod_cluster_address" {
value = module.redis-nonprod.cluster_address
}
output "elasticache_redis_nonprod_cluster_alias" {
value = module.redis-nonprod.cluster_alias
}
Sometimes you need to have a way to create module resources conditionally but Terraform does not allow to use count
inside module
block, so the solution is to specify argument enable_elasticache
.
# This Elasticache will not be created
module "vpc" {
source = "InnovateUKGitHub/terraform-module-elasticache"
enable_elasticache = false
# ... omitted
}
Name | Description | Type | Default | Required |
---|---|---|---|---|
deploy_env | Deployment Environment. Forms part of the unique namespace given to resources | string | yes | |
vpc_id | ID of the VPC to host the elasticache | string | yes | |
subnet_group_name | Subnet group for elasticache | string | yes | |
notification_topic_arn | An Amazon Resource Name (ARN) of an SNS topic to send ElastiCache notifications to | string | yes | |
purpose | Name to add for uniqueness, eg, prod or nonprod | string | "nonprod" |
no |
enable_elasticache | Boolean flag to enable or disable elasticache deploy | boolean | true |
no |
elasticache_clients_sgs | Array of SG ids from which to allow access to Elasticache | list | [] |
no |
elasticache_family | Elasticache family, eg, redis or memcache | string | "memcached1.4" |
no |
elasticache_engine | Which engine to use for elasticache (redis/memcached) | string | "memcached" |
no |
elasticache_port | Which port to use for elasticache (redis/memcached) | string | "11211" |
no |
elasticache_engine_version | Engine version for elasticache | string | "1.4.34" |
no |
elasticache_instance_type | Instance type for elasticache | string | "cache.t2.small" |
no |
elasticache_multi_az | Enable multi AZ | boolean | false |
no |
elasticache_password | Password for elasticache | string | "" |
no |
num_elasticache_instances | Number of elasticache instances | string | "2" |
no |
redis_replicas_per_node_group | Redis setting for number of replicas per node group | string | "1" |
no |
dns_record_ttl | Time To Live for DNS Alias record | string | "60" |
no |
local_dns_domain_zone_id | ZoneID for Route53 localzone to create record for ealasticache | string | no |
Name | Description |
---|---|
cluster_address | Cluster/Config fqdn address of elasticache |
cluster_alias | Alias to Cluster/Config fqdn address of elasticache created in supplied DNS zone |
Module is maintained by Innovate UK.
MIT Licensed. See LICENSE for full details.