diff --git a/README.md b/README.md
index d75571e..e3f9b70 100644
--- a/README.md
+++ b/README.md
@@ -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
@@ -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)
@@ -157,7 +158,7 @@ No modules.
| [create\_users](#input\_create\_users) | Determines whether to create users specified | `bool` | `true` | no |
| [data\_tiering](#input\_data\_tiering) | Must be set to `true` when using a data tiering node type | `bool` | `null` | no |
| [description](#input\_description) | Description for the cluster. Defaults to `Managed by Terraform` | `string` | `null` | no |
-| [engine](#input\_engine) | The engine that will run on your nodes. Supported values are redis and valkey | `string` | `null` | no |
+| [engine](#input\_engine) | The engine that will run on your nodes. Supported values are `redis` and `valkey` | `string` | `null` | no |
| [engine\_version](#input\_engine\_version) | Version number of the engine to be used for the cluster. Downgrades are not supported | `string` | `null` | no |
| [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 |
| [kms\_key\_arn](#input\_kms\_key\_arn) | ARN of the KMS key used to encrypt the cluster at rest | `string` | `null` | no |
diff --git a/examples/complete/README.md b/examples/redis/README.md
similarity index 96%
rename from examples/complete/README.md
rename to examples/redis/README.md
index a048f11..deee909 100644
--- a/examples/complete/README.md
+++ b/examples/redis/README.md
@@ -42,7 +42,7 @@ Note that this example may create resources which will incur monetary charges on
|------|--------|---------|
| [memory\_db](#module\_memory\_db) | ../.. | n/a |
| [memory\_db\_disabled](#module\_memory\_db\_disabled) | ../.. | n/a |
-| [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 4.0 |
+| [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 5.0 |
| [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 6.0 |
## Resources
@@ -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
diff --git a/examples/complete/main.tf b/examples/redis/main.tf
similarity index 79%
rename from examples/complete/main.tf
rename to examples/redis/main.tf
index 03b5675..be10e1e 100644
--- a/examples/complete/main.tf
+++ b/examples/redis/main.tf
@@ -2,13 +2,25 @@ 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"
}
}
@@ -16,13 +28,6 @@ locals {
# MemoryDB Module
################################################################################
-module "memory_db_disabled" {
- source = "../.."
-
- name = "${local.name}-disabled"
- create = false
-}
-
module "memory_db" {
source = "../.."
@@ -30,6 +35,7 @@ module "memory_db" {
name = local.name
description = "Example MemoryDB cluster"
+ engine = "redis"
engine_version = "7.0"
auto_minor_version_upgrade = true
node_type = "db.r6gd.xlarge"
@@ -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" }
@@ -89,6 +95,13 @@ module "memory_db" {
tags = local.tags
}
+module "memory_db_disabled" {
+ source = "../.."
+
+ name = "${local.name}-disabled"
+ create = false
+}
+
################################################################################
# Supporting Resources
################################################################################
@@ -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
@@ -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}"
diff --git a/examples/complete/outputs.tf b/examples/redis/outputs.tf
similarity index 100%
rename from examples/complete/outputs.tf
rename to examples/redis/outputs.tf
diff --git a/examples/complete/variables.tf b/examples/redis/variables.tf
similarity index 100%
rename from examples/complete/variables.tf
rename to examples/redis/variables.tf
diff --git a/examples/complete/versions.tf b/examples/redis/versions.tf
similarity index 100%
rename from examples/complete/versions.tf
rename to examples/redis/versions.tf
diff --git a/examples/valkey/README.md b/examples/valkey/README.md
index e55d7df..ba1eac6 100644
--- a/examples/valkey/README.md
+++ b/examples/valkey/README.md
@@ -42,7 +42,7 @@ Note that this example may create resources which will incur monetary charges on
|------|--------|---------|
| [memory\_db](#module\_memory\_db) | ../.. | n/a |
| [memory\_db\_disabled](#module\_memory\_db\_disabled) | ../.. | n/a |
-| [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 4.0 |
+| [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 5.0 |
| [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 6.0 |
## Resources
@@ -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
diff --git a/examples/valkey/main.tf b/examples/valkey/main.tf
index 4b34cda..ed9f3d2 100644
--- a/examples/valkey/main.tf
+++ b/examples/valkey/main.tf
@@ -2,13 +2,25 @@ 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"
}
}
@@ -16,13 +28,6 @@ locals {
# MemoryDB Module
################################################################################
-module "memory_db_disabled" {
- source = "../.."
-
- name = "${local.name}-disabled"
- create = false
-}
-
module "memory_db" {
source = "../.."
@@ -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
@@ -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" }
@@ -90,6 +95,13 @@ module "memory_db" {
tags = local.tags
}
+module "memory_db_disabled" {
+ source = "../.."
+
+ name = "${local.name}-disabled"
+ create = false
+}
+
################################################################################
# Supporting Resources
################################################################################
@@ -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
@@ -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}"
diff --git a/main.tf b/main.tf
index 0000553..fc9cbc7 100644
--- a/main.tf
+++ b/main.tf
@@ -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
@@ -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
}
@@ -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
@@ -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
@@ -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
@@ -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
diff --git a/outputs.tf b/outputs.tf
index 82bf7b5..e4656a2 100644
--- a/outputs.tf
+++ b/outputs.tf
@@ -4,32 +4,32 @@
output "cluster_id" {
description = "Cluster name"
- value = try(aws_memorydb_cluster.this[0].id, "")
+ value = try(aws_memorydb_cluster.this[0].id, null)
}
output "cluster_arn" {
description = "The ARN of the cluster"
- value = try(aws_memorydb_cluster.this[0].arn, "")
+ value = try(aws_memorydb_cluster.this[0].arn, null)
}
output "cluster_endpoint_address" {
description = "DNS hostname of the cluster configuration endpoint"
- value = try(aws_memorydb_cluster.this[0].cluster_endpoint[0].address, "")
+ value = try(aws_memorydb_cluster.this[0].cluster_endpoint[0].address, null)
}
output "cluster_endpoint_port" {
description = "Port number that the cluster configuration endpoint is listening on"
- value = try(aws_memorydb_cluster.this[0].cluster_endpoint[0].port, "")
+ value = try(aws_memorydb_cluster.this[0].cluster_endpoint[0].port, null)
}
output "cluster_engine_patch_version" {
description = "Patch version number of the Redis engine used by the cluster"
- value = try(aws_memorydb_cluster.this[0].engine_patch_version, "")
+ value = try(aws_memorydb_cluster.this[0].engine_patch_version, null)
}
output "cluster_shards" {
description = "Set of shards in this cluster"
- value = try(aws_memorydb_cluster.this[0].shards, [])
+ value = try(aws_memorydb_cluster.this[0].shards, null)
}
################################################################################
@@ -48,17 +48,17 @@ output "users" {
output "acl_id" {
description = "Name of the ACL"
- value = try(aws_memorydb_acl.this[0].id, "")
+ value = try(aws_memorydb_acl.this[0].id, null)
}
output "acl_arn" {
description = "The ARN of the ACL"
- value = try(aws_memorydb_acl.this[0].arn, "")
+ value = try(aws_memorydb_acl.this[0].arn, null)
}
output "acl_minimum_engine_version" {
description = "The minimum engine version supported by the ACL"
- value = try(aws_memorydb_acl.this[0].minimum_engine_version, "")
+ value = try(aws_memorydb_acl.this[0].minimum_engine_version, null)
}
################################################################################
@@ -67,12 +67,12 @@ output "acl_minimum_engine_version" {
output "parameter_group_id" {
description = "Name of the parameter group"
- value = try(aws_memorydb_parameter_group.this[0].id, "")
+ value = try(aws_memorydb_parameter_group.this[0].id, null)
}
output "parameter_group_arn" {
description = "The ARN of the parameter group"
- value = try(aws_memorydb_parameter_group.this[0].arn, "")
+ value = try(aws_memorydb_parameter_group.this[0].arn, null)
}
################################################################################
@@ -81,15 +81,15 @@ output "parameter_group_arn" {
output "subnet_group_id" {
description = "Name of the subnet group"
- value = try(aws_memorydb_subnet_group.this[0].id, "")
+ value = try(aws_memorydb_subnet_group.this[0].id, null)
}
output "subnet_group_arn" {
description = "ARN of the subnet group"
- value = try(aws_memorydb_subnet_group.this[0].arn, "")
+ value = try(aws_memorydb_subnet_group.this[0].arn, null)
}
output "subnet_group_vpc_id" {
description = "The VPC in which the subnet group exists"
- value = try(aws_memorydb_subnet_group.this[0].vpc_id, "")
+ value = try(aws_memorydb_subnet_group.this[0].vpc_id, null)
}
diff --git a/variables.tf b/variables.tf
index 3201152..2a6a1b4 100644
--- a/variables.tf
+++ b/variables.tf
@@ -39,7 +39,7 @@ variable "description" {
}
variable "engine" {
- description = "The engine that will run on your nodes. Supported values are redis and valkey"
+ description = "The engine that will run on your nodes. Supported values are `redis` and `valkey`"
type = string
default = null
}
@@ -156,6 +156,7 @@ variable "multi_region_cluster_name" {
# User(s)
################################################################################
+# TODO - remove at next breaking change
variable "create_users" {
description = "Determines whether to create users specified"
type = bool