Skip to content

Commit 4f55a42

Browse files
authored
Merge pull request #5 from wiseelf/feat/engine-upgrade-support
Feat/engine upgrade support
2 parents 60f6d29 + 446681d commit 4f55a42

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

main.tf

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,26 @@ resource "aws_elasticache_subnet_group" "default" {
8989
tags = module.this.tags
9090
}
9191

92+
locals {
93+
94+
safe_family = replace(var.elasticache_parameter_group_family, ".", "-")
95+
96+
parameter_group_name = (
97+
var.parameter_group_name != null ? var.parameter_group_name : (
98+
var.create_parameter_group
99+
?
100+
"${module.this.id}-${local.safe_family}" # The name of the new parameter group to be created
101+
:
102+
"default.${var.elasticache_parameter_group_family}" # Default parameter group name created by AWS
103+
)
104+
)
105+
}
106+
92107
resource "aws_elasticache_parameter_group" "default" {
93-
count = local.enabled ? 1 : 0
94-
name = module.this.id
95-
family = var.elasticache_parameter_group_family
108+
count = local.enabled && var.create_parameter_group ? 1 : 0
109+
name = local.parameter_group_name
110+
description = var.parameter_group_description != null ? var.parameter_group_description : "Elasticache parameter group ${local.parameter_group_name}"
111+
family = var.elasticache_parameter_group_family
96112

97113
dynamic "parameter" {
98114
for_each = var.elasticache_parameters
@@ -101,6 +117,10 @@ resource "aws_elasticache_parameter_group" "default" {
101117
value = tostring(parameter.value.value)
102118
}
103119
}
120+
121+
lifecycle {
122+
create_before_destroy = true
123+
}
104124
}
105125

106126
resource "aws_elasticache_cluster" "default" {
@@ -111,7 +131,7 @@ resource "aws_elasticache_cluster" "default" {
111131
engine_version = var.engine_version
112132
node_type = var.instance_type
113133
num_cache_nodes = var.cluster_size
114-
parameter_group_name = join("", aws_elasticache_parameter_group.default[*].name)
134+
parameter_group_name = local.parameter_group_name
115135
transit_encryption_enabled = var.transit_encryption_enabled
116136
subnet_group_name = local.elasticache_subnet_group_name
117137
# It would be nice to remove null or duplicate security group IDs, if there are any, using `compact`,

variables.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,3 +137,21 @@ variable "transit_encryption_enabled" {
137137
description = "Boolean flag to enable transit encryption (requires Memcached version 1.6.12+)"
138138
default = false
139139
}
140+
141+
variable "create_parameter_group" {
142+
type = bool
143+
default = true
144+
description = "Whether new parameter group should be created. Set to false if you want to use existing parameter group"
145+
}
146+
147+
variable "parameter_group_description" {
148+
type = string
149+
default = null
150+
description = "Managed by Terraform"
151+
}
152+
153+
variable "parameter_group_name" {
154+
type = string
155+
default = null
156+
description = "Override the default parameter group name"
157+
}

0 commit comments

Comments
 (0)