Skip to content
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 engine argument and valkey #10

Merged
merged 1 commit into from
Nov 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,20 +111,21 @@ module "memory_db" {
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!

- [Complete](https://github.com/terraform-aws-modules/terraform-aws-memory-db/tree/master/examples/complete)
- [Valkey](https://github.com/terraform-aws-modules/terraform-aws-memory-db/tree/master/examples/valkey)

<!-- 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.47 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.78 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.47 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.78 |

## Modules

Expand Down Expand Up @@ -156,7 +157,8 @@ No modules.
| <a name="input_create_users"></a> [create\_users](#input\_create\_users) | Determines whether to create users specified | `bool` | `true` | no |
| <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 |
| <a name="input_description"></a> [description](#input\_description) | Description for the cluster. Defaults to `Managed by Terraform` | `string` | `null` | no |
| <a name="input_engine_version"></a> [engine\_version](#input\_engine\_version) | Version number of the Redis engine to be used for the cluster. Downgrades are not supported | `string` | `null` | no |
| <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 |
| <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 |
| <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 |
| <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 |
| <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 |
Expand Down
4 changes: 2 additions & 2 deletions examples/complete/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ Note that this example may create resources which will incur monetary charges on
| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 1.0 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.47 |
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 5.78 |
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.47 |
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.78 |
| <a name="provider_random"></a> [random](#provider\_random) | >= 3.0 |

## Modules
Expand Down
2 changes: 1 addition & 1 deletion examples/complete/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ terraform {
required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.47"
version = ">= 5.78"
}
random = {
source = "hashicorp/random"
Expand Down
80 changes: 80 additions & 0 deletions examples/valkey/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Valkey AWS MemoryDB Example

Configuration in this directory creates:

- AWS MemoryDB cluster
- AWS MemoryDB users
- AWS MemoryDB ACL
- AWS MemoryDB subnet group
- AWS MemoryDB parameter group

## Usage

To run this example you need to execute:

```bash
$ terraform init
$ terraform plan
$ terraform apply
```

Note that this example may create resources which will incur monetary charges on your AWS bill. Run `terraform destroy` when you no longer need these resources.

<!-- 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.78 |
| <a name="requirement_random"></a> [random](#requirement\_random) | >= 3.0 |

## Providers

| Name | Version |
|------|---------|
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 5.78 |
| <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_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 |
|------|------|
| [aws_sns_topic.example](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/sns_topic) | resource |
| [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_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 -->

Apache-2.0 Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-aws-memory-db/blob/master/LICENSE).
146 changes: 146 additions & 0 deletions examples/valkey/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
provider "aws" {
region = local.region
}

locals {
region = "us-east-1"
name = "memorydb-ex-${replace(basename(path.cwd), "_", "-")}"

tags = {
Example = local.name
Environment = "dev"
}
}

################################################################################
# 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 = "valkey"
engine_version = "7.2"
auto_minor_version_upgrade = true
node_type = "db.r6gd.xlarge"
num_shards = 2
num_replicas_per_shard = 2
data_tiering = true

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"
type = "iam"
tags = { user = "admin" }
}
readonly = {
user_name = "readonly-user"
access_string = "on ~* &* -@all +@read"
passwords = [random_password.password.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 Valkey MemoryDB parameter group"
parameter_group_family = "memorydb_valkey7"
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 Valkey MemoryDB subnet group"
subnet_ids = module.vpc.database_subnets
subnet_group_tags = {
subnet_group = "custom"
}

tags = local.tags
}

################################################################################
# Supporting Resources
################################################################################

module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "~> 5.0"

name = local.name
cidr = "10.98.0.0/18"

azs = ["${local.region}a", "${local.region}b", "${local.region}d"] # Caution: check which zones are available
private_subnets = ["10.98.0.0/24", "10.98.1.0/24", "10.98.2.0/24"]
database_subnets = ["10.98.3.0/24", "10.98.4.0/24", "10.98.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" {
length = 16
special = true
override_special = "_%@"
}
95 changes: 95 additions & 0 deletions examples/valkey/outputs.tf
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
}
Empty file added examples/valkey/variables.tf
Empty file.
15 changes: 15 additions & 0 deletions examples/valkey/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
terraform {
required_version = ">= 1.0"

required_providers {
aws = {
source = "hashicorp/aws"
version = ">= 5.78"
}
random = {
source = "hashicorp/random"
version = ">= 3.0"
}

}
}
Loading