Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

tomarv2/terraform-aws-elasticache

Open more actions menu

Repository files navigation

Terraform module for AWS Elasticache

➡️ Terraform module for Azure Cache for Redis

➡️ Terraform module for Google Memorystore

Versions

  • Module tested for Terraform 1.0.1.
  • AWS provider version 3.63
  • main branch: Provider versions not pinned to keep up with Terraform releases
  • tags releases: Tags are pinned with versions (use in your releases)

Usage

Option 1:

terrafrom init
terraform plan -var='teamid=tryme' -var='prjid=project1'
terraform apply -var='teamid=tryme' -var='prjid=project1'
terraform destroy -var='teamid=tryme' -var='prjid=project1'

Note: With this option please take care of remote state storage

Option 2:

Recommended method (stores remote state in S3 using prjid and teamid to create directory structure):

  • Create python 3.8+ virtual environment
python3 -m venv <venv name>
  • Install package:
pip install tfremote --upgrade
  • Set below environment variables:
export TF_AWS_BUCKET=<remote state bucket name>
export TF_AWS_BUCKET_REGION=us-west-2
export TF_AWS_PROFILE=<profile from ~/.ws/credentials>

or

  • Set below environment variables:
export TF_AWS_BUCKET=<remote state bucket name>
export TF_AWS_BUCKET_REGION=us-west-2
export AWS_ACCESS_KEY_ID=<aws_access_key_id>
export AWS_SECRET_ACCESS_KEY=<aws_secret_access_key>
  • Updated examples directory with required values.

  • Run and verify the output before deploying:

tf -c=aws plan -var='teamid=foo' -var='prjid=bar'
  • Run below to deploy:
tf -c=aws apply -var='teamid=foo' -var='prjid=bar'
  • Run below to destroy:
tf -c=aws destroy -var='teamid=foo' -var='prjid=bar'

NOTE:


terraform {
  required_version = ">= 1.0.1"
  required_providers {
    aws = {
      version = "~> 3.63"
    }
  }
}

provider "aws" {
  region = var.region
}

module "redis" {
  source = "../"

  deploy_redis                 = true
  deploy_redis_parameter_group = true

  security_group_ids = [module.security_group.security_group_id]
  # ----------------------------------------------
  # Note: Do not change teamid and prjid once set.
  teamid = var.teamid
  prjid  = var.prjid
}

module "security_group" {
  source = "git::git@github.com:tomarv2/terraform-aws-security-group.git?ref=v0.0.6"

  deploy_security_group = true

  service_ports = [6379]
  teamid        = var.teamid
  prjid         = var.prjid
}

Please refer to examples directory link for references.

Requirements

Name Version
terraform >= 1.0.1
aws ~> 3.63

Providers

Name Version
aws ~> 3.63

Modules

Name Source Version
global git::git@github.com:tomarv2/terraform-global.git//aws v0.0.1

Resources

Name Type
aws_elasticache_cluster.default resource
aws_elasticache_parameter_group.default resource
aws_elasticache_subnet_group.default resource
aws_caller_identity.current data source
aws_region.current data source

Inputs

Name Description Type Default Required
apply_immediately Specifies whether any database modifications are applied immediately, or during the next maintenance window. Default is false. bool true no
availability_zone The Availability Zone for the cache cluster. If you want to create cache nodes in multi-az, use preferred_availability_zones instead. Default: System chosen Availability Zone. Changing this value will re-create the resource. string null no
az_mode (Memcached only) 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, default is single-az. If you want to choose cross-az, num_cache_nodes must be greater than 1. string null no
cache_nodes The initial number of cache nodes that the cache cluster will have. For Redis, this value must be 1. For Memcache, this value must be between 1 and 20. number 1 no
cluster_id Group identifier. ElastiCache converts this name to lowercase string null no
cluster_mode_enabled 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
deploy_redis Feature flag, true or false bool true no
deploy_redis_parameter_group Feature flag, true or false bool true no
engine Name of the cache engine to be used for this cache cluster. Valid values for this parameter are memcached or redis. string "redis" no
engine_version Version of engine string "5.0.6" no
maintenance_window Specifies the weekly time range for when maintenance on the cache cluster is performed. string "mon:10:30-mon:11:30" no
node_type The compute and memory capacity of the nodes string "cache.t2.micro" no
notification_topic_arn 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
parameter A list of Redis parameters to apply. Note that parameters may differ from one Redis family to another
list(object({
name = string
value = string
}))
[] no
parameter_group_family The family of the ElastiCache parameter group string "redis5.0" no
port 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
prjid Name of the project/stack e.g: mystack, nifieks, demoaci. Should not be changed after running 'tf apply' string n/a yes
security_group_ids One or more VPC security groups associated with the cache cluster string n/a yes
snapshot_arns 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(any)
[
""
]
no
snapshot_retention_limit Number of days snapshot image will be retained number 5 no
snapshot_window Daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your cache cluster. Example: 05:00-09:00. string "" no
teamid Name of the team/group e.g. devops, dataengineering. Should not be changed after running 'tf apply' string n/a yes

Outputs

Name Description
aws_elasticache_parameter_group Elasticache Parameter Group
elasticache_cluster_address Elasticache Cluster address
elasticache_id Elasticache Id

Note:

  • For more information on redis: link

About

Terraform module for AWS Elasticache

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 2

  •  
  •  

Languages

Morty Proxy This is a proxified and sanitized view of the page, visit original site.