├── .gitignore ├── outputs.tf ├── LICENSE ├── variables.tf ├── examples └── open │ └── readme.md ├── main.tf └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | .terraform 2 | terraform.tfstate 3 | terraform.tfstate.backup 4 | examples/open/main.tf -------------------------------------------------------------------------------- /outputs.tf: -------------------------------------------------------------------------------- 1 | output "cache_security_group_id" { 2 | value = "${aws_security_group.redis.id}" 3 | } 4 | 5 | output "hostname" { 6 | value = "${aws_elasticache_cluster.redis.cache_nodes.0.address}" 7 | } 8 | 9 | output "port" { 10 | value = "${aws_elasticache_cluster.redis.cache_nodes.0.port}" 11 | } 12 | 13 | output "endpoint" { 14 | value = "${join(":", list(aws_elasticache_cluster.redis.cache_nodes.0.address, aws_elasticache_cluster.redis.cache_nodes.0.port))}" 15 | } 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2016 Turner 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /variables.tf: -------------------------------------------------------------------------------- 1 | variable "cluster_id" {} 2 | 3 | variable "vpc_id" {} 4 | 5 | variable "private_subnet_ids" {} 6 | 7 | variable "engine_version" { 8 | default = "2.8.24" 9 | } 10 | 11 | variable "parameter_group_name" { 12 | default = "default.redis2.8" 13 | } 14 | 15 | variable "instance_type" { 16 | default = "cache.m3.medium" 17 | } 18 | 19 | variable "maintenance_window" { 20 | # SUN 01:00AM-02:00AM ET 21 | default = "sun:05:00-sun:06:00" 22 | } 23 | 24 | # tags 25 | variable "tag_name" {} 26 | 27 | variable "tag_environment" {} 28 | variable "tag_team" {} 29 | variable "tag_application" {} 30 | variable "tag_contact-email" {} 31 | variable "tag_customer" {} 32 | -------------------------------------------------------------------------------- /examples/open/readme.md: -------------------------------------------------------------------------------- 1 | An example that launches a redis cluster inside a VPC with open access. 2 | 3 | 4 | ```terraform 5 | provider "aws" { 6 | region = "us-east-1" 7 | } 8 | 9 | module "elasticache_redis" { 10 | source = "github.com/turnerlabs/terraform-aws-elasticache-redis?ref=v2.2" 11 | 12 | cluster_id = "myteam-myapp-dev" 13 | engine_version = "2.8.24" 14 | instance_type = "cache.m3.medium" 15 | maintenance_window = "sun:05:00-sun:06:00" 16 | vpc_id = "vpc-d070efb3" 17 | private_subnet_ids = "subnet-020d8b59,subnet-13f50b64" 18 | 19 | tag_name = "myteam-myapp-dev" 20 | tag_team = "my-team" 21 | tag_contact-email = "my-team@turner.com" 22 | tag_application = "my-app" 23 | tag_environment = "dev" 24 | tag_customer = "my-customer" 25 | } 26 | 27 | resource "aws_security_group_rule" "access_in" { 28 | security_group_id = "${module.elasticache_redis.cache_security_group_id}" 29 | type = "ingress" 30 | from_port = 6379 31 | to_port = 6379 32 | protocol = "tcp" 33 | cidr_blocks = ["0.0.0.0/0"] 34 | } 35 | 36 | resource "aws_security_group_rule" "access_out" { 37 | security_group_id = "${module.elasticache_redis.cache_security_group_id}" 38 | type = "egress" 39 | from_port = 6379 40 | to_port = 6379 41 | protocol = "tcp" 42 | cidr_blocks = ["0.0.0.0/0"] 43 | } 44 | ``` 45 | -------------------------------------------------------------------------------- /main.tf: -------------------------------------------------------------------------------- 1 | resource "aws_security_group" "redis" { 2 | vpc_id = "${var.vpc_id}" 3 | 4 | tags { 5 | Name = "${var.tag_name}" 6 | environment = "${var.tag_environment}" 7 | team = "${var.tag_team}" 8 | application = "${var.tag_application}" 9 | contact-email = "${var.tag_contact-email}" 10 | tag_customer = "${var.tag_customer}" 11 | } 12 | } 13 | 14 | resource "aws_elasticache_subnet_group" "default" { 15 | name = "subnet-group-${var.tag_team}-${var.tag_application}-${var.tag_environment}" 16 | description = "Private subnets for the ElastiCache instances: ${var.tag_team} ${var.tag_application} ${var.tag_environment}" 17 | subnet_ids = ["${split(",", var.private_subnet_ids)}"] 18 | } 19 | 20 | resource "aws_elasticache_cluster" "redis" { 21 | cluster_id = "${var.cluster_id}" 22 | engine = "redis" 23 | engine_version = "${var.engine_version}" 24 | maintenance_window = "${var.maintenance_window}" 25 | node_type = "${var.instance_type}" 26 | num_cache_nodes = "1" 27 | parameter_group_name = "${var.parameter_group_name}" 28 | port = "6379" 29 | subnet_group_name = "${aws_elasticache_subnet_group.default.name}" 30 | security_group_ids = ["${aws_security_group.redis.id}"] 31 | 32 | tags { 33 | Name = "${var.tag_name}" 34 | environment = "${var.tag_environment}" 35 | team = "${var.tag_team}" 36 | application = "${var.tag_application}" 37 | contact-email = "${var.tag_contact-email}" 38 | tag_customer = "${var.tag_customer}" 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | # terraform-aws-elasticache-redis 2 | 3 | A Terraform module that represents an AWS ElastiCache Redis cluster. Note that a default security group is created and outputted that can be extended. See basic example usage below and more examples [here](/examples). 4 | 5 | ### Usage 6 | 7 | ```terraform 8 | provider "aws" { 9 | region = "us-east-1" 10 | } 11 | 12 | module "elasticache_redis" { 13 | source = "github.com/turnerlabs/terraform-aws-elasticache-redis?ref=v2.2" 14 | 15 | cluster_id = "myteam-myapp-dev" 16 | engine_version = "2.8.24" 17 | instance_type = "cache.m3.medium" 18 | maintenance_window = "sun:05:00-sun:06:00" 19 | vpc_id = "vpc-d070efb3" 20 | private_subnet_ids = "subnet-020d8b59,subnet-13f50b64" 21 | 22 | tag_name = "myteam-myapp-dev" 23 | tag_team = "my-team" 24 | tag_contact-email = "my-team@turner.com" 25 | tag_application = "my-app" 26 | tag_environment = "dev" 27 | tag_customer = "my-customer" 28 | } 29 | ``` 30 | 31 | ### Variables 32 | 33 | - `cluster_id` - ID of the cluster 34 | - `vpc_id` - ID of VPC meant to house the cache 35 | - `private_subnet_ids` - Comma delimited list of private subnet IDs 36 | - `engine_version` - Cache engine version (default: `2.8.24`) 37 | - `instance_type` - Instance type for cache instance (default: `cache.m3.medium`) 38 | - `maintenance_window` - 60 minute time window to reserve for maintenance 39 | (default: `sun:05:00-sun:06:00`) 40 | - `parameter_group_name` - Name of the parameter group to associate with this cache cluster (default: `default.redis2.8`) 41 | - `tag_name` 42 | - `tag_environment` 43 | - `tag_team` 44 | - `tag_application` 45 | - `tag_customer` 46 | - `tag_contact-email` 47 | 48 | 49 | ### Outputs 50 | 51 | - `cache_security_group_id` - Security group ID of the cache cluster 52 | - `hostname` - Public DNS name of cache node 53 | - `port` - Port of cache instance 54 | - `endpoint` - Public DNS name and port separated by a `:` 55 | --------------------------------------------------------------------------------