Skip to content

Commit c1a0698

Browse files
committed
feat: initial release of Terraform AWS MemoryDB module 🎉
1 parent 66fcd53 commit c1a0698

File tree

11 files changed

+949
-28
lines changed

11 files changed

+949
-28
lines changed

.github/workflows/semantic-releaser.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,4 @@ jobs:
3333
@semantic-release/git@10.0.0
3434
conventional-changelog-conventionalcommits@4.6.3
3535
env:
36-
GITHUB_TOKEN: ${{ secrets.ACCESS_TOKEN }}
36+
GITHUB_TOKEN: ${{ secrets.SEMANTIC_RELEASE }}

README.md

Lines changed: 168 additions & 13 deletions
Large diffs are not rendered by default.

examples/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
# Terraform <TODO> examples
1+
# Terraform AWS MemoryDB examples
22

3-
- [Complete](./complete)
3+
- [Complete](https://github.com/clowdhaus/terraform-aws-memory-db/tree/main/examples/complete)

examples/complete/README.md

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
1-
# Complete <TODO> Example
1+
# Complete AWS MemoryDB Example
22

33
Configuration in this directory creates:
44

5-
- <TODO>
5+
- AWS MemoryDB cluster
6+
- AWS MemoryDB users
7+
- AWS MemoryDB ACL
8+
- AWS MemoryDB subnet group
9+
- AWS MemoryDB parameter group
610

711
## Usage
812

@@ -22,27 +26,55 @@ Note that this example may create resources which will incur monetary charges on
2226
| Name | Version |
2327
|------|---------|
2428
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13.1 |
25-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.30 |
29+
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.71 |
30+
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.0 |
2631

2732
## Providers
2833

29-
No providers.
34+
| Name | Version |
35+
|------|---------|
36+
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.71 |
37+
| <a name="provider_random"></a> [random](#provider\_random) | >= 3.0 |
3038

3139
## Modules
3240

33-
No modules.
41+
| Name | Source | Version |
42+
|------|--------|---------|
43+
| <a name="module_memory_db"></a> [memory\_db](#module\_memory\_db) | ../.. | n/a |
44+
| <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 |
46+
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 3.0 |
3447

3548
## Resources
3649

37-
No resources.
50+
| Name | Type |
51+
|------|------|
52+
| [aws_sns_topic.example](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic) | resource |
53+
| [random_password.password](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource |
3854

3955
## Inputs
4056

4157
No inputs.
4258

4359
## Outputs
4460

45-
No outputs.
61+
| Name | Description |
62+
|------|-------------|
63+
| <a name="output_acl_arn"></a> [acl\_arn](#output\_acl\_arn) | The ARN of the ACL |
64+
| <a name="output_acl_id"></a> [acl\_id](#output\_acl\_id) | Name of the ACL |
65+
| <a name="output_acl_minimum_engine_version"></a> [acl\_minimum\_engine\_version](#output\_acl\_minimum\_engine\_version) | The minimum engine version supported by the ACL |
66+
| <a name="output_cluster_arn"></a> [cluster\_arn](#output\_cluster\_arn) | The ARN of the cluster |
67+
| <a name="output_cluster_endpoint_address"></a> [cluster\_endpoint\_address](#output\_cluster\_endpoint\_address) | DNS hostname of the cluster configuration endpoint |
68+
| <a name="output_cluster_endpoint_port"></a> [cluster\_endpoint\_port](#output\_cluster\_endpoint\_port) | Port number that the cluster configuration endpoint is listening on |
69+
| <a name="output_cluster_engine_patch_version"></a> [cluster\_engine\_patch\_version](#output\_cluster\_engine\_patch\_version) | Patch version number of the Redis engine used by the cluster |
70+
| <a name="output_cluster_id"></a> [cluster\_id](#output\_cluster\_id) | Cluster name |
71+
| <a name="output_cluster_shards"></a> [cluster\_shards](#output\_cluster\_shards) | Set of shards in this cluster |
72+
| <a name="output_parameter_group_arn"></a> [parameter\_group\_arn](#output\_parameter\_group\_arn) | The ARN of the parameter group |
73+
| <a name="output_parameter_group_id"></a> [parameter\_group\_id](#output\_parameter\_group\_id) | Name of the parameter group |
74+
| <a name="output_subnet_group_arn"></a> [subnet\_group\_arn](#output\_subnet\_group\_arn) | ARN of the subnet group |
75+
| <a name="output_subnet_group_id"></a> [subnet\_group\_id](#output\_subnet\_group\_id) | Name of the subnet group |
76+
| <a name="output_subnet_group_vpc_id"></a> [subnet\_group\_vpc\_id](#output\_subnet\_group\_vpc\_id) | The VPC in which the subnet group exists |
77+
| <a name="output_users"></a> [users](#output\_users) | Map of attributes for the users created |
4678
<!-- END OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
4779

48-
Apache-2.0 Licensed. See [LICENSE](../../LICENSE).
80+
Apache-2.0 Licensed. See [LICENSE](https://github.com/clowdhaus/terraform-aws-memory-db/blob/main/LICENSE).

examples/complete/main.tf

Lines changed: 146 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,146 @@
1-
locals {}
1+
provider "aws" {
2+
region = local.region
3+
}
4+
5+
locals {
6+
region = "us-east-1"
7+
name = "memorydb-ex-${replace(basename(path.cwd), "_", "-")}"
8+
9+
tags = {
10+
Example = local.name
11+
Environment = "dev"
12+
}
13+
}
14+
15+
################################################################################
16+
# Supporting Resources
17+
################################################################################
18+
19+
module "vpc" {
20+
source = "terraform-aws-modules/vpc/aws"
21+
version = "~> 3.0"
22+
23+
name = local.name
24+
cidr = "10.99.0.0/18"
25+
26+
azs = ["${local.region}a", "${local.region}b", "${local.region}d"] # Caution: check which zones are available
27+
private_subnets = ["10.99.0.0/24", "10.99.1.0/24", "10.99.2.0/24"]
28+
database_subnets = ["10.99.3.0/24", "10.99.4.0/24", "10.99.5.0/24"]
29+
30+
create_database_subnet_group = true
31+
enable_nat_gateway = false
32+
33+
manage_default_security_group = true
34+
default_security_group_ingress = []
35+
default_security_group_egress = []
36+
37+
tags = local.tags
38+
}
39+
40+
module "security_group" {
41+
source = "terraform-aws-modules/security-group/aws"
42+
version = "~> 4.0"
43+
44+
name = local.name
45+
description = "Security group for ${local.name}"
46+
vpc_id = module.vpc.vpc_id
47+
48+
ingress_cidr_blocks = module.vpc.private_subnets_cidr_blocks
49+
ingress_rules = ["redis-tcp"]
50+
51+
egress_cidr_blocks = [module.vpc.vpc_cidr_block]
52+
egress_rules = ["all-all"]
53+
54+
tags = local.tags
55+
}
56+
57+
resource "aws_sns_topic" "example" {
58+
name = local.name
59+
kms_master_key_id = "alias/aws/sns"
60+
61+
tags = local.tags
62+
}
63+
64+
resource "random_password" "password" {
65+
for_each = toset(["admin", "readonly"])
66+
67+
length = 16
68+
special = true
69+
override_special = "_%@"
70+
}
71+
72+
################################################################################
73+
# MemoryDB Module
74+
################################################################################
75+
76+
module "memory_db_disabled" {
77+
source = "../.."
78+
79+
name = "${local.name}-disabled"
80+
create = false
81+
}
82+
83+
module "memory_db" {
84+
source = "../.."
85+
86+
# Cluster
87+
name = local.name
88+
description = "Example MemoryDB cluster"
89+
90+
engine_version = "6.2"
91+
auto_minor_version_upgrade = true
92+
node_type = "db.t4g.small"
93+
num_shards = 2
94+
num_replicas_per_shard = 2
95+
96+
tls_enabled = true
97+
security_group_ids = [module.security_group.security_group_id]
98+
maintenance_window = "sun:23:00-mon:01:30"
99+
sns_topic_arn = aws_sns_topic.example.arn
100+
snapshot_retention_limit = 7
101+
snapshot_window = "05:00-09:00"
102+
103+
# Users
104+
users = {
105+
admin = {
106+
user_name = "admin-user"
107+
access_string = "on ~* &* +@all"
108+
passwords = [random_password.password["admin"].result]
109+
tags = { user = "admin" }
110+
}
111+
readonly = {
112+
user_name = "readonly-user"
113+
access_string = "on ~* &* -@all +@read"
114+
passwords = [random_password.password["readonly"].result]
115+
tags = { user = "readonly" }
116+
}
117+
}
118+
119+
# ACL
120+
acl_name = "${local.name}-acl"
121+
acl_tags = { acl = "custom" }
122+
123+
# Parameter group
124+
parameter_group_name = "${local.name}-param-group"
125+
parameter_group_description = "Example MemoryDB parameter group"
126+
parameter_group_family = "memorydb_redis6"
127+
parameter_group_parameters = [
128+
{
129+
name = "activedefrag"
130+
value = "yes"
131+
}
132+
]
133+
parameter_group_tags = {
134+
parameter_group = "custom"
135+
}
136+
137+
# Subnet group
138+
subnet_group_name = "${local.name}-subnet-group"
139+
subnet_group_description = "Example MemoryDB subnet group"
140+
subnet_ids = module.vpc.database_subnets
141+
subnet_group_tags = {
142+
subnet_group = "custom"
143+
}
144+
145+
tags = local.tags
146+
}

examples/complete/outputs.tf

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
################################################################################
2+
# Cluster
3+
################################################################################
4+
5+
output "cluster_id" {
6+
description = "Cluster name"
7+
value = module.memory_db.cluster_id
8+
}
9+
10+
output "cluster_arn" {
11+
description = "The ARN of the cluster"
12+
value = module.memory_db.cluster_arn
13+
}
14+
15+
output "cluster_endpoint_address" {
16+
description = "DNS hostname of the cluster configuration endpoint"
17+
value = module.memory_db.cluster_endpoint_address
18+
}
19+
20+
output "cluster_endpoint_port" {
21+
description = "Port number that the cluster configuration endpoint is listening on"
22+
value = module.memory_db.cluster_endpoint_port
23+
}
24+
25+
output "cluster_engine_patch_version" {
26+
description = "Patch version number of the Redis engine used by the cluster"
27+
value = module.memory_db.cluster_engine_patch_version
28+
}
29+
30+
output "cluster_shards" {
31+
description = "Set of shards in this cluster"
32+
value = module.memory_db.cluster_shards
33+
}
34+
35+
################################################################################
36+
# User(s)
37+
################################################################################
38+
39+
output "users" {
40+
description = "Map of attributes for the users created"
41+
value = module.memory_db.users
42+
sensitive = true
43+
}
44+
45+
################################################################################
46+
# ACL
47+
################################################################################
48+
49+
output "acl_id" {
50+
description = "Name of the ACL"
51+
value = module.memory_db.acl_id
52+
}
53+
54+
output "acl_arn" {
55+
description = "The ARN of the ACL"
56+
value = module.memory_db.acl_arn
57+
}
58+
59+
output "acl_minimum_engine_version" {
60+
description = "The minimum engine version supported by the ACL"
61+
value = module.memory_db.acl_minimum_engine_version
62+
}
63+
64+
################################################################################
65+
# Parameter Group
66+
################################################################################
67+
68+
output "parameter_group_id" {
69+
description = "Name of the parameter group"
70+
value = module.memory_db.parameter_group_id
71+
}
72+
73+
output "parameter_group_arn" {
74+
description = "The ARN of the parameter group"
75+
value = module.memory_db.parameter_group_arn
76+
}
77+
78+
################################################################################
79+
# Subnet Group
80+
################################################################################
81+
82+
output "subnet_group_id" {
83+
description = "Name of the subnet group"
84+
value = module.memory_db.subnet_group_id
85+
}
86+
87+
output "subnet_group_arn" {
88+
description = "ARN of the subnet group"
89+
value = module.memory_db.subnet_group_arn
90+
}
91+
92+
output "subnet_group_vpc_id" {
93+
description = "The VPC in which the subnet group exists"
94+
value = module.memory_db.subnet_group_vpc_id
95+
}

examples/complete/versions.tf

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,12 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 3.30"
7+
version = ">= 3.71"
88
}
9+
random = {
10+
source = "hashicorp/random"
11+
version = ">= 3.0"
12+
}
13+
914
}
1015
}

0 commit comments

Comments
 (0)