Skip to content

Commit b6f1093

Browse files
committed
Restructure standalone code
1 parent 9614ef6 commit b6f1093

File tree

8 files changed

+24
-59
lines changed

8 files changed

+24
-59
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ Security scanning is graciously provided by Prowler. Proowler is the leading ful
161161
| <a name="input_name"></a> [name](#input\_name) | The name of the redis cluster | `string` | `""` | no |
162162
| <a name="input_node_type"></a> [node\_type](#input\_node\_type) | The instance size of the redis cluster | `string` | `"cache.t3.micro"` | no |
163163
| <a name="input_notification_topic_arn"></a> [notification\_topic\_arn](#input\_notification\_topic\_arn) | (Optional) ARN of an SNS topic to send ElastiCache notifications | `string` | `null` | no |
164-
| <a name="input_num_cache_nodes"></a> [num\_cache\_nodes](#input\_num\_cache\_nodes) | The number of cache nodes | `number` | `1` | no |
164+
| <a name="input_num_cache_nodes"></a> [num\_cache\_nodes](#input\_num\_cache\_nodes) | The number of cache nodes | `number` | n/a | yes |
165165
| <a name="input_ok_actions"></a> [ok\_actions](#input\_ok\_actions) | The list of actions to execute when this alarm transitions into an OK state from any other state. Each action is specified as an Amazon Resource Number (ARN) | `list(string)` | `[]` | no |
166166
| <a name="input_parameter"></a> [parameter](#input\_parameter) | A list of Redis parameters to apply. It can be different based on mode slection. | <pre>list(object({<br/> name = string<br/> value = string<br/> }))</pre> | `[]` | no |
167167
| <a name="input_parameter_group_description"></a> [parameter\_group\_description](#input\_parameter\_group\_description) | Parameter group | `string` | `null` | no |
@@ -178,7 +178,7 @@ Security scanning is graciously provided by Prowler. Proowler is the leading ful
178178
| <a name="input_snapshot_retention_limit"></a> [snapshot\_retention\_limit](#input\_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` | `7` | no |
179179
| <a name="input_snapshot_window"></a> [snapshot\_window](#input\_snapshot\_window) | The daily time range (in UTC) during which ElastiCache will begin taking a daily snapshot of your cache cluster. The minimum maintenance window is a 60 minute period. Example: 05:00-09:00 | `string` | `"03:00-05:00"` | no |
180180
| <a name="input_subnets"></a> [subnets](#input\_subnets) | The subnets where the redis cluster is deployed | `list(string)` | `[]` | no |
181-
| <a name="input_transit_encryption_enabled"></a> [transit\_encryption\_enabled](#input\_transit\_encryption\_enabled) | (Optional) Whether to enable encryption in transit | `bool` | `true` | no |
181+
| <a name="input_transit_encryption_enabled"></a> [transit\_encryption\_enabled](#input\_transit\_encryption\_enabled) | (Optional) Whether to enable encryption in transit | `bool` | `false` | no |
182182
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | The vpc where we will put the redis cluster | `string` | `""` | no |
183183

184184
## Outputs

examples/complete-cluster-mode/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ This example will be very useful for users who are new to a module and want to q
2626
| Name | Source | Version |
2727
|------|--------|---------|
2828
| <a name="module_kms"></a> [kms](#module\_kms) | terraform-aws-modules/kms/aws | n/a |
29-
| <a name="module_redis"></a> [redis](#module\_redis) | squareops/elasticache-redis/aws | n/a |
29+
| <a name="module_redis"></a> [redis](#module\_redis) | ../../ | n/a |
3030
| <a name="module_vpc"></a> [vpc](#module\_vpc) | squareops/vpc/aws | 3.3.1 |
3131

3232
## Resources

examples/complete-cluster-mode/main.tf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,20 +104,27 @@ module "redis" {
104104
environment = local.environment
105105
engine_version = local.redis_engine_version
106106
cluster_mode_enabled = local.cluster_mode_enabled
107+
num_cache_nodes = 0
107108
cluster_mode_num_node_groups = 1
108109
cluster_mode_replicas_per_node_group = 2
109110
vpc_id = module.vpc.vpc_id
110111
subnets = module.vpc.database_subnets
111112
kms_key_arn = module.kms.key_arn
112113
multi_az_enabled = true
114+
transit_encryption_enabled = true
113115
availability_zones = local.availability_zones
114116
snapshot_window = "07:00-08:00"
115117
maintenance_window = "sun:09:00-sun:10:00"
116118
allowed_security_groups = local.allowed_security_groups
117119
cloudwatch_metric_alarms_enabled = true
118120
alarm_cpu_threshold_percent = 70
119121
alarm_memory_threshold_bytes = "10000000" # in bytes
120-
slack_notification_enabled = true
122+
alarm_eviction_threshold = 1000
123+
alarm_connections_threshold = 100
124+
alarm_replication_lag_threshold = 10
125+
alarm_cache_hits_threshold = 1000
126+
alarm_cache_misses_threshold = 50
127+
slack_notification_enabled = false
121128
slack_username = ""
122129
slack_channel = ""
123130
slack_webhook_url = ""

examples/complete/main.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ module "vpc" {
9696
}
9797

9898
module "redis" {
99-
source = "../../"
99+
source = "squareops/elasticache-redis/aws"
100100
name = local.name
101101
family = local.family
102102
node_type = local.node_type
@@ -107,6 +107,7 @@ module "redis" {
107107
subnets = module.vpc.database_subnets
108108
kms_key_arn = module.kms.key_arn
109109
multi_az_enabled = true
110+
transit_encryption_enabled = true
110111
availability_zones = local.availability_zones
111112
snapshot_window = "07:00-08:00"
112113
maintenance_window = "sun:09:00-sun:10:00"

examples/standalone/README.md

Lines changed: 0 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -7,45 +7,3 @@
77
<br>
88

99
This example will be very useful for users who are new to a module and want to quickly learn how to use it. By reviewing the examples, users can gain a better understanding of how the module works, what features it supports, and how to customize it to their specific needs.<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK -->
10-
## Requirements
11-
12-
| Name | Version |
13-
|------|---------|
14-
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | >= 0.13 |
15-
| <a name="requirement_aws"></a> [aws](#requirement\_aws) | >= 3.63 |
16-
17-
## Providers
18-
19-
| Name | Version |
20-
|------|---------|
21-
| <a name="provider_aws"></a> [aws](#provider\_aws) | >= 3.63 |
22-
23-
## Modules
24-
25-
| Name | Source | Version |
26-
|------|--------|---------|
27-
| <a name="module_redis"></a> [redis](#module\_redis) | ../../ | n/a |
28-
| <a name="module_vpc"></a> [vpc](#module\_vpc) | squareops/vpc/aws | 3.3.1 |
29-
30-
## Resources
31-
32-
| Name | Type |
33-
|------|------|
34-
| [aws_availability_zones.primary](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source |
35-
| [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source |
36-
| [aws_region.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/region) | data source |
37-
38-
## Inputs
39-
40-
No inputs.
41-
42-
## Outputs
43-
44-
| Name | Description |
45-
|------|-------------|
46-
| <a name="output_cluster_address"></a> [cluster\_address](#output\_cluster\_address) | (Memcached only) DNS name of the cache cluster without the port appended |
47-
| <a name="output_cluster_arn"></a> [cluster\_arn](#output\_cluster\_arn) | The ARN of the ElastiCache Cluster |
48-
| <a name="output_cluster_cache_nodes"></a> [cluster\_cache\_nodes](#output\_cluster\_cache\_nodes) | List of node objects including `id`, `address`, `port` and `availability_zone` |
49-
| <a name="output_cluster_configuration_endpoint"></a> [cluster\_configuration\_endpoint](#output\_cluster\_configuration\_endpoint) | (Memcached only) Configuration endpoint to allow host discovery |
50-
| <a name="output_cluster_engine_version_actual"></a> [cluster\_engine\_version\_actual](#output\_cluster\_engine\_version\_actual) | Because ElastiCache pulls the latest minor or patch for a version, this attribute returns the running version of the cache engine |
51-
<!-- END_TF_DOCS -->

examples/standalone/main.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ module "vpc" {
3636
}
3737

3838
module "redis" {
39-
source = "../../"
40-
num_cache_nodes = 1 #keep it 1 for To create only master node and 0 replica node.
39+
source = "squareops/elasticache-redis/aws"
40+
num_cache_nodes = 1 #keep it 1 for To create only master node and 0 replica node.
4141
name = local.name
4242
family = local.family
4343
node_type = local.node_type

main.tf

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ resource "aws_elasticache_parameter_group" "default" {
3636
}
3737

3838
resource "aws_elasticache_cluster" "redis" {
39-
count = var.num_cache_nodes == 1 ? 1 : 0 # Only create if num_cache_nodes == 1
39+
count = (!var.transit_encryption_enabled && var.num_cache_nodes == 1) ? 1 : 0
4040
cluster_id = "${var.environment}-${var.name}-standalone-redis"
4141
engine = "redis"
4242
engine_version = var.engine_version
@@ -77,7 +77,7 @@ resource "aws_elasticache_cluster" "redis" {
7777
}
7878

7979
resource "aws_elasticache_replication_group" "redis" {
80-
count = var.num_cache_nodes > 1 ? 1 : 0 # Only create if num_cache_nodes == 1
80+
count = var.transit_encryption_enabled ? 1 : 0 # Only create if num_cache_nodes == 1
8181
replication_group_id = "${var.environment}-${var.name}-redis"
8282
port = var.port
8383
engine = "redis"
@@ -222,7 +222,7 @@ resource "aws_cloudwatch_metric_alarm" "cache_cpu" {
222222
threshold = var.alarm_cpu_threshold_percent
223223

224224
dimensions = {
225-
CacheClusterId = var.num_cache_nodes > 1 ? aws_elasticache_replication_group.redis[count.index].id : aws_elasticache_cluster.redis[0].id
225+
CacheClusterId = var.transit_encryption_enabled ? aws_elasticache_replication_group.redis[count.index].id : aws_elasticache_cluster.redis[0].id
226226
}
227227

228228
alarm_actions = [aws_sns_topic.slack_topic[0].arn]
@@ -248,7 +248,7 @@ resource "aws_cloudwatch_metric_alarm" "cache_memory" {
248248
threshold = var.alarm_memory_threshold_bytes
249249

250250
dimensions = {
251-
CacheClusterId = var.num_cache_nodes > 1 ? aws_elasticache_replication_group.redis[count.index].id : aws_elasticache_cluster.redis[0].id
251+
CacheClusterId = var.transit_encryption_enabled ? aws_elasticache_replication_group.redis[count.index].id : aws_elasticache_cluster.redis[0].id
252252
}
253253

254254
alarm_actions = [aws_sns_topic.slack_topic[0].arn]
@@ -274,7 +274,7 @@ resource "aws_cloudwatch_metric_alarm" "cache_evictions" {
274274
threshold = var.alarm_eviction_threshold
275275

276276
dimensions = {
277-
CacheClusterId = var.num_cache_nodes > 1 ? aws_elasticache_replication_group.redis[count.index].id : aws_elasticache_cluster.redis[0].id
277+
CacheClusterId = var.transit_encryption_enabled ? aws_elasticache_replication_group.redis[count.index].id : aws_elasticache_cluster.redis[0].id
278278
}
279279

280280
alarm_actions = [aws_sns_topic.slack_topic[0].arn]
@@ -300,7 +300,7 @@ resource "aws_cloudwatch_metric_alarm" "cache_connections" {
300300
threshold = var.alarm_connections_threshold
301301

302302
dimensions = {
303-
CacheClusterId = var.num_cache_nodes > 1 ? aws_elasticache_replication_group.redis[count.index].id : aws_elasticache_cluster.redis[0].id
303+
CacheClusterId = var.transit_encryption_enabled ? aws_elasticache_replication_group.redis[count.index].id : aws_elasticache_cluster.redis[0].id
304304
}
305305

306306
alarm_actions = [aws_sns_topic.slack_topic[0].arn]
@@ -352,7 +352,7 @@ resource "aws_cloudwatch_metric_alarm" "cache_hits" {
352352
threshold = var.alarm_cache_hits_threshold
353353

354354
dimensions = {
355-
CacheClusterId = var.num_cache_nodes > 1 ? aws_elasticache_replication_group.redis[count.index].id : aws_elasticache_cluster.redis[0].id
355+
CacheClusterId = var.transit_encryption_enabled ? aws_elasticache_replication_group.redis[count.index].id : aws_elasticache_cluster.redis[0].id
356356
}
357357

358358
alarm_actions = [aws_sns_topic.slack_topic[0].arn]
@@ -378,7 +378,7 @@ resource "aws_cloudwatch_metric_alarm" "cache_misses" {
378378
threshold = var.alarm_cache_misses_threshold
379379

380380
dimensions = {
381-
CacheClusterId = var.num_cache_nodes > 1 ? aws_elasticache_replication_group.redis[count.index].id : aws_elasticache_cluster.redis[0].id
381+
CacheClusterId = var.transit_encryption_enabled ? aws_elasticache_replication_group.redis[count.index].id : aws_elasticache_cluster.redis[0].id
382382
}
383383

384384
alarm_actions = [aws_sns_topic.slack_topic[0].arn]

variables.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ variable "parameter" {
3636

3737
variable "num_cache_nodes" {
3838
description = "The number of cache nodes"
39-
default = 1
4039
type = number
4140
}
4241

@@ -127,7 +126,7 @@ variable "at_rest_encryption_enabled" {
127126

128127
variable "transit_encryption_enabled" {
129128
description = "(Optional) Whether to enable encryption in transit"
130-
default = true
129+
default = false
131130
type = bool
132131
}
133132

0 commit comments

Comments
 (0)