generated from clowdhaus/terraform-aws-module-template
-
-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Support Multi Region Cluster Name argument #12
Merged
bryantbiggs
merged 5 commits into
terraform-aws-modules:master
from
magreenbaum:feat/multi_region_cluster
Jan 7, 2025
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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 |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# Multi Region cluster | ||
|
||
Configuration in this directory creates: | ||
|
||
- AWS Multi-Regional MemoryDB cluster | ||
- AWS MemoryDB cluster | ||
- AWS MemoryDB users | ||
- AWS MemoryDB ACL | ||
- AWS MemoryDB subnet group | ||
|
||
<!-- BEGIN_TF_DOCS --> | ||
## Requirements | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 | | ||
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.82 | | ||
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.0 | | ||
|
||
## Providers | ||
|
||
| Name | Version | | ||
|------|---------| | ||
| <a name="provider_random"></a> [random](#provider\_random) | >= 3.0 | | ||
|
||
## Modules | ||
|
||
| Name | Source | Version | | ||
|------|--------|---------| | ||
| <a name="module_memory_db"></a> [memory\_db](#module\_memory\_db) | ../.. | n/a | | ||
| <a name="module_memory_db_disabled"></a> [memory\_db\_disabled](#module\_memory\_db\_disabled) | ../.. | n/a | | ||
| <a name="module_multi_region_cluster"></a> [multi\_region\_cluster](#module\_multi\_region\_cluster) | ../../modules/multi-region-cluster | n/a | | ||
| <a name="module_security_group"></a> [security\_group](#module\_security\_group) | terraform-aws-modules/security-group/aws | ~> 4.0 | | ||
| <a name="module_vpc"></a> [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 5.0 | | ||
|
||
## Resources | ||
|
||
| Name | Type | | ||
|------|------| | ||
| [random_password.password](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/password) | resource | | ||
|
||
## Inputs | ||
|
||
No inputs. | ||
|
||
## Outputs | ||
|
||
| Name | Description | | ||
|------|-------------| | ||
| <a name="output_acl_arn"></a> [acl\_arn](#output\_acl\_arn) | The ARN of the ACL | | ||
| <a name="output_acl_id"></a> [acl\_id](#output\_acl\_id) | Name of the ACL | | ||
| <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 | | ||
| <a name="output_cluster_arn"></a> [cluster\_arn](#output\_cluster\_arn) | The ARN of the cluster | | ||
| <a name="output_cluster_endpoint_address"></a> [cluster\_endpoint\_address](#output\_cluster\_endpoint\_address) | DNS hostname of the cluster configuration endpoint | | ||
| <a name="output_cluster_endpoint_port"></a> [cluster\_endpoint\_port](#output\_cluster\_endpoint\_port) | Port number that the cluster configuration endpoint is listening on | | ||
| <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 | | ||
| <a name="output_cluster_id"></a> [cluster\_id](#output\_cluster\_id) | Cluster name | | ||
| <a name="output_cluster_shards"></a> [cluster\_shards](#output\_cluster\_shards) | Set of shards in this cluster | | ||
| <a name="output_multi_region_cluster_arn"></a> [multi\_region\_cluster\_arn](#output\_multi\_region\_cluster\_arn) | The ARN of the multi-region cluster | | ||
| <a name="output_multi_region_cluster_name"></a> [multi\_region\_cluster\_name](#output\_multi\_region\_cluster\_name) | The name of the multi-region cluster | | ||
| <a name="output_parameter_group_arn"></a> [parameter\_group\_arn](#output\_parameter\_group\_arn) | The ARN of the parameter group | | ||
| <a name="output_parameter_group_id"></a> [parameter\_group\_id](#output\_parameter\_group\_id) | Name of the parameter group | | ||
| <a name="output_subnet_group_arn"></a> [subnet\_group\_arn](#output\_subnet\_group\_arn) | ARN of the subnet group | | ||
| <a name="output_subnet_group_id"></a> [subnet\_group\_id](#output\_subnet\_group\_id) | Name of the subnet group | | ||
| <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 | | ||
| <a name="output_users"></a> [users](#output\_users) | Map of attributes for the users created | | ||
<!-- END_TF_DOCS --> |
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,237 @@ | ||
provider "aws" { | ||
region = local.region | ||
} | ||
|
||
locals { | ||
region = "us-east-1" | ||
name = "memorydb-ex-${replace(basename(path.cwd), "_", "-")}" | ||
|
||
tags = { | ||
Example = local.name | ||
Environment = "dev" | ||
} | ||
} | ||
|
||
################################################################################ | ||
# Multi Region MemoryDB Module | ||
################################################################################ | ||
|
||
module "memory_db_disabled" { | ||
source = "../.." | ||
|
||
name = "${local.name}-disabled" | ||
create = false | ||
} | ||
|
||
module "multi_region_cluster" { | ||
source = "../../modules/multi-region-cluster" | ||
|
||
create = true | ||
multi_region_cluster_name_suffix = local.name | ||
tls_enabled = true | ||
engine = "valkey" | ||
engine_version = "7.3" | ||
node_type = "db.r7g.xlarge" | ||
num_shards = 2 | ||
} | ||
|
||
module "memory_db" { | ||
source = "../.." | ||
|
||
# Cluster | ||
name = local.name | ||
description = "Example MemoryDB cluster" | ||
|
||
# This makes it part of the multi region cluster | ||
multi_region_cluster_name = module.multi_region_cluster.multi_region_cluster_name | ||
|
||
auto_minor_version_upgrade = true | ||
node_type = "db.r7g.xlarge" | ||
num_shards = 2 | ||
num_replicas_per_shard = 2 | ||
|
||
security_group_ids = [module.security_group.security_group_id] | ||
maintenance_window = "sun:23:00-mon:01:30" | ||
snapshot_retention_limit = 7 | ||
snapshot_window = "05:00-09:00" | ||
|
||
# Users | ||
users = { | ||
admin = { | ||
user_name = "admin-user" | ||
access_string = "on ~* &* +@all" | ||
type = "iam" | ||
tags = { user = "admin" } | ||
} | ||
readonly = { | ||
user_name = "readonly-user" | ||
access_string = "on ~* &* -@all +@read" | ||
passwords = [random_password.password.result] | ||
tags = { user = "readonly" } | ||
} | ||
} | ||
|
||
# ACL | ||
create_acl = true | ||
acl_name = "${local.name}-acl" | ||
acl_tags = { acl = "custom" } | ||
|
||
# Parameter group | ||
create_parameter_group = false | ||
|
||
# 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 | ||
} | ||
|
||
# Provides example of an additional region cluster that is part of the multi-region cluster | ||
# Note: Deleting a cluster with existing clusters in other regions can take up to several hours | ||
# It places the multi-region clusters into an updating state which is not valid for deletion | ||
|
||
#provider "aws" { | ||
# region = "us-west-2" | ||
# alias = "us-west-2" | ||
#} | ||
|
||
#module "secondary_memory_db" { | ||
# source = "../.." | ||
# | ||
# # Cluster | ||
# name = "${local.name}-secondary" | ||
# description = "Example MemoryDB cluster" | ||
# | ||
# # This makes it part of the multi region cluster | ||
# multi_region_cluster_name = module.multi_region_cluster.multi_region_cluster_name | ||
# | ||
# auto_minor_version_upgrade = true | ||
# node_type = "db.r7g.xlarge" | ||
# num_shards = 2 | ||
# num_replicas_per_shard = 2 | ||
# | ||
# security_group_ids = [module.secondary_security_group.security_group_id] | ||
# maintenance_window = "sun:23:00-mon:01:30" | ||
# snapshot_retention_limit = 7 | ||
# snapshot_window = "05:00-09:00" | ||
# | ||
# # ACL | ||
# create_acl = true | ||
# acl_name = "${local.name}-acl" | ||
# acl_tags = { acl = "custom" } | ||
# | ||
# # Parameter group | ||
# create_parameter_group = false | ||
# | ||
# # Subnet group | ||
# subnet_group_name = "${local.name}-subnet-group" | ||
# subnet_group_description = "Example MemoryDB subnet group" | ||
# subnet_ids = module.secondary_vpc.database_subnets | ||
# subnet_group_tags = { | ||
# subnet_group = "custom" | ||
# } | ||
# | ||
# tags = local.tags | ||
# | ||
# providers = { | ||
# aws = aws.us-west-2 | ||
# } | ||
#} | ||
|
||
################################################################################ | ||
# Supporting Resources | ||
################################################################################ | ||
|
||
module "vpc" { | ||
source = "terraform-aws-modules/vpc/aws" | ||
version = "~> 5.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 "random_password" "password" { | ||
length = 16 | ||
special = true | ||
override_special = "_%@" | ||
} | ||
|
||
#module "secondary_vpc" { | ||
# source = "terraform-aws-modules/vpc/aws" | ||
# version = "~> 5.0" | ||
# | ||
# name = local.name | ||
# cidr = "10.99.0.0/18" | ||
# | ||
# azs = ["us-west-2a", "us-west-2b", "us-west-2d"] # 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 | ||
# | ||
# providers = { | ||
# aws = aws.us-west-2 | ||
# } | ||
#} | ||
# | ||
#module "secondary_security_group" { | ||
# source = "terraform-aws-modules/security-group/aws" | ||
# version = "~> 4.0" | ||
# | ||
# name = local.name | ||
# description = "Security group for ${local.name}" | ||
# vpc_id = module.secondary_vpc.vpc_id | ||
# | ||
# ingress_cidr_blocks = module.secondary_vpc.private_subnets_cidr_blocks | ||
# ingress_rules = ["redis-tcp"] | ||
# | ||
# egress_cidr_blocks = [module.secondary_vpc.vpc_cidr_block] | ||
# egress_rules = ["all-all"] | ||
# | ||
# tags = local.tags | ||
# | ||
# providers = { | ||
# aws = aws.us-west-2 | ||
# } | ||
#} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lets leave out this example for now as well