Skip to content

Commit

Permalink
feat: Support elasticache serverless cache (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
magreenbaum authored Apr 24, 2024
1 parent 079e768 commit f91028d
Show file tree
Hide file tree
Showing 23 changed files with 470 additions and 22 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,14 @@ Examples codified under the [`examples`](https://github.com/terraform-aws-module
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.27 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.46 |
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.27 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.46 |
| <a name="provider_random"></a> [random](#provider\_random) | >= 3.0 |

## Modules
Expand Down
4 changes: 2 additions & 2 deletions examples/memcached-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ Note that this example may create resources which will incur monetary charges on
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.27 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.46 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.27 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.46 |

## Modules

Expand Down
2 changes: 1 addition & 1 deletion examples/memcached-cluster/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.27"
version = ">= 5.46"
}
}
}
4 changes: 2 additions & 2 deletions examples/redis-cluster-mode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ Note that this example may create resources which will incur monetary charges on
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.27 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.46 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.27 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.46 |

## Modules

Expand Down
2 changes: 1 addition & 1 deletion examples/redis-cluster-mode/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.27"
version = ">= 5.46"
}
}
}
4 changes: 2 additions & 2 deletions examples/redis-cluster/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ Note that this example may create resources which will incur monetary charges on
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.27 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.46 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.27 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.46 |

## Modules

Expand Down
2 changes: 1 addition & 1 deletion examples/redis-cluster/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.27"
version = ">= 5.46"
}
}
}
6 changes: 3 additions & 3 deletions examples/redis-global-replication-group/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ Note that this example may create resources which will incur monetary charges on
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.27 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.46 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.27 |
| <a name="provider_aws.euwest1"></a> [aws.euwest1](#provider\_aws.euwest1) | >= 5.27 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.46 |
| <a name="provider_aws.euwest1"></a> [aws.euwest1](#provider\_aws.euwest1) | >= 5.46 |

## Modules

Expand Down
2 changes: 1 addition & 1 deletion examples/redis-global-replication-group/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.27"
version = ">= 5.46"
}
}
}
4 changes: 2 additions & 2 deletions examples/redis-replication-group/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ Note that this example may create resources which will incur monetary charges on
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.27 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.46 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.27 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.46 |

## Modules

Expand Down
2 changes: 1 addition & 1 deletion examples/redis-replication-group/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.27"
version = ">= 5.46"
}
}
}
109 changes: 109 additions & 0 deletions examples/serverless-cache/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
provider "aws" {
region = local.region
}

data "aws_availability_zones" "available" {}

locals {
region = "eu-west-1"
name = "ex-${basename(path.cwd)}"

vpc_cidr = "10.0.0.0/16"
azs = slice(data.aws_availability_zones.available.names, 0, 3)

tags = {
Name = local.name
Example = local.name
Repository = "https://github.com/terraform-aws-modules/terraform-aws-elasticache"
}
}

module "serverless" {
source = "../../modules/serverless-cache"

engine = "redis"
cache_name = local.name

cache_usage_limits = {
data_storage = {
maximum = 2
}
ecpu_per_second = {
maximum = 1000
}
}

daily_snapshot_time = "22:00"
description = "${local.name} serverless cluster"
kms_key_id = aws_kms_key.this.arn
major_engine_version = "7"
security_group_ids = [module.sg.security_group_id]

snapshot_retention_limit = 7
subnet_ids = module.vpc.private_subnets

user_group_id = module.cache_user_group.group_id
}

module "cache_user_group" {
source = "../../modules/user-group"

default_user = {
user_id = "${local.name}-default"
authentication_mode = {
type = "no-password-required"
}
}

users = {
redis = {
user_id = local.name
user_name = "redis"
access_string = "on ~* -@all +@read"
authentication_mode = {
type = "no-password-required"
}
}
}

user_group_id = "redis"
}

################################################################################
# Supporting Resources
################################################################################

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 5.0"

name = local.name
cidr = local.vpc_cidr

azs = local.azs
public_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k)]
private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 10)]

tags = local.tags
}

resource "aws_kms_key" "this" {
description = "KMS CMK for ${local.name}"
enable_key_rotation = true

tags = local.tags
}

module "sg" {
source = "terraform-aws-modules/security-group/aws"
version = "~> 5.0"

name = local.name
description = "Security group for VPC traffic"
vpc_id = module.vpc.vpc_id

ingress_cidr_blocks = [module.vpc.vpc_cidr_block]
ingress_rules = ["redis-tcp"]

tags = local.tags
}
34 changes: 34 additions & 0 deletions examples/serverless-cache/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
output "serverless_cache_arn" {
description = "The amazon resource name of the serverless cache"
value = module.serverless.serverless_cache_arn
}

output "serverless_cache_create_time" {
description = "Timestamp of when the serverless cache was created"
value = module.serverless.serverless_cache_create_time
}

output "serverless_cache_endpoint" {
description = " Represents the information required for client programs to connect to a cache node"
value = module.serverless.serverless_cache_endpoint
}

output "serverless_cache_full_engine_version" {
description = "The name and version number of the engine the serverless cache is compatible with"
value = module.serverless.serverless_cache_full_engine_version
}

output "serverless_cache_major_engine_version" {
description = "The version number of the engine the serverless cache is compatible with"
value = module.serverless.serverless_cache_major_engine_version
}

output "serverless_cache_reader_endpoint" {
description = "Represents the information required for client programs to connect to a cache node"
value = module.serverless.serverless_cache_reader_endpoint
}

output "serverless_cache_status" {
description = "The current status of the serverless cache. The allowed values are CREATING, AVAILABLE, DELETING, CREATE-FAILED and MODIFYING"
value = module.serverless.serverless_cache_status
}
Empty file.
10 changes: 10 additions & 0 deletions examples/serverless-cache/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
terraform {
required_version = ">= 1.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.46"
}
}
}
Loading

0 comments on commit f91028d

Please sign in to comment.