Skip to content

Commit 7a994d3

Browse files
authored
chore: Update examples to use latest versions and practices (#17)
1 parent b67d63d commit 7a994d3

File tree

11 files changed

+96
-62
lines changed

11 files changed

+96
-62
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ module "memory_db" {
1414
name = "example"
1515
description = "Example MemoryDB cluster"
1616
17-
engine_version = "6.2"
17+
engine = "valkey"
18+
engine_version = "7.3"
1819
auto_minor_version_upgrade = true
1920
node_type = "db.t4g.small"
2021
num_shards = 2
@@ -110,7 +111,7 @@ module "memory_db" {
110111

111112
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!
112113

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

116117
<!-- BEGIN_TF_DOCS -->
@@ -157,7 +158,7 @@ No modules.
157158
| <a name="input_create_users"></a> [create\_users](#input\_create\_users) | Determines whether to create users specified | `bool` | `true` | no |
158159
| <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 |
159160
| <a name="input_description"></a> [description](#input\_description) | Description for the cluster. Defaults to `Managed by Terraform` | `string` | `null` | no |
160-
| <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 |
161+
| <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 |
161162
| <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 |
162163
| <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 |
163164
| <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 |

examples/complete/README.md renamed to examples/redis/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Note that this example may create resources which will incur monetary charges on
4242
|------|--------|---------|
4343
| <a name="module_memory_db"></a> [memory\_db](#module\_memory\_db) | ../.. | n/a |
4444
| <a name="module_memory_db_disabled"></a> [memory\_db\_disabled](#module\_memory\_db\_disabled) | ../.. | n/a |
45-
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 4.0 |
45+
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 5.0 |
4646
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 6.0 |
4747

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

5556
## Inputs
5657

examples/complete/main.tf renamed to examples/redis/main.tf

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,40 @@ provider "aws" {
22
region = local.region
33
}
44

5+
data "aws_availability_zones" "available" {
6+
# Exclude local zones
7+
filter {
8+
name = "opt-in-status"
9+
values = ["opt-in-not-required"]
10+
}
11+
}
12+
513
locals {
6-
region = "us-east-1"
7-
name = "memorydb-ex-${replace(basename(path.cwd), "_", "-")}"
14+
region = "eu-west-1"
15+
name = "ex-${basename(path.cwd)}"
16+
17+
vpc_cidr = "10.0.0.0/16"
18+
azs = slice(data.aws_availability_zones.available.names, 0, 3)
819

920
tags = {
10-
Example = local.name
11-
Environment = "dev"
21+
Name = local.name
22+
Example = local.name
23+
Repository = "https://github.com/terraform-aws-modules/terraform-aws-memory-db"
1224
}
1325
}
1426

1527
################################################################################
1628
# MemoryDB Module
1729
################################################################################
1830

19-
module "memory_db_disabled" {
20-
source = "../.."
21-
22-
name = "${local.name}-disabled"
23-
create = false
24-
}
25-
2631
module "memory_db" {
2732
source = "../.."
2833

2934
# Cluster
3035
name = local.name
3136
description = "Example MemoryDB cluster"
3237

38+
engine = "redis"
3339
engine_version = "7.0"
3440
auto_minor_version_upgrade = true
3541
node_type = "db.r6gd.xlarge"
@@ -47,13 +53,13 @@ module "memory_db" {
4753
# Users
4854
users = {
4955
admin = {
50-
user_name = "admin-user"
56+
user_name = "redis-admin-user"
5157
access_string = "on ~* &* +@all"
5258
type = "iam"
5359
tags = { user = "admin" }
5460
}
5561
readonly = {
56-
user_name = "readonly-user"
62+
user_name = "redis-readonly-user"
5763
access_string = "on ~* &* -@all +@read"
5864
passwords = [random_password.password.result]
5965
tags = { user = "readonly" }
@@ -89,6 +95,13 @@ module "memory_db" {
8995
tags = local.tags
9096
}
9197

98+
module "memory_db_disabled" {
99+
source = "../.."
100+
101+
name = "${local.name}-disabled"
102+
create = false
103+
}
104+
92105
################################################################################
93106
# Supporting Resources
94107
################################################################################
@@ -98,11 +111,11 @@ module "vpc" {
98111
version = "~> 6.0"
99112

100113
name = local.name
101-
cidr = "10.99.0.0/18"
114+
cidr = local.vpc_cidr
102115

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

107120
create_database_subnet_group = true
108121
enable_nat_gateway = false
@@ -116,7 +129,7 @@ module "vpc" {
116129

117130
module "security_group" {
118131
source = "terraform-aws-modules/security-group/aws"
119-
version = "~> 4.0"
132+
version = "~> 5.0"
120133

121134
name = local.name
122135
description = "Security group for ${local.name}"
File renamed without changes.
File renamed without changes.
File renamed without changes.

examples/valkey/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Note that this example may create resources which will incur monetary charges on
4242
|------|--------|---------|
4343
| <a name="module_memory_db"></a> [memory\_db](#module\_memory\_db) | ../.. | n/a |
4444
| <a name="module_memory_db_disabled"></a> [memory\_db\_disabled](#module\_memory\_db\_disabled) | ../.. | n/a |
45-
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 4.0 |
45+
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 5.0 |
4646
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 6.0 |
4747

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

5556
## Inputs
5657

examples/valkey/main.tf

Lines changed: 31 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,32 @@ provider "aws" {
22
region = local.region
33
}
44

5+
data "aws_availability_zones" "available" {
6+
# Exclude local zones
7+
filter {
8+
name = "opt-in-status"
9+
values = ["opt-in-not-required"]
10+
}
11+
}
12+
513
locals {
6-
region = "us-east-1"
7-
name = "memorydb-ex-${replace(basename(path.cwd), "_", "-")}"
14+
region = "eu-west-1"
15+
name = "ex-${basename(path.cwd)}"
16+
17+
vpc_cidr = "10.0.0.0/16"
18+
azs = slice(data.aws_availability_zones.available.names, 0, 3)
819

920
tags = {
10-
Example = local.name
11-
Environment = "dev"
21+
Name = local.name
22+
Example = local.name
23+
Repository = "https://github.com/terraform-aws-modules/terraform-aws-memory-db"
1224
}
1325
}
1426

1527
################################################################################
1628
# MemoryDB Module
1729
################################################################################
1830

19-
module "memory_db_disabled" {
20-
source = "../.."
21-
22-
name = "${local.name}-disabled"
23-
create = false
24-
}
25-
2631
module "memory_db" {
2732
source = "../.."
2833

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

3338
engine = "valkey"
34-
engine_version = "7.2"
39+
engine_version = "7.3"
3540
auto_minor_version_upgrade = true
3641
node_type = "db.r6gd.xlarge"
3742
num_shards = 2
@@ -48,13 +53,13 @@ module "memory_db" {
4853
# Users
4954
users = {
5055
admin = {
51-
user_name = "admin-user"
56+
user_name = "valkey-admin-user"
5257
access_string = "on ~* &* +@all"
5358
type = "iam"
5459
tags = { user = "admin" }
5560
}
5661
readonly = {
57-
user_name = "readonly-user"
62+
user_name = "valkey-readonly-user"
5863
access_string = "on ~* &* -@all +@read"
5964
passwords = [random_password.password.result]
6065
tags = { user = "readonly" }
@@ -90,6 +95,13 @@ module "memory_db" {
9095
tags = local.tags
9196
}
9297

98+
module "memory_db_disabled" {
99+
source = "../.."
100+
101+
name = "${local.name}-disabled"
102+
create = false
103+
}
104+
93105
################################################################################
94106
# Supporting Resources
95107
################################################################################
@@ -99,11 +111,11 @@ module "vpc" {
99111
version = "~> 6.0"
100112

101113
name = local.name
102-
cidr = "10.98.0.0/18"
114+
cidr = local.vpc_cidr
103115

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

108120
create_database_subnet_group = true
109121
enable_nat_gateway = false
@@ -117,7 +129,7 @@ module "vpc" {
117129

118130
module "security_group" {
119131
source = "terraform-aws-modules/security-group/aws"
120-
version = "~> 4.0"
132+
version = "~> 5.0"
121133

122134
name = local.name
123135
description = "Security group for ${local.name}"

main.tf

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ locals {
1616
resource "aws_memorydb_cluster" "this" {
1717
count = var.create ? 1 : 0
1818

19+
region = var.region
20+
1921
name = var.use_name_prefix ? null : var.name
2022
name_prefix = var.use_name_prefix ? "${var.name}-" : null
2123
description = var.description
@@ -45,7 +47,6 @@ resource "aws_memorydb_cluster" "this" {
4547
snapshot_retention_limit = var.snapshot_retention_limit
4648
snapshot_window = var.snapshot_window
4749
final_snapshot_name = var.final_snapshot_name
48-
region = var.region
4950

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

61+
region = var.region
62+
6063
user_name = each.value.user_name
6164
access_string = each.value.access_string
62-
region = var.region
6365

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

81+
region = var.region
82+
7983
name = var.acl_use_name_prefix ? null : local.create_acl_name
8084
name_prefix = var.acl_use_name_prefix ? "${local.create_acl_name}-" : null
8185

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

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

102+
region = var.region
103+
99104
name = var.parameter_group_use_name_prefix ? null : local.create_parameter_group_name
100105
name_prefix = var.parameter_group_use_name_prefix ? "${local.create_parameter_group_name}-" : null
101106
description = var.parameter_group_description
102107
family = var.parameter_group_family
103-
region = var.region
104108

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

131+
region = var.region
132+
127133
name = var.subnet_group_use_name_prefix ? null : local.create_subnet_group_name
128134
name_prefix = var.subnet_group_use_name_prefix ? "${local.create_subnet_group_name}-" : null
129135
description = var.subnet_group_description
130136
subnet_ids = var.subnet_ids
131-
region = var.region
132137

133138
lifecycle {
134139
create_before_destroy = true

0 commit comments

Comments
 (0)