Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
94fc158
change version
manoj-me Oct 18, 2023
8a88f6a
change version
manoj-me Oct 18, 2023
117173b
cahnge to old version
manoj-me Oct 18, 2023
5914066
change the version
manoj-me Oct 20, 2023
2480d09
change version
manoj-me Oct 20, 2023
d8d09c5
change aws version
manoj-me Oct 23, 2023
e2f448d
add jakarta regions
manoj-me Oct 24, 2023
244b299
fix bucket ownership
manoj-me Oct 24, 2023
1740378
change to latest bucket
manoj-me Oct 24, 2023
14bb5ba
change to latest bucket
manoj-me Oct 24, 2023
3300048
change to latest bucket
manoj-me Oct 24, 2023
a8680df
change to latest bucket
manoj-me Oct 24, 2023
88fe0d3
remove acl
manoj-me Oct 24, 2023
18d7b12
change policy
manoj-me Oct 24, 2023
519d1dd
add version to redis
manoj-me Oct 24, 2023
af3b7c1
[SRE-8756] added valkey
tanmayatmoe Jun 4, 2025
422c1df
[SRE-8756] added valkey
tanmayatmoe Jun 4, 2025
1615a32
[SRE-8756] valkey main tf fixes
tanmayatmoe Jun 4, 2025
db8710f
[SRE-8756] fix
tanmayatmoe Jun 4, 2025
c3960e1
[SRE-8756] added cluster_mode var
tanmayatmoe Jun 4, 2025
c46b10e
Merge pull request #83 from moengage/SRE-8756
tanmayatmoe Jun 4, 2025
97b44e2
Update main.tf
manoj-me Jul 2, 2025
0e1a392
Update main.tf
manoj-me Jul 2, 2025
8f35546
Update variables.tf
manoj-me Jul 2, 2025
1df18f5
Update main.tf
manoj-me Jul 2, 2025
14ccfea
Update variables.tf
manoj-me Jul 2, 2025
5ab52b8
Update main.tf
arnold1796 Jul 17, 2025
a563098
Merge pull request #84 from moengage/arnold1796-patch-1
atish-andhare Jul 17, 2025
f831e23
Update main.tf
tanmayatmoe Jul 22, 2025
c5dc98b
Update variables.tf
tanmayatmoe Jul 22, 2025
5a356c7
Update variables.tf
atish-andhare Jul 22, 2025
156e059
Update variables.tf
manoj-me Jul 22, 2025
c15c60f
Update main.tf
manoj-me Jul 22, 2025
1178af7
Update variables.tf
manoj-me Jul 22, 2025
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
5 changes: 3 additions & 2 deletions elasticache/redis/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ resource "aws_elasticache_replication_group" "redis" {
node_type = var.redis_node_type
automatic_failover_enabled = var.automatic_failover_enabled && var.cluster_mode_enabled ? true : false
auto_minor_version_upgrade = var.auto_minor_version_upgrade
availability_zones = var.availability_zones
availability_zones = try(length(var.availability_zones) > 0 ? var.availability_zones : null, null)
engine = "redis"
at_rest_encryption_enabled = var.at_rest_encryption_enabled
kms_key_id = var.kms_key_id
Expand Down Expand Up @@ -39,7 +39,8 @@ resource "aws_elasticache_parameter_group" "redis_parameter_group" {
name = local.resource_identifier
description = "Terraform-managed ElastiCache parameter group for ${local.resource_identifier}"
# Strip the patch version from redis_version var
family = "redis${replace(var.redis_version, "/\\.[\\d]+$/", "")}"
#family = "redis${replace(var.redis_version, "/\\.[\\d]+$/", "")}"
family = var.redis_version == "6.2" ? "redis6.x" : "redis${replace(var.redis_version, "/\\.[\\d]+$/", "")}"

dynamic "parameter" {
for_each = var.cluster_mode_enabled ? concat([{ name = "cluster-enabled", value = "yes" }], var.parameter) : var.parameter
Expand Down
10 changes: 10 additions & 0 deletions elasticache/redis/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

terraform {
required_version = "~> 0.13"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 4.60.0"
}
}
}
54 changes: 54 additions & 0 deletions elasticache/valkey/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
## Requirements

No requirements.

## Providers

| Name | Version |
|------|---------|
| aws | n/a |

## Inputs

| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| apply\_immediately | Specifies whether any modifications are applied immediately, or during the next maintenance window. Default is false. | `bool` | `false` | no |
| at\_rest\_encryption\_enabled | Whether to enable encryption at rest | `bool` | `true` | no |
| auth\_token | The password used to access a password protected server. Can be specified only if transit\_encryption\_enabled = true. If specified must contain from 16 to 128 alphanumeric characters or symbols | `string` | `""` | no |
| auto\_minor\_version\_upgrade | Specifies whether a minor engine upgrades will be applied automatically to the underlying Cache Cluster instances during the maintenance window | `bool` | `true` | no |
| automatic\_failover\_enabled | Specifies whether a read-only replica will be automatically promoted to read/write primary if the existing primary fails. | `bool` | `true` | no |
| availability\_zones | A list of EC2 availability zones in which the replication group's cache clusters will be created. The order of the availability zones in the list is not important | `list(string)` | n/a | yes |
| business\_name | Business Name | `string` | n/a | yes |
| cluster\_mode\_enabled | Enable creation of a native redis cluster. | `bool` | `false` | no |
| environment | environment to deploy into, should typically dev/staging/prod | `string` | n/a | yes |
| kms\_key\_id | The ARN of the key that you wish to use if encrypting at rest. If not supplied, uses service managed encryption. Can be specified only if at\_rest\_encryption\_enabled = true | `string` | `""` | no |
| notification\_topic\_arn | An Amazon Resource Name (ARN) of an SNS topic to send ElastiCache notifications to. Example: arn:aws:sns:us-east-1:012345678999:my\_sns\_topic | `string` | `""` | no |
| num\_node\_groups | Required when cluster\_mode\_enabled is set to true. Specify the number of node groups (shards) for this Redis replication group. Changing this number will trigger an online resizing operation before other settings modifications. | `number` | `0` | no |
| number\_cache\_clusters | Number of Redis cache clusters (nodes) to create | `number` | `0` | no |
| parameter | A list of Redis parameters to apply. Note that parameters may differ from one Redis family to another | <pre>list(object({<br> name = string<br> value = string<br> }))</pre> | `[]` | no |
| redis\_maintenance\_window | Specifies the weekly time range for when maintenance on the cache cluster is performed. The format is ddd:hh24:mi-ddd:hh24:mi (24H Clock UTC). The minimum maintenance window is a 60 minute period | `string` | `"fri:08:00-fri:09:00"` | no |
| redis\_node\_type | Instance type to use for creating the Redis cache clusters | `string` | n/a | yes |
| redis\_port | n/a | `number` | `6379` | no |
| redis\_snapshot\_retention\_limit | The number of days for which ElastiCache will retain automatic cache cluster snapshots before deleting them. For example, if you set SnapshotRetentionLimit to 5, then a snapshot that was taken today will be retained for 5 days before being deleted. If the value of SnapshotRetentionLimit is set to zero (0), backups are turned off. Please note that setting a snapshot\_retention\_limit is not supported on cache.t1.micro or cache.t2.\* cache nodes | `number` | `0` | no |
| redis\_snapshot\_window | The daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your cache cluster. The minimum snapshot window is a 60 minute period | `string` | `"06:30-07:30"` | no |
| redis\_version | Redis version to use, defaults to 5.0.6 | `string` | `"5.0.6"` | no |
| replicas\_per\_node\_group | Required when `cluster_mode_enabled` is set to true. Specify the number of replica nodes in each node group. Valid values are 0 to 5. Changing this number will force a new resource. | `number` | `0` | no |
| security\_group\_ids | A list of cache security group ids to associate with this replication group | `list(string)` | n/a | yes |
| service\_name | Service name | `string` | n/a | yes |
| snapshot\_arns | A single-element string list containing an Amazon Resource Name (ARN) of a Redis RDB snapshot file stored in Amazon S3. Example: arn:aws:s3:::my\_bucket/snapshot1.rdb | `list(string)` | `[]` | no |
| snapshot\_name | The name of a snapshot from which to restore data into the new node group. Changing the snapshot\_name forces a new resource | `string` | `""` | no |
| subnets | List of VPC Subnet IDs for the cache subnet group | `list(string)` | n/a | yes |
| subservice\_name | Sub Service name | `string` | n/a | yes |
| tags | Tags for redis nodes | `map(string)` | `{}` | no |
| transit\_encryption\_enabled | Whether to enable encryption in transit. Requires 3.2.6 or >=4.0 redis\_version | `bool` | `false` | no |
| vpc\_id | VPC ID | `string` | n/a | yes |

## Outputs

| Name | Description |
|------|-------------|
| endpoint | n/a |
| id | n/a |
| parameter\_group | n/a |
| redis\_subnet\_group\_name | n/a |

12 changes: 12 additions & 0 deletions elasticache/valkey/dns.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
data "aws_route53_zone" "valkey_dns_hosted_zone" {
name = var.zone_name
vpc_id = var.vpc_id
}

resource "aws_route53_record" "valkey_dns" {
zone_id = data.aws_route53_zone.valkey_dns_hosted_zone.id
name = var.valkey_dns
type = "CNAME"
ttl = "300"
records = var.cluster_mode_enabled ? [join("", aws_elasticache_replication_group.valkey.*.configuration_endpoint_address)] : [join("", aws_elasticache_replication_group.valkey.*.primary_endpoint_address)]
}
14 changes: 14 additions & 0 deletions elasticache/valkey/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
locals {
_resource_identifier = "${var.business_name}-${var.service_name}-${var.subservice_name}"
resource_identifier = lower(local._resource_identifier)

default_tags = {
ManagedBy = "terraform"
Environment = lower(var.environment)
Business = lower(var.business_name)
Service = lower(var.service_name)
SubService = lower(var.subservice_name)
Name = lower(local.resource_identifier)
}
}

49 changes: 49 additions & 0 deletions elasticache/valkey/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
resource "aws_elasticache_replication_group" "valkey" {
replication_group_id = format("%.30s", "${local.resource_identifier}")
num_cache_clusters = var.cluster_mode_enabled ? null : var.number_cache_clusters
node_type = var.valkey_node_type
automatic_failover_enabled = var.automatic_failover_enabled && var.cluster_mode_enabled ? true : false
auto_minor_version_upgrade = var.auto_minor_version_upgrade
preferred_cache_cluster_azs = var.availability_zones
description = "Terraform-managed ElastiCache replication group for ${local.resource_identifier}"
engine = "valkey"
at_rest_encryption_enabled = var.at_rest_encryption_enabled
kms_key_id = var.kms_key_id
transit_encryption_enabled = var.transit_encryption_enabled
auth_token = var.transit_encryption_enabled ? var.auth_token : null
engine_version = var.valkey_version
port = var.valkey_port
parameter_group_name = aws_elasticache_parameter_group.valkey_parameter_group.id
subnet_group_name = aws_elasticache_subnet_group.valkey_subnet_group.id
security_group_ids = var.security_group_ids
snapshot_arns = var.snapshot_arns
snapshot_name = var.snapshot_name
apply_immediately = var.apply_immediately
maintenance_window = var.valkey_maintenance_window
notification_topic_arn = var.notification_topic_arn
snapshot_window = var.valkey_snapshot_window
snapshot_retention_limit = var.valkey_snapshot_retention_limit
tags = local.default_tags
cluster_mode = var.cluster_mode

}

resource "aws_elasticache_parameter_group" "valkey_parameter_group" {
name = local.resource_identifier
description = "Terraform-managed ElastiCache parameter group for ${local.resource_identifier}"
# Strip the patch version from valkey_version var
family = "valkey${replace(var.valkey_version, "/\\.[\\d]+$/", "")}"

dynamic "parameter" {
for_each = var.cluster_mode_enabled ? concat([{ name = "cluster-enabled", value = "yes" }], var.parameter) : var.parameter
content {
name = parameter.value.name
value = parameter.value.value
}
}
}

resource "aws_elasticache_subnet_group" "valkey_subnet_group" {
name = local.resource_identifier
subnet_ids = var.subnets
}
19 changes: 19 additions & 0 deletions elasticache/valkey/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
output "parameter_group" {
value = aws_elasticache_parameter_group.valkey_parameter_group.id
}

output "valkey_subnet_group_name" {
value = aws_elasticache_subnet_group.valkey_subnet_group.name
}

output "id" {
value = aws_elasticache_replication_group.valkey.id
}

output "endpoint" {
value = aws_elasticache_replication_group.valkey.primary_endpoint_address
}

output "dns_endpoint" {
value = aws_route53_record.valkey_dns.fqdn
}
189 changes: 189 additions & 0 deletions elasticache/valkey/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
variable "apply_immediately" {
description = "Specifies whether any modifications are applied immediately, or during the next maintenance window. Default is false."
type = bool
default = false
}

variable "environment" {
description = "environment to deploy into, should typically dev/staging/prod"
type = string
}

variable "number_cache_clusters" {
description = "Number of Redis cache clusters (nodes) to create"
type = number
default = 0
}

variable "automatic_failover_enabled" {
default = true
type = bool
description = "Specifies whether a read-only replica will be automatically promoted to read/write primary if the existing primary fails."
}

variable "valkey_node_type" {
description = "Instance type to use for creating the Redis cache clusters"
type = string
}

variable "valkey_port" {
type = number
default = 6379
}

variable "subnets" {
type = list(string)
description = "List of VPC Subnet IDs for the cache subnet group"
}

variable "valkey_version" {
description = "Redis version to use, defaults to 5.0.6"
type = string
default = "5.0.6"
}

variable "vpc_id" {
description = "VPC ID"
type = string
}

variable "valkey_maintenance_window" {
description = "Specifies the weekly time range for when maintenance on the cache cluster is performed. The format is ddd:hh24:mi-ddd:hh24:mi (24H Clock UTC). The minimum maintenance window is a 60 minute period"
type = string
default = "fri:08:00-fri:09:00"
}

variable "valkey_snapshot_window" {
description = "The daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your cache cluster. The minimum snapshot window is a 60 minute period"
type = string
default = "06:30-07:30"
}

variable "valkey_snapshot_retention_limit" {
description = "The number of days for which ElastiCache will retain automatic cache cluster snapshots before deleting them. For example, if you set SnapshotRetentionLimit to 5, then a snapshot that was taken today will be retained for 5 days before being deleted. If the value of SnapshotRetentionLimit is set to zero (0), backups are turned off. Please note that setting a snapshot_retention_limit is not supported on cache.t1.micro or cache.t2.* cache nodes"
type = number
default = 0
}

variable "tags" {
description = "Tags for valkey nodes"
type = map(string)
default = {}
}

variable "auto_minor_version_upgrade" {
description = "Specifies whether a minor engine upgrades will be applied automatically to the underlying Cache Cluster instances during the maintenance window"
type = bool
default = true
}

variable "availability_zones" {
description = "A list of EC2 availability zones in which the replication group's cache clusters will be created. The order of the availability zones in the list is not important"
type = list(string)
}

variable "at_rest_encryption_enabled" {
description = "Whether to enable encryption at rest"
type = bool
default = true
}

variable "kms_key_id" {
description = "The ARN of the key that you wish to use if encrypting at rest. If not supplied, uses service managed encryption. Can be specified only if at_rest_encryption_enabled = true"
type = string
default = ""
}

variable "transit_encryption_enabled" {
description = "Whether to enable encryption in transit. Requires 3.2.6 or >=4.0 valkey_version"
type = bool
default = false
}

variable "auth_token" {
description = "The password used to access a password protected server. Can be specified only if transit_encryption_enabled = true. If specified must contain from 16 to 128 alphanumeric characters or symbols"
type = string
default = ""
}

variable "security_group_ids" {
description = "A list of cache security group ids to associate with this replication group"
type = list(string)
}

variable "snapshot_arns" {
description = "A single-element string list containing an Amazon Resource Name (ARN) of a Redis RDB snapshot file stored in Amazon S3. Example: arn:aws:s3:::my_bucket/snapshot1.rdb"
type = list(string)
default = []
}

variable "snapshot_name" {
description = " The name of a snapshot from which to restore data into the new node group. Changing the snapshot_name forces a new resource"
type = string
default = ""
}

variable "notification_topic_arn" {
description = "An Amazon Resource Name (ARN) of an SNS topic to send ElastiCache notifications to. Example: arn:aws:sns:us-east-1:012345678999:my_sns_topic"
type = string
default = ""
}

variable "business_name" {
type = string
description = "Business Name"
}

variable "service_name" {
type = string
description = "Service name"
}

variable "subservice_name" {
type = string
description = "Sub Service name"
}

variable "cluster_mode_enabled" {
type = bool
description = "Enable creation of a native valkey cluster."
default = false
}

variable "cluster_mode" {
type = string
description = "Enable creation of a native valkey cluster."
default = "disabled"
}

variable "num_node_groups" {
type = number
description = "Required when cluster_mode_enabled is set to true. Specify the number of node groups (shards) for this Redis replication group. Changing this number will trigger an online resizing operation before other settings modifications."
default = 0
}

variable "replicas_per_node_group" {
type = number
description = "Required when `cluster_mode_enabled` is set to true. Specify the number of replica nodes in each node group. Valid values are 0 to 5. Changing this number will force a new resource."
default = 0
}

variable "parameter" {
type = list(object({
name = string
value = string
}))
default = []
description = "A list of Redis parameters to apply. Note that parameters may differ from one Redis family to another"
}

variable "valkey_dns" {
description = "valkey dns name"
type = string
}

variable "zone_name" {
description = "valkey dns name"
default = "moeinternal.com"
type = string
}
10 changes: 10 additions & 0 deletions elasticache/valkey/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

terraform {
required_version = "~> 0.13"
required_providers {
aws = {
source = "hashicorp/aws"
version = "~> 5.99.1"
}
}
}
Loading