Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ module "memory_db" {
name = "example"
description = "Example MemoryDB cluster"

engine_version = "6.2"
engine = "valkey"
engine_version = "7.3"
auto_minor_version_upgrade = true
node_type = "db.t4g.small"
num_shards = 2
Expand Down Expand Up @@ -110,7 +111,7 @@ module "memory_db" {

Examples codified under the [`examples`](https://github.com/terraform-aws-modules/terraform-aws-memory-db/tree/master/examples) are intended to give users references for how to use the module(s) as well as testing/validating changes to the source code of the module. If contributing to the project, please be sure to make any appropriate updates to the relevant examples to allow maintainers to test your changes and to keep the examples up to date for users. Thank you!

- [Complete](https://github.com/terraform-aws-modules/terraform-aws-memory-db/tree/master/examples/complete)
- [Redis](https://github.com/terraform-aws-modules/terraform-aws-memory-db/tree/master/examples/redis)
- [Valkey](https://github.com/terraform-aws-modules/terraform-aws-memory-db/tree/master/examples/valkey)

<!-- BEGIN_TF_DOCS -->
Expand Down Expand Up @@ -157,7 +158,7 @@ No modules.
| <a name="input_create_users"></a> [create\_users](#input\_create\_users) | Determines whether to create users specified | `bool` | `true` | no |
| <a name="input_data_tiering"></a> [data\_tiering](#input\_data\_tiering) | Must be set to `true` when using a data tiering node type | `bool` | `null` | no |
| <a name="input_description"></a> [description](#input\_description) | Description for the cluster. Defaults to `Managed by Terraform` | `string` | `null` | no |
| <a name="input_engine"></a> [engine](#input\_engine) | The engine that will run on your nodes. Supported values are redis and valkey | `string` | `null` | no |
| <a name="input_engine"></a> [engine](#input\_engine) | The engine that will run on your nodes. Supported values are `redis` and `valkey` | `string` | `null` | no |
| <a name="input_engine_version"></a> [engine\_version](#input\_engine\_version) | Version number of the engine to be used for the cluster. Downgrades are not supported | `string` | `null` | no |
| <a name="input_final_snapshot_name"></a> [final\_snapshot\_name](#input\_final\_snapshot\_name) | Name of the final cluster snapshot to be created when this resource is deleted. If omitted, no final snapshot will be made | `string` | `null` | no |
| <a name="input_kms_key_arn"></a> [kms\_key\_arn](#input\_kms\_key\_arn) | ARN of the KMS key used to encrypt the cluster at rest | `string` | `null` | no |
Expand Down
3 changes: 2 additions & 1 deletion examples/complete/README.md → examples/redis/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Note that this example may create resources which will incur monetary charges on
|------|--------|---------|
| <a name="module_memory_db"></a> [memory\_db](#module\_memory\_db) | ../.. | n/a |
| <a name="module_memory_db_disabled"></a> [memory\_db\_disabled](#module\_memory\_db\_disabled) | ../.. | n/a |
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 4.0 |
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 5.0 |
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 6.0 |

## Resources
Expand All @@ -51,6 +51,7 @@ Note that this example may create resources which will incur monetary charges on
|------|------|
| [aws_sns_topic.example](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic) | resource |
| [random_password.password](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |

## Inputs

Expand Down
49 changes: 31 additions & 18 deletions examples/complete/main.tf → examples/redis/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,40 @@ provider "aws" {
region = local.region
}

data "aws_availability_zones" "available" {
# Exclude local zones
filter {
name = "opt-in-status"
values = ["opt-in-not-required"]
}
}

locals {
region = "us-east-1"
name = "memorydb-ex-${replace(basename(path.cwd), "_", "-")}"
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 = {
Example = local.name
Environment = "dev"
Name = local.name
Example = local.name
Repository = "https://github.com/terraform-aws-modules/terraform-aws-memory-db"
}
}

################################################################################
# MemoryDB Module
################################################################################

module "memory_db_disabled" {
source = "../.."

name = "${local.name}-disabled"
create = false
}

module "memory_db" {
source = "../.."

# Cluster
name = local.name
description = "Example MemoryDB cluster"

engine = "redis"
engine_version = "7.0"
auto_minor_version_upgrade = true
node_type = "db.r6gd.xlarge"
Expand All @@ -47,13 +53,13 @@ module "memory_db" {
# Users
users = {
admin = {
user_name = "admin-user"
user_name = "redis-admin-user"
access_string = "on ~* &* +@all"
type = "iam"
tags = { user = "admin" }
}
readonly = {
user_name = "readonly-user"
user_name = "redis-readonly-user"
access_string = "on ~* &* -@all +@read"
passwords = [random_password.password.result]
tags = { user = "readonly" }
Expand Down Expand Up @@ -89,6 +95,13 @@ module "memory_db" {
tags = local.tags
}

module "memory_db_disabled" {
source = "../.."

name = "${local.name}-disabled"
create = false
}

################################################################################
# Supporting Resources
################################################################################
Expand All @@ -98,11 +111,11 @@ module "vpc" {
version = "~> 6.0"

name = local.name
cidr = "10.99.0.0/18"
cidr = local.vpc_cidr

azs = ["${local.region}a", "${local.region}b", "${local.region}d"] # Caution: check which zones are available
private_subnets = ["10.99.0.0/24", "10.99.1.0/24", "10.99.2.0/24"]
database_subnets = ["10.99.3.0/24", "10.99.4.0/24", "10.99.5.0/24"]
azs = local.azs
private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 4, k)]
database_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 48)]

create_database_subnet_group = true
enable_nat_gateway = false
Expand All @@ -116,7 +129,7 @@ module "vpc" {

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

name = local.name
description = "Security group for ${local.name}"
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion examples/valkey/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Note that this example may create resources which will incur monetary charges on
|------|--------|---------|
| <a name="module_memory_db"></a> [memory\_db](#module\_memory\_db) | ../.. | n/a |
| <a name="module_memory_db_disabled"></a> [memory\_db\_disabled](#module\_memory\_db\_disabled) | ../.. | n/a |
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 4.0 |
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 5.0 |
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 6.0 |

## Resources
Expand All @@ -51,6 +51,7 @@ Note that this example may create resources which will incur monetary charges on
|------|------|
| [aws_sns_topic.example](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic) | resource |
| [random_password.password](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |
| [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |

## Inputs

Expand Down
50 changes: 31 additions & 19 deletions examples/valkey/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,32 @@ provider "aws" {
region = local.region
}

data "aws_availability_zones" "available" {
# Exclude local zones
filter {
name = "opt-in-status"
values = ["opt-in-not-required"]
}
}

locals {
region = "us-east-1"
name = "memorydb-ex-${replace(basename(path.cwd), "_", "-")}"
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 = {
Example = local.name
Environment = "dev"
Name = local.name
Example = local.name
Repository = "https://github.com/terraform-aws-modules/terraform-aws-memory-db"
}
}

################################################################################
# MemoryDB Module
################################################################################

module "memory_db_disabled" {
source = "../.."

name = "${local.name}-disabled"
create = false
}

module "memory_db" {
source = "../.."

Expand All @@ -31,7 +36,7 @@ module "memory_db" {
description = "Example MemoryDB cluster"

engine = "valkey"
engine_version = "7.2"
engine_version = "7.3"
auto_minor_version_upgrade = true
node_type = "db.r6gd.xlarge"
num_shards = 2
Expand All @@ -48,13 +53,13 @@ module "memory_db" {
# Users
users = {
admin = {
user_name = "admin-user"
user_name = "valkey-admin-user"
access_string = "on ~* &* +@all"
type = "iam"
tags = { user = "admin" }
}
readonly = {
user_name = "readonly-user"
user_name = "valkey-readonly-user"
access_string = "on ~* &* -@all +@read"
passwords = [random_password.password.result]
tags = { user = "readonly" }
Expand Down Expand Up @@ -90,6 +95,13 @@ module "memory_db" {
tags = local.tags
}

module "memory_db_disabled" {
source = "../.."

name = "${local.name}-disabled"
create = false
}

################################################################################
# Supporting Resources
################################################################################
Expand All @@ -99,11 +111,11 @@ module "vpc" {
version = "~> 6.0"

name = local.name
cidr = "10.98.0.0/18"
cidr = local.vpc_cidr

azs = ["${local.region}a", "${local.region}b", "${local.region}d"] # Caution: check which zones are available
private_subnets = ["10.98.0.0/24", "10.98.1.0/24", "10.98.2.0/24"]
database_subnets = ["10.98.3.0/24", "10.98.4.0/24", "10.98.5.0/24"]
azs = local.azs
private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 4, k)]
database_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 48)]

create_database_subnet_group = true
enable_nat_gateway = false
Expand All @@ -117,7 +129,7 @@ module "vpc" {

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

name = local.name
description = "Security group for ${local.name}"
Expand Down
15 changes: 10 additions & 5 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ locals {
resource "aws_memorydb_cluster" "this" {
count = var.create ? 1 : 0

region = var.region

name = var.use_name_prefix ? null : var.name
name_prefix = var.use_name_prefix ? "${var.name}-" : null
description = var.description
Expand Down Expand Up @@ -45,7 +47,6 @@ resource "aws_memorydb_cluster" "this" {
snapshot_retention_limit = var.snapshot_retention_limit
snapshot_window = var.snapshot_window
final_snapshot_name = var.final_snapshot_name
region = var.region

tags = var.tags
}
Expand All @@ -57,9 +58,10 @@ resource "aws_memorydb_cluster" "this" {
resource "aws_memorydb_user" "this" {
for_each = { for k, v in var.users : k => v if var.create && var.create_users }

region = var.region

user_name = each.value.user_name
access_string = each.value.access_string
region = var.region

authentication_mode {
type = each.value.type
Expand All @@ -76,11 +78,12 @@ resource "aws_memorydb_user" "this" {
resource "aws_memorydb_acl" "this" {
count = var.create && var.create_acl ? 1 : 0

region = var.region

name = var.acl_use_name_prefix ? null : local.create_acl_name
name_prefix = var.acl_use_name_prefix ? "${local.create_acl_name}-" : null

user_names = distinct(concat([for u in aws_memorydb_user.this : u.id], var.acl_user_names))
region = var.region

lifecycle {
create_before_destroy = true
Expand All @@ -96,11 +99,12 @@ resource "aws_memorydb_acl" "this" {
resource "aws_memorydb_parameter_group" "this" {
count = var.create && var.create_parameter_group ? 1 : 0

region = var.region

name = var.parameter_group_use_name_prefix ? null : local.create_parameter_group_name
name_prefix = var.parameter_group_use_name_prefix ? "${local.create_parameter_group_name}-" : null
description = var.parameter_group_description
family = var.parameter_group_family
region = var.region

dynamic "parameter" {
for_each = var.parameter_group_parameters
Expand All @@ -124,11 +128,12 @@ resource "aws_memorydb_parameter_group" "this" {
resource "aws_memorydb_subnet_group" "this" {
count = var.create && var.create_subnet_group ? 1 : 0

region = var.region

name = var.subnet_group_use_name_prefix ? null : local.create_subnet_group_name
name_prefix = var.subnet_group_use_name_prefix ? "${local.create_subnet_group_name}-" : null
description = var.subnet_group_description
subnet_ids = var.subnet_ids
region = var.region

lifecycle {
create_before_destroy = true
Expand Down
Loading