# elasticache

Creates an ElastiCache Redis replication group or Memcached cluster with at-rest and in-transit encryption.

Provisions either a Redis replication group (with Multi-AZ, automatic failover, TLS, AUTH token, KMS encryption, and snapshot retention) or a Memcached cluster, with a custom parameter group and subnet group. Redis is the default engine.

## Usage

```hcl
module "redis" {
  source  = "hcassc.jfrog.io/iac-terraform-modules-virtual/database/elasticache/aws"
  version = "0.1.0"

  cluster_id         = "prod-redis"
  subnet_ids         = module.vpc.isolated_subnet_id_list
  security_group_ids = [module.security_groups.ids["redis"]]
  kms_key_id         = module.kms.key_arn
  auth_token         = random_password.redis_auth.result
}
```

<!-- BEGIN_TF_DOCS — DO NOT EDIT BELOW THIS LINE -->
## Requirements

| Name | Version |
| ---- | ------- |
| <a name="requirement_terraform"></a> [terraform](#requirement_terraform) | ~> 1.5 |
| <a name="requirement_aws"></a> [aws](#requirement_aws) | ~> 6.50 |

## Providers

| Name | Version |
| ---- | ------- |
| <a name="provider_aws"></a> [aws](#provider_aws) | 6.50.0 |

## Resources

| Name | Type |
| ---- | ---- |
| [aws_elasticache_cluster.memcached](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_cluster) | resource |
| [aws_elasticache_parameter_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_parameter_group) | resource |
| [aws_elasticache_replication_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_replication_group) | resource |
| [aws_elasticache_subnet_group.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/elasticache_subnet_group) | resource |

## Inputs

| Name | Description | Type | Default | Required |
| ---- | ----------- | ---- | ------- | :------: |
| <a name="input_cluster_id"></a> [cluster_id](#input_cluster_id) | Replication group ID | `string` | n/a | yes |
| <a name="input_security_group_ids"></a> [security_group_ids](#input_security_group_ids) | Security group IDs | `list(string)` | n/a | yes |
| <a name="input_at_rest_encryption_enabled"></a> [at_rest_encryption_enabled](#input_at_rest_encryption_enabled) | Enable at-rest encryption | `bool` | `true` | no |
| <a name="input_auth_token"></a> [auth_token](#input_auth_token) | Redis AUTH token (required when transit_encryption_enabled = true) | `string` | `null` | no |
| <a name="input_automatic_failover_enabled"></a> [automatic_failover_enabled](#input_automatic_failover_enabled) | Enable Redis automatic failover (requires num_cache_clusters >= 2) | `bool` | `true` | no |
| <a name="input_engine"></a> [engine](#input_engine) | Cache engine — redis or memcached | `string` | `"redis"` | no |
| <a name="input_engine_version"></a> [engine_version](#input_engine_version) | Cache engine version | `string` | `"7.1"` | no |
| <a name="input_kms_key_id"></a> [kms_key_id](#input_kms_key_id) | KMS key ARN for at-rest encryption | `string` | `null` | no |
| <a name="input_maintenance_window"></a> [maintenance_window](#input_maintenance_window) | Weekly maintenance window | `string` | `"sun:05:00-sun:06:00"` | no |
| <a name="input_multi_az_enabled"></a> [multi_az_enabled](#input_multi_az_enabled) | Enable Multi-AZ for the replication group | `bool` | `true` | no |
| <a name="input_node_type"></a> [node_type](#input_node_type) | ElastiCache node type | `string` | `"cache.t3.medium"` | no |
| <a name="input_num_cache_clusters"></a> [num_cache_clusters](#input_num_cache_clusters) | Number of Redis replica clusters | `number` | `2` | no |
| <a name="input_num_cache_nodes"></a> [num_cache_nodes](#input_num_cache_nodes) | Number of cache nodes (Memcached) or number of node groups (Redis cluster mode disabled = 1) | `number` | `1` | no |
| <a name="input_parameters"></a> [parameters](#input_parameters) | Map of cache parameter names to values | `map(string)` | `{}` | no |
| <a name="input_snapshot_retention_limit"></a> [snapshot_retention_limit](#input_snapshot_retention_limit) | Days to retain Redis snapshots (0 disables) | `number` | `7` | no |
| <a name="input_snapshot_window"></a> [snapshot_window](#input_snapshot_window) | Daily snapshot window (UTC) | `string` | `"03:00-04:00"` | no |
| <a name="input_subnet_group_name"></a> [subnet_group_name](#input_subnet_group_name) | ElastiCache subnet group name (created when subnet_ids is non-empty) | `string` | `null` | no |
| <a name="input_subnet_ids"></a> [subnet_ids](#input_subnet_ids) | Subnet IDs for the subnet group | `list(string)` | `[]` | no |
| <a name="input_tags"></a> [tags](#input_tags) | Resource tags to apply to all resources | `map(string)` | `{}` | no |
| <a name="input_transit_encryption_enabled"></a> [transit_encryption_enabled](#input_transit_encryption_enabled) | Enable in-transit TLS encryption | `bool` | `true` | no |

## Outputs

| Name | Description |
| ---- | ----------- |
| <a name="output_memcached_configuration_endpoint"></a> [memcached_configuration_endpoint](#output_memcached_configuration_endpoint) | Memcached configuration endpoint |
| <a name="output_memcached_id"></a> [memcached_id](#output_memcached_id) | Memcached cluster ID (null for Redis) |
| <a name="output_redis_arn"></a> [redis_arn](#output_redis_arn) | Redis replication group ARN |
| <a name="output_redis_id"></a> [redis_id](#output_redis_id) | Redis replication group ID (null for Memcached) |
| <a name="output_redis_primary_endpoint"></a> [redis_primary_endpoint](#output_redis_primary_endpoint) | Redis primary endpoint address |
| <a name="output_redis_reader_endpoint"></a> [redis_reader_endpoint](#output_redis_reader_endpoint) | Redis reader endpoint address |
<!-- END_TF_DOCS — DO NOT EDIT ABOVE THIS LINE -->
