Skip to content

fix: Handle kms_key_id for secondary global replication group with at_rest_encryption#71

Closed
PadminiSahoo wants to merge 1 commit intoterraform-aws-modules:masterfrom
PadminiSahoo:master
Closed

fix: Handle kms_key_id for secondary global replication group with at_rest_encryption#71
PadminiSahoo wants to merge 1 commit intoterraform-aws-modules:masterfrom
PadminiSahoo:master

Conversation

@PadminiSahoo
Copy link
Copy Markdown

Bug Description

When creating a secondary replication group in a Global Datastore with CMK
enabled, terraform plan fails with:

Error: Null condition
kms_key_id = var.at_rest_encryption_enabled ? var.kms_key_arn : null
var.at_rest_encryption_enabled is null

Root Cause

In main.tf line 169, kms_key_id uses var.at_rest_encryption_enabled as a
boolean condition. For secondary replication groups, this variable must be null
(AWS rejects AtRestEncryptionEnabled when global_replication_group_id is set),
so the ternary condition itself errors.

Expected Behavior

When create_secondary_global_replication_group = true, kms_key_id should
be set directly from var.kms_key_arn without checking
at_rest_encryption_enabled.

Suggested Fix

kms_key_id = var.create_secondary_global_replication_group ? var.kms_key_arn : (
var.at_rest_encryption_enabled ? var.kms_key_arn : null
)

Steps to Reproduce

  1. Create primary replication group with CMK (kms_key_arn set,
    at_rest_encryption_enabled = true)
  2. Create secondary with create_secondary_global_replication_group = true,
    global_replication_group_id set, kms_key_arn set
  3. Run terraform plan → Null condition error

…group

When creating a secondary replication group in a Global Datastore with CMK 
enabled, terraform plan fails with:

  Error: Null condition
  kms_key_id = var.at_rest_encryption_enabled ? var.kms_key_arn : null
  var.at_rest_encryption_enabled is null

## Root Cause
In main.tf line 169, kms_key_id uses var.at_rest_encryption_enabled as a 
boolean condition. For secondary replication groups, this variable must be null 
(AWS rejects AtRestEncryptionEnabled when global_replication_group_id is set), 
so the ternary condition itself errors.

## Expected Behavior
When create_secondary_global_replication_group = true, kms_key_id should 
be set directly from var.kms_key_arn without checking 
at_rest_encryption_enabled.
@PadminiSahoo PadminiSahoo changed the title fix(elasticache): handle kms_key_id for secondary global replication group along with at_rest_encryption Fix(elasticache): Handle kms_key_id for secondary global replication group with at_rest_encryption Mar 19, 2026
@PadminiSahoo PadminiSahoo changed the title Fix(elasticache): Handle kms_key_id for secondary global replication group with at_rest_encryption fix: Handle kms_key_id for secondary global replication group with at_rest_encryption Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant