Skip to content

Commit 2d3c633

Browse files
authored
Merge pull request #84 from NHSDigital/feature/CCM-10231_kms
CCM-10231: Enable support for multi-region KMS key
2 parents 688e630 + 9f8152c commit 2d3c633

6 files changed

Lines changed: 31 additions & 1 deletion

File tree

infrastructure/modules/kms/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
| <a name="input_deletion_window"></a> [deletion\_window](#input\_deletion\_window) | KMS key deletion window | `string` | n/a | yes |
1919
| <a name="input_environment"></a> [environment](#input\_environment) | The name of the terraformscaffold environment the module is called for | `string` | n/a | yes |
2020
| <a name="input_iam_delegation"></a> [iam\_delegation](#input\_iam\_delegation) | Whether to delegate administration of the key to the local account. Defaults to true | `bool` | `true` | no |
21+
| <a name="input_is_multi_region"></a> [is\_multi\_region](#input\_is\_multi\_region) | Whether the KMS key is a multi-region key, where secondary region would mostly be us-east-1. Defaults to false | `bool` | `false` | no |
2122
| <a name="input_key_policy_documents"></a> [key\_policy\_documents](#input\_key\_policy\_documents) | List of KMS key policy JSON documents | `list(string)` | `[]` | no |
2223
| <a name="input_name"></a> [name](#input\_name) | A unique name to distinguish this module invocation from others within the same CSI scope | `string` | n/a | yes |
2324
| <a name="input_project"></a> [project](#input\_project) | The name of the terraformscaffold project calling the module | `string` | n/a | yes |
@@ -32,6 +33,8 @@ No modules.
3233
| <a name="output_admin_policy_arn"></a> [admin\_policy\_arn](#output\_admin\_policy\_arn) | ARN of the admin IAM policy |
3334
| <a name="output_key_arn"></a> [key\_arn](#output\_key\_arn) | ARN of the KMS key |
3435
| <a name="output_key_id"></a> [key\_id](#output\_key\_id) | ID of the KMS key |
36+
| <a name="output_replica_key_arn"></a> [replica\_key\_arn](#output\_replica\_key\_arn) | ARN of the Replica KMS key |
37+
| <a name="output_replica_key_id"></a> [replica\_key\_id](#output\_replica\_key\_id) | ID of the Replica KMS key |
3538
| <a name="output_user_policy_arn"></a> [user\_policy\_arn](#output\_user\_policy\_arn) | ARN of the user IAM policy |
3639
<!-- vale on -->
3740
<!-- markdownlint-enable -->

infrastructure/modules/kms/kms_key.tf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ resource "aws_kms_key" "main" {
33
deletion_window_in_days = var.deletion_window
44
description = local.csi
55
enable_key_rotation = true
6+
multi_region = var.is_multi_region
67
policy = data.aws_iam_policy_document.key.json
78
tags = local.default_tags
89
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
resource "aws_kms_replica_key" "replica" {
2+
provider = aws.us-east-1
3+
count = var.is_multi_region ? 1 : 0
4+
5+
description = "Multi-Region replica key"
6+
deletion_window_in_days = var.deletion_window
7+
policy = data.aws_iam_policy_document.key.json
8+
primary_key_arn = aws_kms_key.main.arn
9+
}

infrastructure/modules/kms/outputs.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,13 @@ output "user_policy_arn" {
1717
description = "ARN of the user IAM policy"
1818
value = aws_iam_policy.user.arn
1919
}
20+
21+
output "replica_key_arn" {
22+
description = "ARN of the Replica KMS key"
23+
value = try(aws_kms_replica_key.replica[0].arn, null)
24+
}
25+
26+
output "replica_key_id" {
27+
description = "ID of the Replica KMS key"
28+
value = try(aws_kms_replica_key.replica[0].key_id, null)
29+
}

infrastructure/modules/kms/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,9 @@ variable "iam_delegation" {
6666
description = "Whether to delegate administration of the key to the local account. Defaults to true"
6767
default = true
6868
}
69+
70+
variable "is_multi_region" {
71+
type = bool
72+
description = "Whether the KMS key is a multi-region key, where secondary region would mostly be us-east-1. Defaults to false"
73+
default = false
74+
}

infrastructure/modules/kms/versions.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
terraform {
33
required_providers {
44
aws = {
5-
source = "hashicorp/aws"
5+
source = "hashicorp/aws"
6+
configuration_aliases = [aws.us-east-1]
67
}
78
}
89
required_version = ">= 1.9.0"

0 commit comments

Comments
 (0)