Skip to content

Commit ce820cc

Browse files
committed
multi region cluster
1 parent 42be407 commit ce820cc

File tree

17 files changed

+376
-9
lines changed

17 files changed

+376
-9
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ Examples codified under the [`examples`](https://github.com/terraform-aws-module
119119
| Name | Version |
120120
|------|---------|
121121
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
122-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.78 |
122+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.82 |
123123

124124
## Providers
125125

126126
| Name | Version |
127127
|------|---------|
128-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.78 |
128+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.82 |
129129

130130
## Modules
131131

@@ -162,6 +162,7 @@ No modules.
162162
| <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 |
163163
| <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 |
164164
| <a name="input_maintenance_window"></a> [maintenance\_window](#input\_maintenance\_window) | Specifies the weekly time range during which maintenance on the cluster is performed. It is specified as a range in the format `ddd:hh24:mi-ddd:hh24:mi` | `string` | `null` | no |
165+
| <a name="input_multi_region_cluster_name"></a> [multi\_region\_cluster\_name](#input\_multi\_region\_cluster\_name) | The multi region cluster identifier if part of a multi region cluster | `string` | `null` | no |
165166
| <a name="input_name"></a> [name](#input\_name) | Cluster name - also default name used on all resources if more specific resource names are not provided | `string` | `""` | no |
166167
| <a name="input_node_type"></a> [node\_type](#input\_node\_type) | The compute and memory capacity of the nodes in the cluster. See AWS documentation on [supported node types](https://docs.aws.amazon.com/memorydb/latest/devguide/nodes.supportedtypes.html) as well as [vertical scaling](https://docs.aws.amazon.com/memorydb/latest/devguide/cluster-vertical-scaling.html) | `string` | `null` | no |
167168
| <a name="input_num_replicas_per_shard"></a> [num\_replicas\_per\_shard](#input\_num\_replicas\_per\_shard) | The number of replicas to apply to each shard, up to a maximum of 5. Defaults to `1` (i.e. 2 nodes per shard) | `number` | `null` | no |

examples/complete/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ Note that this example may create resources which will incur monetary charges on
2626
| Name | Version |
2727
|------|---------|
2828
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
29-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.78 |
29+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.82 |
3030
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.0 |
3131

3232
## Providers
3333

3434
| Name | Version |
3535
|------|---------|
36-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.78 |
36+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.82 |
3737
| <a name="provider_random"></a> [random](#provider\_random) | >= 3.0 |
3838

3939
## Modules

examples/complete/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.78"
7+
version = ">= 5.82"
88
}
99
random = {
1010
source = "hashicorp/random"

examples/multi-region/main.tf

Lines changed: 240 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,240 @@
1+
provider "aws" {
2+
region = local.region
3+
}
4+
5+
provider "aws" {
6+
region = "us-west-2"
7+
alias = "us-west-2"
8+
}
9+
10+
locals {
11+
region = "us-east-1"
12+
name = "memorydb-ex-${replace(basename(path.cwd), "_", "-")}"
13+
14+
tags = {
15+
Example = local.name
16+
Environment = "dev"
17+
}
18+
}
19+
20+
################################################################################
21+
# MemoryDB Module
22+
################################################################################
23+
24+
module "memory_db_disabled" {
25+
source = "../.."
26+
27+
name = "${local.name}-disabled"
28+
create = false
29+
}
30+
31+
module "multi_region_cluster" {
32+
source = "../../modules/multi-region-cluster"
33+
34+
create = true
35+
multi_region_cluster_name_suffix = local.name
36+
tls_enabled = true
37+
engine = "valkey"
38+
engine_version = "7.3"
39+
node_type = "db.r7g.xlarge"
40+
num_shards = 2
41+
}
42+
43+
44+
module "memory_db" {
45+
source = "../.."
46+
47+
# Cluster
48+
name = local.name
49+
description = "Example MemoryDB cluster"
50+
51+
# This makes it part of the multi region cluster
52+
multi_region_cluster_name = module.multi_region_cluster.multi_region_cluster_name
53+
54+
# engine = "valkey"
55+
# engine_version = "7.3"
56+
auto_minor_version_upgrade = true
57+
node_type = "db.r7g.xlarge"
58+
num_shards = 2
59+
num_replicas_per_shard = 2
60+
61+
# tls_enabled = true
62+
security_group_ids = [module.security_group.security_group_id]
63+
maintenance_window = "sun:23:00-mon:01:30"
64+
snapshot_retention_limit = 7
65+
snapshot_window = "05:00-09:00"
66+
67+
# Users
68+
users = {
69+
admin = {
70+
user_name = "admin-user"
71+
access_string = "on ~* &* +@all"
72+
type = "iam"
73+
tags = { user = "admin" }
74+
}
75+
readonly = {
76+
user_name = "readonly-user"
77+
access_string = "on ~* &* -@all +@read"
78+
passwords = [random_password.password.result]
79+
tags = { user = "readonly" }
80+
}
81+
}
82+
83+
# ACL
84+
create_acl = false
85+
acl_name = "${local.name}-acl"
86+
acl_tags = { acl = "custom" }
87+
88+
# Parameter group
89+
create_parameter_group = false
90+
91+
# Subnet group
92+
subnet_group_name = "${local.name}-subnet-group"
93+
subnet_group_description = "Example MemoryDB subnet group"
94+
subnet_ids = module.vpc.database_subnets
95+
subnet_group_tags = {
96+
subnet_group = "custom"
97+
}
98+
99+
tags = local.tags
100+
}
101+
102+
module "secondary_memory_db" {
103+
source = "../.."
104+
105+
# Cluster
106+
name = "${local.name}-secondary"
107+
description = "Example MemoryDB cluster"
108+
109+
# This makes it part of the multi region cluster
110+
multi_region_cluster_name = module.multi_region_cluster.multi_region_cluster_name
111+
112+
# engine = "valkey"
113+
# engine_version = "7.3"
114+
auto_minor_version_upgrade = true
115+
node_type = "db.r7g.xlarge"
116+
num_shards = 2
117+
num_replicas_per_shard = 2
118+
119+
# tls_enabled = true
120+
security_group_ids = [module.secondary_security_group.security_group_id]
121+
maintenance_window = "sun:23:00-mon:01:30"
122+
snapshot_retention_limit = 7
123+
snapshot_window = "05:00-09:00"
124+
125+
# ACL
126+
create_acl = false
127+
acl_name = "${local.name}-acl"
128+
acl_tags = { acl = "custom" }
129+
130+
# Parameter group
131+
create_parameter_group = false
132+
133+
# Subnet group
134+
subnet_group_name = "${local.name}-subnet-group"
135+
subnet_group_description = "Example MemoryDB subnet group"
136+
subnet_ids = module.secondary_vpc.database_subnets
137+
subnet_group_tags = {
138+
subnet_group = "custom"
139+
}
140+
141+
tags = local.tags
142+
143+
providers = {
144+
aws = aws.us-west-2
145+
}
146+
}
147+
148+
################################################################################
149+
# Supporting Resources
150+
################################################################################
151+
152+
module "vpc" {
153+
source = "terraform-aws-modules/vpc/aws"
154+
version = "~> 5.0"
155+
156+
name = local.name
157+
cidr = "10.99.0.0/18"
158+
159+
azs = ["${local.region}a", "${local.region}b", "${local.region}d"] # Caution: check which zones are available
160+
private_subnets = ["10.99.0.0/24", "10.99.1.0/24", "10.99.2.0/24"]
161+
database_subnets = ["10.99.3.0/24", "10.99.4.0/24", "10.99.5.0/24"]
162+
163+
create_database_subnet_group = true
164+
enable_nat_gateway = false
165+
166+
manage_default_security_group = true
167+
default_security_group_ingress = []
168+
default_security_group_egress = []
169+
170+
tags = local.tags
171+
}
172+
173+
module "secondary_vpc" {
174+
source = "terraform-aws-modules/vpc/aws"
175+
version = "~> 5.0"
176+
177+
name = local.name
178+
cidr = "10.99.0.0/18"
179+
180+
azs = ["us-west-2a", "us-west-2b", "us-west-2d"] # Caution: check which zones are available
181+
private_subnets = ["10.99.0.0/24", "10.99.1.0/24", "10.99.2.0/24"]
182+
database_subnets = ["10.99.3.0/24", "10.99.4.0/24", "10.99.5.0/24"]
183+
184+
create_database_subnet_group = true
185+
enable_nat_gateway = false
186+
187+
manage_default_security_group = true
188+
default_security_group_ingress = []
189+
default_security_group_egress = []
190+
191+
tags = local.tags
192+
193+
providers = {
194+
aws = aws.us-west-2
195+
}
196+
}
197+
198+
module "security_group" {
199+
source = "terraform-aws-modules/security-group/aws"
200+
version = "~> 4.0"
201+
202+
name = local.name
203+
description = "Security group for ${local.name}"
204+
vpc_id = module.vpc.vpc_id
205+
206+
ingress_cidr_blocks = module.vpc.private_subnets_cidr_blocks
207+
ingress_rules = ["redis-tcp"]
208+
209+
egress_cidr_blocks = [module.vpc.vpc_cidr_block]
210+
egress_rules = ["all-all"]
211+
212+
tags = local.tags
213+
}
214+
215+
module "secondary_security_group" {
216+
source = "terraform-aws-modules/security-group/aws"
217+
version = "~> 4.0"
218+
219+
name = local.name
220+
description = "Security group for ${local.name}"
221+
vpc_id = module.secondary_vpc.vpc_id
222+
223+
ingress_cidr_blocks = module.secondary_vpc.private_subnets_cidr_blocks
224+
ingress_rules = ["redis-tcp"]
225+
226+
egress_cidr_blocks = [module.secondary_vpc.vpc_cidr_block]
227+
egress_rules = ["all-all"]
228+
229+
tags = local.tags
230+
231+
providers = {
232+
aws = aws.us-west-2
233+
}
234+
}
235+
236+
resource "random_password" "password" {
237+
length = 16
238+
special = true
239+
override_special = "_%@"
240+
}

examples/multi-region/outputs.tf

Whitespace-only changes.

examples/multi-region/variables.tf

Whitespace-only changes.

examples/multi-region/versions.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
terraform {
2+
required_version = ">= 1.0"
3+
4+
required_providers {
5+
aws = {
6+
source = "hashicorp/aws"
7+
version = ">= 5.82"
8+
}
9+
random = {
10+
source = "hashicorp/random"
11+
version = ">= 3.0"
12+
}
13+
}
14+
}

examples/valkey/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,14 @@ Note that this example may create resources which will incur monetary charges on
2626
| Name | Version |
2727
|------|---------|
2828
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
29-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.78 |
29+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.82 |
3030
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.0 |
3131

3232
## Providers
3333

3434
| Name | Version |
3535
|------|---------|
36-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.78 |
36+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.82 |
3737
| <a name="provider_random"></a> [random](#provider\_random) | >= 3.0 |
3838

3939
## Modules

examples/valkey/versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.78"
7+
version = ">= 5.82"
88
}
99
random = {
1010
source = "hashicorp/random"

main.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ resource "aws_memorydb_cluster" "this" {
2929
num_replicas_per_shard = var.num_replicas_per_shard
3030
parameter_group_name = local.parameter_group_name
3131
data_tiering = var.data_tiering
32+
multi_region_cluster_name = var.multi_region_cluster_name
3233

3334
acl_name = local.acl_name
3435
kms_key_arn = var.kms_key_arn

0 commit comments

Comments
 (0)