Skip to content

Commit e3d73ee

Browse files
vyrwuclaude
andcommitted
feat: Allow overriding Performance Insights KMS key
Add performance_insights_kms_key_arn variable to allow specifying a custom KMS key ARN for Performance Insights encryption. When null (default), falls back to the component's RDS CMK. This is needed when a cluster was initially created with PI disabled (or with a different KMS key), and PI is later enabled via Terraform. In that scenario, the cluster already has a PI KMS key assigned by AWS (typically the default aws/rds managed key), and the component unconditionally tries to set the RDS CMK — which AWS rejects because PI KMS keys cannot be changed after cluster creation. The new variable allows users to pass the ARN of the key already in use, preventing the InvalidParameterCombination error: "You can't change your Performance Insights KMS key." Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 4cdb023 commit e3d73ee

2 files changed

Lines changed: 7 additions & 1 deletion

File tree

src/cluster-regional.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ module "aurora_postgres_cluster" {
3434
storage_encrypted = var.storage_encrypted
3535
storage_type = var.storage_type
3636
kms_key_arn = var.storage_encrypted ? module.kms_key_rds.key_arn : null
37-
performance_insights_kms_key_id = var.performance_insights_enabled ? module.kms_key_rds.key_arn : null
37+
performance_insights_kms_key_id = var.performance_insights_enabled ? coalesce(var.performance_insights_kms_key_arn, module.kms_key_rds.key_arn) : null
3838
maintenance_window = var.maintenance_window
3939
enabled_cloudwatch_logs_exports = var.enabled_cloudwatch_logs_exports
4040
enhanced_monitoring_role_enabled = var.enhanced_monitoring_role_enabled

src/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ variable "performance_insights_enabled" {
200200
description = "Whether to enable Performance Insights"
201201
}
202202

203+
variable "performance_insights_kms_key_arn" {
204+
type = string
205+
default = null
206+
description = "ARN of the KMS key for Performance Insights encryption. If null, defaults to the RDS CMK."
207+
}
208+
203209
variable "database_insights_mode" {
204210
type = string
205211
description = "The database insights mode for the RDS cluster. Valid values are `standard`, `advanced`. See https://registry.terraform.io/providers/hashicorp/aws/6.16.0/docs/resources/rds_cluster#database_insights_mode-1"

0 commit comments

Comments
 (0)