generated from clowdhaus/terraform-aws-module-template
-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: initial release of Terraform AWS MemoryDB module 🎉
- Loading branch information
1 parent
66fcd53
commit c1a0698
Showing
11 changed files
with
949 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
# Terraform <TODO> examples | ||
# Terraform AWS MemoryDB examples | ||
|
||
- [Complete](./complete) | ||
- [Complete](https://github.com/clowdhaus/terraform-aws-memory-db/tree/main/examples/complete) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,146 @@ | ||
locals {} | ||
provider "aws" { | ||
region = local.region | ||
} | ||
|
||
locals { | ||
region = "us-east-1" | ||
name = "memorydb-ex-${replace(basename(path.cwd), "_", "-")}" | ||
|
||
tags = { | ||
Example = local.name | ||
Environment = "dev" | ||
} | ||
} | ||
|
||
################################################################################ | ||
# Supporting Resources | ||
################################################################################ | ||
|
||
module "vpc" { | ||
source = "terraform-aws-modules/vpc/aws" | ||
version = "~> 3.0" | ||
|
||
name = local.name | ||
cidr = "10.99.0.0/18" | ||
|
||
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"] | ||
|
||
create_database_subnet_group = true | ||
enable_nat_gateway = false | ||
|
||
manage_default_security_group = true | ||
default_security_group_ingress = [] | ||
default_security_group_egress = [] | ||
|
||
tags = local.tags | ||
} | ||
|
||
module "security_group" { | ||
source = "terraform-aws-modules/security-group/aws" | ||
version = "~> 4.0" | ||
|
||
name = local.name | ||
description = "Security group for ${local.name}" | ||
vpc_id = module.vpc.vpc_id | ||
|
||
ingress_cidr_blocks = module.vpc.private_subnets_cidr_blocks | ||
ingress_rules = ["redis-tcp"] | ||
|
||
egress_cidr_blocks = [module.vpc.vpc_cidr_block] | ||
egress_rules = ["all-all"] | ||
|
||
tags = local.tags | ||
} | ||
|
||
resource "aws_sns_topic" "example" { | ||
name = local.name | ||
kms_master_key_id = "alias/aws/sns" | ||
|
||
tags = local.tags | ||
} | ||
|
||
resource "random_password" "password" { | ||
for_each = toset(["admin", "readonly"]) | ||
|
||
length = 16 | ||
special = true | ||
override_special = "_%@" | ||
} | ||
|
||
################################################################################ | ||
# 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_version = "6.2" | ||
auto_minor_version_upgrade = true | ||
node_type = "db.t4g.small" | ||
num_shards = 2 | ||
num_replicas_per_shard = 2 | ||
|
||
tls_enabled = true | ||
security_group_ids = [module.security_group.security_group_id] | ||
maintenance_window = "sun:23:00-mon:01:30" | ||
sns_topic_arn = aws_sns_topic.example.arn | ||
snapshot_retention_limit = 7 | ||
snapshot_window = "05:00-09:00" | ||
|
||
# Users | ||
users = { | ||
admin = { | ||
user_name = "admin-user" | ||
access_string = "on ~* &* +@all" | ||
passwords = [random_password.password["admin"].result] | ||
tags = { user = "admin" } | ||
} | ||
readonly = { | ||
user_name = "readonly-user" | ||
access_string = "on ~* &* -@all +@read" | ||
passwords = [random_password.password["readonly"].result] | ||
tags = { user = "readonly" } | ||
} | ||
} | ||
|
||
# ACL | ||
acl_name = "${local.name}-acl" | ||
acl_tags = { acl = "custom" } | ||
|
||
# Parameter group | ||
parameter_group_name = "${local.name}-param-group" | ||
parameter_group_description = "Example MemoryDB parameter group" | ||
parameter_group_family = "memorydb_redis6" | ||
parameter_group_parameters = [ | ||
{ | ||
name = "activedefrag" | ||
value = "yes" | ||
} | ||
] | ||
parameter_group_tags = { | ||
parameter_group = "custom" | ||
} | ||
|
||
# Subnet group | ||
subnet_group_name = "${local.name}-subnet-group" | ||
subnet_group_description = "Example MemoryDB subnet group" | ||
subnet_ids = module.vpc.database_subnets | ||
subnet_group_tags = { | ||
subnet_group = "custom" | ||
} | ||
|
||
tags = local.tags | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
################################################################################ | ||
# Cluster | ||
################################################################################ | ||
|
||
output "cluster_id" { | ||
description = "Cluster name" | ||
value = module.memory_db.cluster_id | ||
} | ||
|
||
output "cluster_arn" { | ||
description = "The ARN of the cluster" | ||
value = module.memory_db.cluster_arn | ||
} | ||
|
||
output "cluster_endpoint_address" { | ||
description = "DNS hostname of the cluster configuration endpoint" | ||
value = module.memory_db.cluster_endpoint_address | ||
} | ||
|
||
output "cluster_endpoint_port" { | ||
description = "Port number that the cluster configuration endpoint is listening on" | ||
value = module.memory_db.cluster_endpoint_port | ||
} | ||
|
||
output "cluster_engine_patch_version" { | ||
description = "Patch version number of the Redis engine used by the cluster" | ||
value = module.memory_db.cluster_engine_patch_version | ||
} | ||
|
||
output "cluster_shards" { | ||
description = "Set of shards in this cluster" | ||
value = module.memory_db.cluster_shards | ||
} | ||
|
||
################################################################################ | ||
# User(s) | ||
################################################################################ | ||
|
||
output "users" { | ||
description = "Map of attributes for the users created" | ||
value = module.memory_db.users | ||
sensitive = true | ||
} | ||
|
||
################################################################################ | ||
# ACL | ||
################################################################################ | ||
|
||
output "acl_id" { | ||
description = "Name of the ACL" | ||
value = module.memory_db.acl_id | ||
} | ||
|
||
output "acl_arn" { | ||
description = "The ARN of the ACL" | ||
value = module.memory_db.acl_arn | ||
} | ||
|
||
output "acl_minimum_engine_version" { | ||
description = "The minimum engine version supported by the ACL" | ||
value = module.memory_db.acl_minimum_engine_version | ||
} | ||
|
||
################################################################################ | ||
# Parameter Group | ||
################################################################################ | ||
|
||
output "parameter_group_id" { | ||
description = "Name of the parameter group" | ||
value = module.memory_db.parameter_group_id | ||
} | ||
|
||
output "parameter_group_arn" { | ||
description = "The ARN of the parameter group" | ||
value = module.memory_db.parameter_group_arn | ||
} | ||
|
||
################################################################################ | ||
# Subnet Group | ||
################################################################################ | ||
|
||
output "subnet_group_id" { | ||
description = "Name of the subnet group" | ||
value = module.memory_db.subnet_group_id | ||
} | ||
|
||
output "subnet_group_arn" { | ||
description = "ARN of the subnet group" | ||
value = module.memory_db.subnet_group_arn | ||
} | ||
|
||
output "subnet_group_vpc_id" { | ||
description = "The VPC in which the subnet group exists" | ||
value = module.memory_db.subnet_group_vpc_id | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.