I created a Primary Replication Group in Elasticache and registered it in the global replication group. Up to this point, there was no problem at all.
However, when creating and registering a Secondary Replication Group, I encountered a situation where I could not activate the Multi-AZ option.
To activate the Multi-AZ option, you need to set automatic_failover_enabled = true
.
However, if you specify this option in the Secondary Replication Group Resource, it conflicts with the global_replication_group_id
option.
How can I activate Multi-AZ in the Secondary Replication Group as well?
# Elasticache Global Datastore
# ========================================================
resource "aws_elasticache_global_replication_group" "global_datastore" {
provider = aws.primary
global_replication_group_id_suffix = var.cache.global.name_suffix
primary_replication_group_id = aws_elasticache_replication_group.primary-elasticache.id
engine_version = var.cache.global.engine_version
}
# Primary Elasticache
# ========================================================
resource "aws_elasticache_replication_group" "primary-elasticache" {
provider = aws.primary
replication_group_id = var.cache.primary.name
description = "Elasticache ${var.cache.primary.name}"
engine = var.cache.primary.engine
engine_version = var.cache.primary.engine_version
cluster_mode = "enabled"
node_type = var.cache.primary.node_type
num_node_groups = var.cache.primary.nodegroup_count
replicas_per_node_group = var.cache.primary.replicas_per_nodegroup
port = var.cache.primary.port
subnet_group_name = aws_elasticache_subnet_group.primary_cache_subnet_group.name
security_group_ids = [aws_security_group.primary_cache_security_group.id]
multi_az_enabled = true
automatic_failover_enabled = true
at_rest_encryption_enabled = true
kms_key_id = aws_kms_key.primary-elasticache-cmk.id
transit_encryption_enabled = true
transit_encryption_mode = "required"
snapshot_retention_limit = var.cache.primary.snapshot_retention_limit
log_delivery_configuration {
log_type = "slow-log"
log_format = "json"
destination_type = "cloudwatch-logs"
destination = aws_cloudwatch_log_group.primary_slow-log-log_group.name
}
log_delivery_configuration {
log_type = "engine-log"
log_format = "json"
destination_type = "cloudwatch-logs"
destination = aws_cloudwatch_log_group.primary_engine-log-log_group.name
}
apply_immediately = true
}
# Secondary Elasticache
# ========================================================
resource "aws_elasticache_replication_group" "secondary-elasticache" {
provider = aws.secondary
global_replication_group_id = aws_elasticache_global_replication_group.global_datastore.id
replication_group_id = var.cache.secondary.name
description = "Elasticache ${var.cache.secondary.name}"
subnet_group_name = aws_elasticache_subnet_group.secondary_cache_subnet_group.name
security_group_ids = [aws_security_group.secondary_cache_security_group.id]
port = var.cache.secondary.port
kms_key_id = aws_kms_key.secondary-elasticache-cmk.id
snapshot_retention_limit = var.cache.secondary.snapshot_retention_limit
log_delivery_configuration {
log_type = "slow-log"
log_format = "json"
destination_type = "cloudwatch-logs"
destination = aws_cloudwatch_log_group.secondary_slow-log-log_group.name
}
log_delivery_configuration {
log_type = "engine-log"
log_format = "json"
destination_type = "cloudwatch-logs"
destination = aws_cloudwatch_log_group.secondary_engine-log-log_group.name
}
apply_immediately = true
}