Skip to content

Commit 8f78400

Browse files
[FEAT] add global_replication_group_id support (#253)
1 parent e5cca56 commit 8f78400

File tree

4 files changed

+42
-30
lines changed

4 files changed

+42
-30
lines changed

Diff for: README.md

+1
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,7 @@ Available targets:
247247
| <a name="input_existing_security_groups"></a> [existing\_security\_groups](#input\_existing\_security\_groups) | DEPRECATED: Use `associated_security_group_ids` instead.<br/>Historical description: List of existing Security Group IDs to place the cluster into.<br/>Set `use_existing_security_groups` to `true` to enable using `existing_security_groups` as Security Groups for the cluster. | `list(string)` | `[]` | no |
248248
| <a name="input_family"></a> [family](#input\_family) | The family of the ElastiCache parameter group | `string` | `"redis4.0"` | no |
249249
| <a name="input_final_snapshot_identifier"></a> [final\_snapshot\_identifier](#input\_final\_snapshot\_identifier) | The name of your final node group (shard) snapshot. ElastiCache creates the snapshot from the primary node in the cluster. If omitted, no final snapshot will be made. | `string` | `null` | no |
250+
| <a name="input_global_replication_group_id"></a> [global\_replication\_group\_id](#input\_global\_replication\_group\_id) | The ID of the global replication group to which this replication group should belong. If this parameter is specified, the replication group is added to the specified global replication group as a secondary replication group. When `global_replication_group_id` is set, the following parameters are ignored (set to `null`): `engine`, `engine_version`, `instance_type`, `cluster_mode_num_node_groups`, `transit_encryption_enabled`, and `snapshot_arns`. Additionally, `create_parameter_group` is set to `false`. | `string` | `null` | no |
250251
| <a name="input_id_length_limit"></a> [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).<br/>Set to `0` for unlimited length.<br/>Set to `null` for keep the existing setting, which defaults to `0`.<br/>Does not affect `id_full`. | `number` | `null` | no |
251252
| <a name="input_inline_rules_enabled"></a> [inline\_rules\_enabled](#input\_inline\_rules\_enabled) | NOT RECOMMENDED. Create rules "inline" instead of as separate `aws_security_group_rule` resources.<br/>See [#20046](https://github.com/hashicorp/terraform-provider-aws/issues/20046) for one of several issues with inline rules.<br/>See [this post](https://github.com/hashicorp/terraform-provider-aws/pull/9032#issuecomment-639545250) for details on the difference between inline rules and rule resources. | `bool` | `false` | no |
252253
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | Elastic cache instance type | `string` | `"cache.t2.micro"` | no |

Diff for: main.tf

+34-28
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ locals {
55
enabled = module.this.enabled
66
create_normal_instance = local.enabled && !var.serverless_enabled
77
create_serverless_instance = local.enabled && var.serverless_enabled
8+
create_parameter_group = var.global_replication_group_id == null ? var.create_parameter_group : false
9+
engine = var.global_replication_group_id == null ? var.engine : null
10+
engine_version = var.global_replication_group_id == null ? var.engine_version : null
11+
instance_type = var.global_replication_group_id == null ? var.instance_type : null
12+
num_node_groups = (var.global_replication_group_id == null && var.cluster_mode_enabled) ? var.cluster_mode_num_node_groups : null
13+
transit_encryption_enabled = var.global_replication_group_id == null ? var.transit_encryption_enabled : null
14+
at_rest_encryption_enabled = var.global_replication_group_id == null ? var.at_rest_encryption_enabled : null
15+
snapshot_arns = var.global_replication_group_id == null ? var.snapshot_arns : null
816

917
legacy_egress_rule = local.use_legacy_egress ? {
1018
key = "legacy-egress"
@@ -89,14 +97,11 @@ locals {
8997
# The name of the parameter group can’t include "."
9098
safe_family = replace(var.family, ".", "-")
9199

92-
parameter_group_name = (
93-
var.parameter_group_name != null ? var.parameter_group_name : (
94-
var.create_parameter_group
95-
?
96-
"${module.this.id}-${local.safe_family}" # The name of the new parameter group to be created
97-
:
98-
"default.${var.family}" # Default parameter group name created by AWS
99-
)
100+
parameter_group_name = var.global_replication_group_id != null ? null : coalesce(
101+
var.parameter_group_name,
102+
var.create_parameter_group ?
103+
"${module.this.id}-${local.safe_family}" # The name of the new parameter group to be created
104+
: "default.${var.family}" # Default parameter group name created by AWS
100105
)
101106

102107
arn = (
@@ -128,7 +133,7 @@ resource "aws_elasticache_subnet_group" "default" {
128133
}
129134

130135
resource "aws_elasticache_parameter_group" "default" {
131-
count = local.enabled && var.create_parameter_group ? 1 : 0
136+
count = local.enabled && local.create_parameter_group ? 1 : 0
132137
name = local.parameter_group_name
133138
description = var.parameter_group_description != null ? var.parameter_group_description : "Elasticache parameter group ${local.parameter_group_name}"
134139
family = var.family
@@ -161,7 +166,7 @@ resource "aws_elasticache_replication_group" "default" {
161166
auth_token_update_strategy = var.auth_token_update_strategy
162167
replication_group_id = var.replication_group_id == "" ? module.this.id : var.replication_group_id
163168
description = coalesce(var.description, module.this.id)
164-
node_type = var.instance_type
169+
node_type = local.instance_type
165170
num_cache_clusters = var.cluster_mode_enabled ? null : var.cluster_size
166171
port = var.port
167172
parameter_group_name = local.parameter_group_name
@@ -173,23 +178,24 @@ resource "aws_elasticache_replication_group" "default" {
173178
# It would be nice to remove null or duplicate security group IDs, if there are any, using `compact`,
174179
# but that causes problems, and having duplicates does not seem to cause problems.
175180
# See https://github.com/hashicorp/terraform/issues/29799
176-
security_group_ids = local.create_security_group ? concat(local.associated_security_group_ids, [module.aws_security_group.id]) : local.associated_security_group_ids
177-
maintenance_window = var.maintenance_window
178-
notification_topic_arn = var.notification_topic_arn
179-
engine = var.engine
180-
engine_version = var.engine_version
181-
at_rest_encryption_enabled = var.at_rest_encryption_enabled
182-
transit_encryption_enabled = var.transit_encryption_enabled
183-
transit_encryption_mode = var.transit_encryption_mode
184-
kms_key_id = var.at_rest_encryption_enabled ? var.kms_key_id : null
185-
snapshot_name = var.snapshot_name
186-
snapshot_arns = var.snapshot_arns
187-
snapshot_window = var.snapshot_window
188-
snapshot_retention_limit = var.snapshot_retention_limit
189-
final_snapshot_identifier = var.final_snapshot_identifier
190-
apply_immediately = var.apply_immediately
191-
data_tiering_enabled = var.data_tiering_enabled
192-
auto_minor_version_upgrade = var.auto_minor_version_upgrade
181+
security_group_ids = local.create_security_group ? concat(local.associated_security_group_ids, [module.aws_security_group.id]) : local.associated_security_group_ids
182+
maintenance_window = var.maintenance_window
183+
notification_topic_arn = var.notification_topic_arn
184+
engine = local.engine
185+
engine_version = local.engine_version
186+
at_rest_encryption_enabled = local.at_rest_encryption_enabled
187+
transit_encryption_enabled = local.transit_encryption_enabled
188+
transit_encryption_mode = var.transit_encryption_mode
189+
kms_key_id = var.at_rest_encryption_enabled ? var.kms_key_id : null
190+
snapshot_name = var.snapshot_name
191+
snapshot_arns = local.snapshot_arns
192+
snapshot_window = var.snapshot_window
193+
snapshot_retention_limit = var.snapshot_retention_limit
194+
final_snapshot_identifier = var.final_snapshot_identifier
195+
apply_immediately = var.apply_immediately
196+
data_tiering_enabled = var.data_tiering_enabled
197+
auto_minor_version_upgrade = var.auto_minor_version_upgrade
198+
global_replication_group_id = var.global_replication_group_id
193199

194200
dynamic "log_delivery_configuration" {
195201
for_each = var.log_delivery_configuration
@@ -204,7 +210,7 @@ resource "aws_elasticache_replication_group" "default" {
204210

205211
tags = module.this.tags
206212

207-
num_node_groups = var.cluster_mode_enabled ? var.cluster_mode_num_node_groups : null
213+
num_node_groups = local.num_node_groups
208214
replicas_per_node_group = var.cluster_mode_enabled ? var.cluster_mode_replicas_per_node_group : null
209215
user_group_ids = var.user_group_ids
210216

Diff for: variables.tf

+6-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,6 @@ variable "auto_minor_version_upgrade" {
298298
description = "Specifies whether minor version engine upgrades will be applied automatically to the underlying Cache Cluster instances during the maintenance window. Only supported if the engine version is 6 or higher."
299299
}
300300

301-
# Add boolean to create a serverless cluster
302301
variable "serverless_enabled" {
303302
type = bool
304303
default = false
@@ -334,3 +333,9 @@ variable "serverless_snapshot_arns_to_restore" {
334333
default = []
335334
description = "The list of ARN(s) of the snapshot that the new serverless cache will be created from. Available for Redis only."
336335
}
336+
337+
variable "global_replication_group_id" {
338+
type = string
339+
default = null
340+
description = "The ID of the global replication group to which this replication group should belong. If this parameter is specified, the replication group is added to the specified global replication group as a secondary replication group; otherwise, the replication group is not part of any global replication group. If global_replication_group_id is set, the num_node_groups parameter cannot be set."
341+
}

Diff for: versions.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ terraform {
44
required_providers {
55
aws = {
66
source = "hashicorp/aws"
7-
version = ">= 5.47"
7+
version = ">= 5.47.0"
88
}
99
}
1010
}

0 commit comments

Comments
 (0)