diff --git a/infrastructure/modules/elasticache-redis/README.md b/infrastructure/modules/elasticache-redis/README.md new file mode 100644 index 00000000..51282225 --- /dev/null +++ b/infrastructure/modules/elasticache-redis/README.md @@ -0,0 +1,159 @@ +# ElastiCache Redis/Valkey + +NHS Screening wrapper around the community +[`terraform-aws-modules/elasticache/aws`](https://registry.terraform.io/modules/terraform-aws-modules/elasticache/aws/latest) +module for ElastiCache replication groups. It consumes the shared `context.tf` for +naming and tagging, keeps the interface close to upstream, and adds a few +defaults that are useful for the platform. + + + +## What this module does + +* Provisions a Valkey or Redis OSS replication group using the upstream ElastiCache module. +* Creates a subnet group and parameter group by default. +* Security groups must be created externally (e.g. using the `security-group` module) and passed via `security_group_ids`. +* Derives `replication_group_id` from the shared context when you do not set it. +* Defaults new deployments to `engine = "valkey"`. +* Derives `parameter_group_family` from `engine` and `engine_version` when possible. +* Enforces encryption at rest and in transit (cannot be overridden). +* Rejects Redis OSS major versions 4 and 5 so new callers do not encode an EOL engine choice. +* Sends slow logs to CloudWatch Logs by default unless you override + `log_delivery_configuration`. + +## Important boundary + +This wrapper can provision a Valkey-backed ElastiCache replication group, but it does not prove +application compatibility. If an existing connector or client library is tightly coupled to older +Redis OSS behaviour, that compatibility check still needs to happen in the consuming service. + +## Usage + +### Minimal Valkey replication group + +```hcl +module "redis" { + source = "git::https://github.com/NHSDigital/screening-terraform-modules-aws.git//infrastructure/modules/elasticache-redis?ref=main" + + service = "bcss" + project = "screening" + environment = "dev" + name = "redis" + + engine = "valkey" + node_type = "cache.t4g.small" + engine_version = "7.2" + auth_token = "replace-with-a-secret-value" + + vpc_id = module.vpc.vpc_id + subnet_ids = module.vpc.private_subnets + + security_group_rules = { + ingress_vpc = { + description = "VPC traffic" + cidr_ipv4 = module.vpc.vpc_cidr_block + } + } +} +``` + +### Highly available non-clustered Valkey + +```hcl +module "redis" { + source = "git::https://github.com/NHSDigital/screening-terraform-modules-aws.git//infrastructure/modules/elasticache-redis?ref=main" + + service = "bcss" + project = "screening" + environment = "prod" + name = "redis" + + engine = "valkey" + node_type = "cache.r7g.large" + engine_version = "7.2" + auth_token = "replace-with-a-secret-value" + num_cache_clusters = 2 + automatic_failover_enabled = true + multi_az_enabled = true + maintenance_window = "sun:05:00-sun:09:00" + snapshot_retention_limit = 7 + notification_topic_arn = module.alerts.topic_arn + + vpc_id = module.vpc.vpc_id + subnet_ids = module.vpc.private_subnets + + security_group_rules = { + ingress_app = { + description = "Application traffic" + referenced_security_group_id = module.app.security_group_id + } + } +} +``` + +### Cluster mode Valkey + +```hcl +module "redis" { + source = "git::https://github.com/NHSDigital/screening-terraform-modules-aws.git//infrastructure/modules/elasticache-redis?ref=main" + + service = "bcss" + project = "screening" + environment = "prod" + name = "redis-cluster" + + engine = "valkey" + node_type = "cache.r7g.large" + engine_version = "7.2" + auth_token = "replace-with-a-secret-value" + cluster_mode_enabled = true + num_node_groups = 2 + replicas_per_node_group = 1 + automatic_failover_enabled = true + multi_az_enabled = true + + vpc_id = module.vpc.vpc_id + subnet_ids = module.vpc.private_subnets + + security_group_rules = { + ingress_vpc = { + description = "VPC traffic" + cidr_ipv4 = module.vpc.vpc_cidr_block + } + } +} +``` + +### Redis OSS compatibility mode + +If a caller cannot move to Valkey yet, set `engine = "redis"` explicitly and use a supported +engine version such as `6.x` or `7.x`. + + + +## Conventions + +* `replication_group_id`, `subnet_group_name`, `parameter_group_name`, and + `security_group_name` default to the shared context-derived module ID. +* `parameter_group_family` defaults from the selected `engine` and the major + `engine_version`, for example `7.2` becomes `valkey7` when `engine = "valkey"`. +* `redis_auth_token` and `elasticache_port` are supported as compatibility + aliases for older callers, but new callers should prefer `auth_token` and + `port`. +* The module exposes both upstream-style outputs and compatibility aliases for + the old bespoke module outputs. + +## What this module does NOT do + +* Create user groups or Redis users. Use the upstream user-group submodule if + you need Redis ACL management. +* Create a KMS key. Pass an existing key arn through `kms_key_arn`. +* Manage global replication groups or serverless caches. Those are different + deployment patterns and should be wrapped separately if needed. + + + + + + + diff --git a/infrastructure/modules/elasticache-redis/context.tf b/infrastructure/modules/elasticache-redis/context.tf new file mode 100644 index 00000000..2bcb41d9 --- /dev/null +++ b/infrastructure/modules/elasticache-redis/context.tf @@ -0,0 +1,370 @@ +# +# ONLY EDIT THIS FILE IN github.com/NHSDigital/screening-terraform-modules-aws/infrastructure/modules/tags +# All other instances of this file should be a copy of that one +# +# +# Copy this file from https://github.com/NHSDigital/screening-terraform-modules-aws/blob/master/infrastructure/modules/tags/exports/context.tf +# and then place it in your Terraform module to automatically get +# tag module standard configuration inputs suitable for passing +# to other modules. +# +# curl -sL https://raw.githubusercontent.com/NHSDigital/screening-terraform-modules-aws/master/infrastructure/modules/tags/exports/context.tf -o context.tf +# +# Modules should access the whole context as `module.this.context` +# to get the input variables with nulls for defaults, +# for example `context = module.this.context`, +# and access individual variables as `module.this.`, +# with final values filled in. +# +# For example, when using defaults, `module.this.context.delimiter` +# will be null, and `module.this.delimiter` will be `-` (hyphen). +# + +module "this" { + source = "git::https://github.com/NHSDigital/screening-terraform-modules-aws.git//infrastructure/modules/tags?ref=v2.5.0" + + service = var.service + project = var.project + region = var.region + environment = var.environment + stack = var.stack + workspace = var.workspace + name = var.name + delimiter = var.delimiter + attributes = var.attributes + tags = var.tags + additional_tag_map = var.additional_tag_map + label_order = var.label_order + regex_replace_chars = var.regex_replace_chars + id_length_limit = var.id_length_limit + label_key_case = var.label_key_case + label_value_case = var.label_value_case + terraform_source = coalesce(var.terraform_source, path.module) + descriptor_formats = var.descriptor_formats + labels_as_tags = var.labels_as_tags + + context = var.context +} + +# Copy contents of screening-terraform-modules-aws/tags/variables.tf here +# tflint-ignore: terraform_unused_declarations +variable "aws_region" { + type = string + description = "The AWS region" + default = "eu-west-2" + validation { + condition = contains(["eu-west-1", "eu-west-2", "us-east-1"], var.aws_region) + error_message = "AWS Region must be one of eu-west-1, eu-west-2, us-east-1" + } +} + +variable "context" { + type = any + default = { + enabled = true + service = null + project = null + region = null + environment = null + stack = null + workspace = null + name = null + delimiter = null + attributes = [] + tags = {} + additional_tag_map = {} + regex_replace_chars = null + label_order = [] + id_length_limit = null + label_key_case = null + label_value_case = null + terraform_source = null + descriptor_formats = {} + labels_as_tags = ["unset"] + } + description = <<-EOT + Single object for setting entire context at once. + See description of individual variables for details. + Leave string and numeric variables as `null` to use default value. + Individual variable settings (non-null) override settings in context object, + except for attributes, tags, and additional_tag_map, which are merged. + EOT + + validation { + condition = lookup(var.context, "label_key_case", null) == null ? true : contains(["lower", "title", "upper"], var.context["label_key_case"]) + error_message = "Allowed values: `lower`, `title`, `upper`." + } + + validation { + condition = lookup(var.context, "label_value_case", null) == null ? true : contains(["lower", "title", "upper", "none"], var.context["label_value_case"]) + error_message = "Allowed values: `lower`, `title`, `upper`, `none`." + } +} + +variable "terraform_source" { + type = string + default = null + description = "Source location to record in the Terraform_source tag. Defaults to the caller module path when not set." +} + +variable "enabled" { + type = bool + default = null + description = "Set to false to prevent the module from creating any resources" +} + +variable "service" { + type = string + default = null + description = "ID element. Usually an abbreviation of your service directorate name, e.g. 'bcss' or 'csms', to help ensure generated IDs are globally unique" +} + +variable "region" { + type = string + default = null + description = "ID element _(Rarely used, not included by default)_. Usually an abbreviation of the selected AWS region e.g. 'uw2', 'ew2' or 'gbl' for resources like IAM roles that have no region" +} + +variable "project" { + type = string + default = null + description = "ID element. A project identifier, indicating the name or role of the project the resource is for, such as `website` or `api`" +} + +variable "stack" { + type = string + default = null + description = "ID element. The name of the stack/component, e.g. `database`, `web`, `waf`, `eks`" +} + +variable "workspace" { + type = string + default = null + description = "ID element. The Terraform workspace, to help ensure generated IDs are unique across workspaces" +} + +variable "environment" { + type = string + default = null + description = "ID element. Usually used to indicate role, e.g. 'prd', 'dev', 'test', 'preprod', 'prod', 'uat'" +} + +variable "name" { + type = string + default = null + description = <<-EOT + ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'. + This is the only ID element not also included as a `tag`. + The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. + EOT +} + +variable "delimiter" { + type = string + default = null + description = <<-EOT + Delimiter to be used between ID elements. + Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. + EOT +} + +variable "attributes" { + type = list(string) + default = [] + description = <<-EOT + ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`, + in the order they appear in the list. New attributes are appended to the + end of the list. The elements of the list are joined by the `delimiter` + and treated as a single ID element. + EOT +} + +variable "labels_as_tags" { + type = set(string) + default = ["default"] + description = <<-EOT + Set of labels (ID elements) to include as tags in the `tags` output. + Default is to include all labels. + Tags with empty values will not be included in the `tags` output. + Set to `[]` to suppress all generated tags. + **Notes:** + The value of the `name` tag, if included, will be the `id`, not the `name`. + Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be + changed in later chained modules. Attempts to change it will be silently ignored. + EOT +} + +variable "tags" { + type = map(string) + default = {} + description = <<-EOT + Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`). + Neither the tag keys nor the tag values will be modified by this module. + EOT +} + +variable "additional_tag_map" { + type = map(string) + default = {} + description = <<-EOT + Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`. + This is for some rare cases where resources want additional configuration of tags + and therefore take a list of maps with tag key, value, and additional configuration. + EOT +} + +variable "label_order" { + type = list(string) + default = null + description = <<-EOT + The order in which the labels (ID elements) appear in the `id`. + Defaults to ["namespace", "environment", "stage", "name", "attributes"]. + You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. + EOT +} + +variable "regex_replace_chars" { + type = string + default = null + description = <<-EOT + Terraform regular expression (regex) string. + Characters matching the regex will be removed from the ID elements. + If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. + EOT +} + +variable "id_length_limit" { + type = number + default = null + description = <<-EOT + Limit `id` to this many characters (minimum 6). + Set to `0` for unlimited length. + Set to `null` for keep the existing setting, which defaults to `0`. + Does not affect `id_full`. + EOT + validation { + condition = var.id_length_limit == null ? true : var.id_length_limit >= 6 || var.id_length_limit == 0 + error_message = "The id_length_limit must be >= 6 if supplied (not null), or 0 for unlimited length." + } +} + +variable "label_key_case" { + type = string + default = null + description = <<-EOT + Controls the letter case of the `tags` keys (label names) for tags generated by this module. + Does not affect keys of tags passed in via the `tags` input. + Possible values: `lower`, `title`, `upper`. + Default value: `title`. + EOT + + validation { + condition = var.label_key_case == null ? true : contains(["lower", "title", "upper"], var.label_key_case) + error_message = "Allowed values: `lower`, `title`, `upper`." + } +} + +variable "label_value_case" { + type = string + default = null + description = <<-EOT + Controls the letter case of ID elements (labels) as included in `id`, + set as tag values, and output by this module individually. + Does not affect values of tags passed in via the `tags` input. + Possible values: `lower`, `title`, `upper` and `none` (no transformation). + Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs. + Default value: `lower`. + EOT + + validation { + condition = var.label_value_case == null ? true : contains(["lower", "title", "upper", "none"], var.label_value_case) + error_message = "Allowed values: `lower`, `title`, `upper`, `none`." + } +} + +variable "descriptor_formats" { + type = any + default = {} + description = <<-EOT + Describe additional descriptors to be output in the `descriptors` output map. + Map of maps. Keys are names of descriptors. Values are maps of the form + `{ + format = string + labels = list(string) + }` + (Type is `any` so the map values can later be enhanced to provide additional options.) + `format` is a Terraform format string to be passed to the `format()` function. + `labels` is a list of labels, in order, to pass to `format()` function. + Label values will be normalized before being passed to `format()` so they will be + identical to how they appear in `id`. + Default is `{}` (`descriptors` output will be empty). + EOT +} + +variable "owner" { + type = string + description = "The name and or NHS.net email address of the service owner" + default = "None" +} + +variable "tag_version" { + type = string + description = "Used to identify the tagging version in use" + default = "1.0" +} + +variable "data_classification" { + type = string + description = "Used to identify the data classification of the resource, e.g 1-5" + default = "n/a" + validation { + condition = contains(["n/a", "1", "2", "3", "4", "5"], var.data_classification) + error_message = "Data Classification must be \"n/a\" or between 1-5" + } +} + +variable "data_type" { + type = string + description = "The tag data_type" + default = "None" + validation { + condition = contains(["None", "PCD", "PID", "Anonymised", "UserAccount", "Audit"], var.data_type) + error_message = "Data Type must be one of None, PCD, PID, Anonymised, UserAccount, Audit" + } +} + +variable "public_facing" { + type = bool + description = "Whether this resource is public facing" + default = false +} + +variable "service_category" { + type = string + description = "The tag service_category" + default = "n/a" + validation { + condition = contains(["n/a", "Bronze", "Silver", "Gold", "Platinum"], var.service_category) + error_message = "The Service Category must be one of n/a, Bronze, Silver, Gold, Platinum" + } +} + +variable "on_off_pattern" { + type = string + description = "Used to turn resources on and off based on a time pattern" + default = "n/a" +} + +variable "application_role" { + type = string + description = "The role the application is performing" + default = "General" +} + +variable "tool" { + type = string + description = "The tool used to deploy the resource" + default = "Terraform" +} + +#### End of copy of screening-terraform-modules-aws/tags/variables.tf diff --git a/infrastructure/modules/elasticache-redis/main.tf b/infrastructure/modules/elasticache-redis/main.tf new file mode 100644 index 00000000..2d099ac4 --- /dev/null +++ b/infrastructure/modules/elasticache-redis/main.tf @@ -0,0 +1,97 @@ +# ---------------------------------------------------------------------------- +# Elasticache Redis / Valkey replication group +# +# Wraps terraform-aws-modules/elasticache/aws v1.11.0. +# +# Fixed controls (not exposed as variables): +# - at_rest_encryption_enabled = true (encryption at rest is mandatory) +# - transit_encryption_enabled = true (encryption in transit is mandatory) +# - create_cluster = false (always replication group, not standalone) +# - create_replication_group = true +# - create_security_group = false (SGs managed externally via security-group module) +# ---------------------------------------------------------------------------- + +locals { + replication_group_id = substr(coalesce(var.replication_group_id, module.this.id), 0, 40) + + engine_version_major = try(regex("^\\d+", var.engine_version), null) + + parameter_group_family = coalesce( + var.parameter_group_family, + local.engine_version_major != null ? "${var.engine}${local.engine_version_major}" : null + ) + + log_delivery_configuration = length(var.log_delivery_configuration) > 0 ? var.log_delivery_configuration : { + slow-log = { + destination_type = "cloudwatch-logs" + log_format = "json" + } + } +} + +module "elasticache" { + source = "terraform-aws-modules/elasticache/aws" + version = "1.11.0" + + create = module.this.enabled + create_cluster = false + create_replication_group = true + + # Engine + engine = var.engine + engine_version = var.engine_version + replication_group_id = local.replication_group_id + description = coalesce(var.description, "${local.replication_group_id} ${title(var.engine)} replication group") + + # Instance sizing + node_type = var.node_type + port = var.port + + # Encryption (fixed controls) + at_rest_encryption_enabled = true + transit_encryption_enabled = true + transit_encryption_mode = var.transit_encryption_mode + auth_token = var.auth_token + kms_key_arn = var.kms_key_arn + + # Cluster topology + cluster_mode = var.cluster_mode + num_cache_clusters = var.num_cache_clusters + num_node_groups = var.num_node_groups + replicas_per_node_group = var.replicas_per_node_group + + # Availability + automatic_failover_enabled = var.automatic_failover_enabled + multi_az_enabled = var.multi_az_enabled + apply_immediately = var.apply_immediately + auto_minor_version_upgrade = var.auto_minor_version_upgrade + maintenance_window = var.maintenance_window + + # Networking (SGs managed externally) + create_security_group = false + security_group_ids = var.security_group_ids + + # Subnet group (managed by this module) + create_subnet_group = true + subnet_group_name = coalesce(var.subnet_group_name, local.replication_group_id) + subnet_group_description = var.subnet_group_description + subnet_ids = var.subnet_ids + + # Parameter group + create_parameter_group = var.create_parameter_group + parameter_group_family = coalesce(local.parameter_group_family, "") + parameter_group_name = coalesce(var.parameter_group_name, local.replication_group_id) + parameter_group_description = var.parameter_group_description + parameters = var.parameters + + # Logging + log_delivery_configuration = local.log_delivery_configuration + notification_topic_arn = var.notification_topic_arn + + # Snapshots + snapshot_retention_limit = var.snapshot_retention_limit + snapshot_window = var.snapshot_window + final_snapshot_identifier = var.final_snapshot_identifier + + tags = module.this.tags +} diff --git a/infrastructure/modules/elasticache-redis/outputs.tf b/infrastructure/modules/elasticache-redis/outputs.tf new file mode 100644 index 00000000..7d0bd411 --- /dev/null +++ b/infrastructure/modules/elasticache-redis/outputs.tf @@ -0,0 +1,45 @@ +# Replication group + +output "replication_group_arn" { + description = "ARN of the ElastiCache replication group" + value = module.elasticache.replication_group_arn +} + +output "replication_group_id" { + description = "ID of the ElastiCache replication group" + value = module.elasticache.replication_group_id +} + +output "replication_group_configuration_endpoint_address" { + description = "Configuration endpoint address (cluster mode enabled)" + value = module.elasticache.replication_group_configuration_endpoint_address +} + +output "replication_group_primary_endpoint_address" { + description = "Primary endpoint address (cluster mode disabled)" + value = module.elasticache.replication_group_primary_endpoint_address +} + +output "replication_group_reader_endpoint_address" { + description = "Reader endpoint address (cluster mode disabled)" + value = module.elasticache.replication_group_reader_endpoint_address +} + +output "replication_group_port" { + description = "Port of the replication group" + value = module.elasticache.replication_group_port +} + +# Parameter group + +output "parameter_group_id" { + description = "Name of the ElastiCache parameter group" + value = module.elasticache.parameter_group_id +} + +# Subnet group + +output "subnet_group_name" { + description = "Name of the ElastiCache subnet group" + value = module.elasticache.subnet_group_name +} diff --git a/infrastructure/modules/elasticache-redis/variables.tf b/infrastructure/modules/elasticache-redis/variables.tf new file mode 100644 index 00000000..1e3dccaa --- /dev/null +++ b/infrastructure/modules/elasticache-redis/variables.tf @@ -0,0 +1,244 @@ +# ---------------------------------------------------------------------------- +# Engine +# ---------------------------------------------------------------------------- + +variable "engine" { + description = "Cache engine. Valid values are redis and valkey" + type = string + default = "valkey" + + validation { + condition = contains(["redis", "valkey"], var.engine) + error_message = "engine must be either redis or valkey." + } +} + +variable "engine_version" { + description = "Engine version (e.g. '7.1'). Major version is used to derive parameter_group_family when not set explicitly" + type = string + + validation { + condition = !can(regex("^[45](\\.|$)", var.engine_version)) + error_message = "Redis OSS major versions 4 and 5 are out of standard support. Use Valkey or Redis OSS 6+." + } +} + +# ---------------------------------------------------------------------------- +# Instance identity +# ---------------------------------------------------------------------------- + +variable "replication_group_id" { + description = "Explicit replication group identifier. Defaults to module.this.id from context" + type = string + default = null +} + +variable "description" { + description = "Description for the replication group" + type = string + default = null +} + +# ---------------------------------------------------------------------------- +# Instance sizing +# ---------------------------------------------------------------------------- + +variable "node_type" { + description = "The instance class for cache nodes (e.g. 'cache.t3.micro', 'cache.r6g.large')" + type = string +} + +variable "port" { + description = "Port on which the cache accepts connections" + type = number + default = 6379 +} + +# ---------------------------------------------------------------------------- +# Encryption and authentication +# ---------------------------------------------------------------------------- + +variable "auth_token" { + description = "Auth token for Redis/Valkey AUTH. Transit encryption is always enabled in this module" + type = string + default = null + sensitive = true +} + +variable "transit_encryption_mode" { + description = "Setting to enable clients to migrate to in-transit encryption without downtime. Valid values: preferred, required" + type = string + default = null +} + +variable "kms_key_arn" { + description = "ARN of the KMS key for encryption at rest. If omitted, the default ElastiCache key is used" + type = string + default = null +} + +# ---------------------------------------------------------------------------- +# Cluster topology +# ---------------------------------------------------------------------------- + +variable "cluster_mode" { + description = "Cluster mode setting. Valid values: enabled, disabled, compatible" + type = string + default = null +} + +variable "num_cache_clusters" { + description = "Number of cache clusters when cluster mode is disabled" + type = number + default = null +} + +variable "num_node_groups" { + description = "Number of node groups (shards) when cluster mode is enabled" + type = number + default = null +} + +variable "replicas_per_node_group" { + description = "Number of replica nodes per node group when cluster mode is enabled" + type = number + default = null +} + +# ---------------------------------------------------------------------------- +# Availability +# ---------------------------------------------------------------------------- + +variable "automatic_failover_enabled" { + description = "Whether a read replica is promoted automatically if the primary fails" + type = bool + default = null +} + +variable "multi_az_enabled" { + description = "Whether to enable Multi-AZ for the replication group" + type = bool + default = false +} + +variable "apply_immediately" { + description = "Whether modifications are applied immediately or during the next maintenance window" + type = bool + default = false +} + +variable "auto_minor_version_upgrade" { + description = "Whether minor engine upgrades are applied automatically during the maintenance window" + type = bool + default = null +} + +variable "maintenance_window" { + description = "Weekly maintenance window in UTC (e.g. 'Mon:00:00-Mon:03:00')" + type = string + default = null +} + +# ---------------------------------------------------------------------------- +# Networking +# ---------------------------------------------------------------------------- + +variable "security_group_ids" { + description = "List of security group IDs to associate with the replication group. Create SGs externally using the security-group module" + type = list(string) + default = [] +} + +variable "subnet_ids" { + description = "List of private subnet IDs for the subnet group" + type = list(string) + + validation { + condition = length(var.subnet_ids) > 0 + error_message = "subnet_ids must contain at least one subnet." + } +} + +variable "subnet_group_name" { + description = "Explicit subnet group name. Defaults to the replication group ID" + type = string + default = null +} + +variable "subnet_group_description" { + description = "Description for the subnet group" + type = string + default = null +} + +# ---------------------------------------------------------------------------- +# Parameter group +# ---------------------------------------------------------------------------- + +variable "create_parameter_group" { + description = "Whether to create a parameter group" + type = bool + default = true +} + +variable "parameter_group_name" { + description = "Explicit parameter group name. Defaults to the replication group ID" + type = string + default = null +} + +variable "parameter_group_family" { + description = "Parameter group family. When omitted, derived from engine + major engine_version (e.g. 'valkey7', 'redis7')" + type = string + default = null +} + +variable "parameter_group_description" { + description = "Description for the parameter group" + type = string + default = null +} + +variable "parameters" { + description = "List of parameter name/value maps for the parameter group" + type = list(map(string)) + default = [] +} + +# ---------------------------------------------------------------------------- +# Logging +# ---------------------------------------------------------------------------- + +variable "log_delivery_configuration" { + description = "Log delivery configuration. Defaults to slow-log via CloudWatch Logs when empty" + type = any + default = {} +} + +variable "notification_topic_arn" { + description = "ARN of an SNS topic to receive ElastiCache notifications" + type = string + default = null +} + +# ---------------------------------------------------------------------------- +# Snapshots +# ---------------------------------------------------------------------------- + +variable "snapshot_retention_limit" { + description = "Number of days to retain automatic snapshots. 0 disables backups" + type = number + default = null +} + +variable "snapshot_window" { + description = "Daily UTC time range for automatic snapshots (e.g. '05:00-09:00')" + type = string + default = null +} + +variable "final_snapshot_identifier" { + description = "Final snapshot identifier when the replication group is destroyed" + type = string + default = null +} diff --git a/infrastructure/modules/elasticache-redis/versions.tf b/infrastructure/modules/elasticache-redis/versions.tf new file mode 100644 index 00000000..cb30fe5c --- /dev/null +++ b/infrastructure/modules/elasticache-redis/versions.tf @@ -0,0 +1,10 @@ +terraform { + required_version = ">= 1.13" + + required_providers { + aws = { + source = "hashicorp/aws" + version = ">= 6.42" + } + } +}