Skip to content

Commit f6a8889

Browse files
committed
chore: Updates from testing and validating examples
1 parent fe5d295 commit f6a8889

File tree

6 files changed

+28
-32
lines changed

6 files changed

+28
-32
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ No modules.
8585
| <a name="input_kms_key_arn"></a> [kms\_key\_arn](#input\_kms\_key\_arn) | 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` | `null` | no |
8686
| <a name="input_log_delivery_configuration"></a> [log\_delivery\_configuration](#input\_log\_delivery\_configuration) | (Redis only) Specifies the destination and format of Redis SLOWLOG or Redis Engine Log | `any` | <pre>{<br> "slow-log": {<br> "destination_type": "cloudwatch-logs",<br> "log_format": "json"<br> }<br>}</pre> | no |
8787
| <a name="input_maintenance_window"></a> [maintenance\_window](#input\_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) | `string` | `null` | no |
88-
| <a name="input_multi_az_enabled"></a> [multi\_az\_enabled](#input\_multi\_az\_enabled) | Specifies whether to enable Multi-AZ Support for the replication group. If true, `automatic_failover_enabled` must also be enabled. Defaults to `false` | `bool` | `null` | no |
88+
| <a name="input_multi_az_enabled"></a> [multi\_az\_enabled](#input\_multi\_az\_enabled) | Specifies whether to enable Multi-AZ Support for the replication group. If true, `automatic_failover_enabled` must also be enabled. Defaults to `false` | `bool` | `false` | no |
8989
| <a name="input_network_type"></a> [network\_type](#input\_network\_type) | The IP versions for cache cluster connections. Valid values are `ipv4`, `ipv6` or `dual_stack` | `string` | `null` | no |
9090
| <a name="input_node_type"></a> [node\_type](#input\_node\_type) | The instance class used. For Memcached, changing this value will re-create the resource | `string` | `null` | no |
9191
| <a name="input_notification_topic_arn"></a> [notification\_topic\_arn](#input\_notification\_topic\_arn) | ARN of an SNS topic to send ElastiCache notifications to | `string` | `null` | no |
@@ -119,7 +119,7 @@ No modules.
119119
| <a name="input_subnet_ids"></a> [subnet\_ids](#input\_subnet\_ids) | List of VPC Subnet IDs for the Elasticache subnet group | `list(string)` | `[]` | no |
120120
| <a name="input_tags"></a> [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no |
121121
| <a name="input_transit_encryption_enabled"></a> [transit\_encryption\_enabled](#input\_transit\_encryption\_enabled) | Enable encryption in-transit. Supported only with Memcached versions `1.6.12` and later, running in a VPC | `bool` | `null` | no |
122-
| <a name="input_user_group_ids"></a> [user\_group\_ids](#input\_user\_group\_ids) | User Group ID to associate with the replication group. Only a maximum of one (1) user group ID is valid | `list(string)` | `[]` | no |
122+
| <a name="input_user_group_ids"></a> [user\_group\_ids](#input\_user\_group\_ids) | User Group ID to associate with the replication group. Only a maximum of one (1) user group ID is valid | `list(string)` | `null` | no |
123123
| <a name="input_vpc_id"></a> [vpc\_id](#input\_vpc\_id) | Identifier of the VPC where the security group will be created | `string` | `null` | no |
124124

125125
## Outputs

examples/memcached-cluster/main.tf

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@ module "elasticache" {
2828
cluster_id = local.name
2929

3030
engine = "memcached"
31-
engine_version = "1.6"
31+
engine_version = "1.6.17"
3232
node_type = "cache.t4g.small"
3333
num_cache_nodes = 2
3434
az_mode = "cross-az"
3535

36+
# Security group
37+
vpc_id = module.vpc.vpc_id
3638
security_group_rules = {
3739
ingress_vpc = {
3840
# Default type is `ingress`

examples/redis-cluster/main.tf

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ module "elasticache" {
3030
engine_version = "7.1"
3131
node_type = "cache.t4g.small"
3232

33+
# Security group
34+
vpc_id = module.vpc.vpc_id
3335
security_group_rules = {
3436
ingress_vpc = {
3537
# Default type is `ingress`
@@ -50,16 +52,12 @@ module "elasticache" {
5052
# parameter group
5153
create_parameter_group = true
5254
parameter_group_name = local.name
53-
parameter_group_family = "redis7.1"
55+
parameter_group_family = "redis7"
5456
parameter_group_description = "${title(local.name)} parameter group"
5557
parameters = [
5658
{
57-
name = "activerehashing"
59+
name = "latency-tracking"
5860
value = "yes"
59-
},
60-
{
61-
name = "min-slaves-to-write"
62-
value = "2"
6361
}
6462
]
6563

examples/redis-replication-group/main.tf

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ locals {
2525
module "elasticache" {
2626
source = "../../"
2727

28+
create_cluster = false
2829
create_replication_group = true
2930
replication_group_id = local.name
3031

@@ -42,6 +43,8 @@ module "elasticache" {
4243
transit_encryption_enabled = true
4344
auth_token = "PickSomethingMoreSecure123!"
4445

46+
# Security group
47+
vpc_id = module.vpc.vpc_id
4548
security_group_rules = {
4649
ingress_vpc = {
4750
# Default type is `ingress`
@@ -62,16 +65,12 @@ module "elasticache" {
6265
# parameter group
6366
create_parameter_group = true
6467
parameter_group_name = local.name
65-
parameter_group_family = "redis7.1"
68+
parameter_group_family = "redis7"
6669
parameter_group_description = "${title(local.name)} parameter group"
6770
parameters = [
6871
{
69-
name = "activerehashing"
72+
name = "latency-tracking"
7073
value = "yes"
71-
},
72-
{
73-
name = "min-slaves-to-write"
74-
value = "2"
7574
}
7675
]
7776

main.tf

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ locals {
22
# https://github.com/hashicorp/terraform-provider-aws/blob/3c4cb52c5dc2c09e10e5a717f73d1d8bc4186e87/internal/service/elasticache/cluster.go#L271
33
in_replication_group = var.replication_group_id != null
44

5-
security_group_ids = local.create_security_group ? concat(var.security_group_ids, aws_security_group.this[0].id) : var.security_group_ids
5+
security_group_ids = local.create_security_group ? concat(var.security_group_ids, [aws_security_group.this[0].id]) : var.security_group_ids
66
port = var.engine == "memcached" ? 11211 : 6379
77

88
tags = merge(var.tags, { terraform-aws-modules = "elasticache" })
@@ -29,10 +29,10 @@ resource "aws_elasticache_cluster" "this" {
2929
for_each = { for k, v in var.log_delivery_configuration : k => v if var.engine == "redis" }
3030

3131
content {
32-
destination = try(v.create_cloudwatch_log_group, true) && log_delivery_configuration.value.destination_type == "cloudwatch-logs" ? aws_cloudwatch_log_group.this[each.key].name : log_delivery_configuration.value.destination
32+
destination = try(log_delivery_configuration.value.create_cloudwatch_log_group, true) && log_delivery_configuration.value.destination_type == "cloudwatch-logs" ? aws_cloudwatch_log_group.this[log_delivery_configuration.key].name : log_delivery_configuration.value.destination
3333
destination_type = log_delivery_configuration.value.destination_type
3434
log_format = log_delivery_configuration.value.log_format
35-
log_type = try(log_delivery_configuration.value.log_type, each.key)
35+
log_type = try(log_delivery_configuration.value.log_type, log_delivery_configuration.key)
3636
}
3737
}
3838

@@ -52,7 +52,7 @@ resource "aws_elasticache_cluster" "this" {
5252
snapshot_name = local.in_replication_group ? null : var.snapshot_name
5353
snapshot_retention_limit = local.in_replication_group ? null : var.snapshot_retention_limit
5454
snapshot_window = local.in_replication_group ? null : var.snapshot_window
55-
subnet_group_name = local.in_replication_group ? null : var.subnet_group_name
55+
subnet_group_name = local.in_replication_group ? null : local.subnet_group_name
5656
transit_encryption_enabled = var.transit_encryption_enabled
5757

5858
tags = local.tags
@@ -89,10 +89,10 @@ resource "aws_elasticache_replication_group" "this" {
8989
for_each = { for k, v in var.log_delivery_configuration : k => v if var.engine == "redis" }
9090

9191
content {
92-
destination = try(v.create_cloudwatch_log_group, true) && log_delivery_configuration.value.destination_type == "cloudwatch-logs" ? aws_cloudwatch_log_group.this[each.key].name : log_delivery_configuration.value.destination
92+
destination = try(log_delivery_configuration.value.create_cloudwatch_log_group, true) && log_delivery_configuration.value.destination_type == "cloudwatch-logs" ? aws_cloudwatch_log_group.this[log_delivery_configuration.key].name : log_delivery_configuration.value.destination
9393
destination_type = log_delivery_configuration.value.destination_type
9494
log_format = log_delivery_configuration.value.log_format
95-
log_type = try(log_delivery_configuration.value.log_type, each.key)
95+
log_type = try(log_delivery_configuration.value.log_type, log_delivery_configuration.key)
9696
}
9797
}
9898

@@ -114,7 +114,7 @@ resource "aws_elasticache_replication_group" "this" {
114114
snapshot_name = local.in_global_replication_group ? null : var.snapshot_name
115115
snapshot_retention_limit = var.snapshot_retention_limit
116116
snapshot_window = var.snapshot_window
117-
subnet_group_name = var.subnet_group_name
117+
subnet_group_name = local.subnet_group_name
118118
transit_encryption_enabled = local.in_global_replication_group ? null : var.transit_encryption_enabled
119119
user_group_ids = var.user_group_ids
120120

@@ -166,10 +166,6 @@ resource "aws_elasticache_parameter_group" "this" {
166166
}
167167
}
168168

169-
lifecycle {
170-
create_before_destroy = true
171-
}
172-
173169
tags = local.tags
174170
}
175171

@@ -178,13 +174,14 @@ resource "aws_elasticache_parameter_group" "this" {
178174
################################################################################
179175

180176
locals {
181-
subnet_group_name = try(coalesce(var.subnet_group_name, var.cluster_id, var.replication_group_id), "")
177+
inter_subnet_group_name = try(coalesce(var.subnet_group_name, var.cluster_id, var.replication_group_id), "")
178+
subnet_group_name = var.create && var.create_subnet_group ? aws_elasticache_subnet_group.this[0].name : var.subnet_group_name
182179
}
183180

184181
resource "aws_elasticache_subnet_group" "this" {
185182
count = var.create && var.create_subnet_group ? 1 : 0
186183

187-
name = local.subnet_group_name
184+
name = local.inter_subnet_group_name
188185
description = coalesce(var.subnet_group_description, "ElastiCache subnet group")
189186
subnet_ids = var.subnet_ids
190187

@@ -216,7 +213,7 @@ resource "aws_security_group" "this" {
216213
}
217214

218215
resource "aws_vpc_security_group_ingress_rule" "this" {
219-
for_each = { for k, v in var.security_group_rules : k => v if local.create_security_group && try(v.type == "ingress") }
216+
for_each = { for k, v in var.security_group_rules : k => v if local.create_security_group && try(v.type, "ingress") == "ingress" }
220217

221218
# Required
222219
security_group_id = aws_security_group.this[0].id
@@ -235,7 +232,7 @@ resource "aws_vpc_security_group_ingress_rule" "this" {
235232
}
236233

237234
resource "aws_vpc_security_group_egress_rule" "this" {
238-
for_each = { for k, v in var.security_group_rules : k => v if local.create_security_group && try(v.type == "egress") }
235+
for_each = { for k, v in var.security_group_rules : k => v if local.create_security_group && try(v.type, "ingress") == "egress" }
239236

240237
# Required
241238
security_group_id = aws_security_group.this[0].id

variables.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ variable "kms_key_arn" {
236236
variable "multi_az_enabled" {
237237
description = "Specifies whether to enable Multi-AZ Support for the replication group. If true, `automatic_failover_enabled` must also be enabled. Defaults to `false`"
238238
type = bool
239-
default = null
239+
default = false
240240
}
241241

242242
variable "num_cache_clusters" {
@@ -278,7 +278,7 @@ variable "security_group_names" {
278278
variable "user_group_ids" {
279279
description = "User Group ID to associate with the replication group. Only a maximum of one (1) user group ID is valid"
280280
type = list(string)
281-
default = []
281+
default = null
282282
}
283283

284284
################################################################################

0 commit comments

Comments
 (0)