diff --git a/main.tf b/main.tf index 7951697..43293f2 100644 --- a/main.tf +++ b/main.tf @@ -253,7 +253,7 @@ resource "aws_kms_alias" "this" { name = var.aliases_use_name_prefix ? null : "alias/${each.value}" name_prefix = var.aliases_use_name_prefix ? "alias/${each.value}-" : null - target_key_id = aws_kms_key.this[0].id + target_key_id = var.create_external ? aws_kms_external_key.this[0].id : aws_kms_key.this[0].key_id } ################################################################################ @@ -264,7 +264,7 @@ resource "aws_kms_grant" "this" { for_each = { for k, v in var.grants : k => v if var.create } name = try(each.value.name, each.key) - key_id = aws_kms_key.this[0].key_id + key_id = var.create_external ? aws_kms_external_key.this[0].id : aws_kms_key.this[0].key_id grantee_principal = each.value.grantee_principal operations = each.value.operations