-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MLPAB-2202 - Refactor KMS resources into a module (#1333)
* createe a module to creatre kms keys * output alias name from module * use module for cloudwatch kms key
- Loading branch information
1 parent
402a2c8
commit e82646e
Showing
8 changed files
with
116 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
data "aws_default_tags" "current" { | ||
provider = aws.eu_west_1 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
resource "aws_kms_key" "main" { | ||
description = "${data.aws_default_tags.current.tags.application} ${var.encrypted_resource} encryption key" | ||
deletion_window_in_days = var.deletion_window_in_days | ||
enable_key_rotation = var.enable_key_rotation | ||
policy = var.kms_key_policy | ||
multi_region = var.enable_multi_region | ||
provider = aws.eu_west_1 | ||
} | ||
|
||
resource "aws_kms_replica_key" "main" { | ||
description = "${data.aws_default_tags.current.tags.application} ${var.encrypted_resource} multi-region replica key" | ||
deletion_window_in_days = var.deletion_window_in_days | ||
primary_key_arn = aws_kms_key.main.arn | ||
policy = var.kms_key_policy | ||
provider = aws.eu_west_2 | ||
} | ||
|
||
resource "aws_kms_alias" "main_eu_west_1" { | ||
name = "alias/${var.kms_key_alias_name}" | ||
target_key_id = aws_kms_key.main.key_id | ||
provider = aws.eu_west_1 | ||
} | ||
|
||
resource "aws_kms_alias" "main_eu_west_2" { | ||
name = "alias/${var.kms_key_alias_name}" | ||
target_key_id = aws_kms_replica_key.main.key_id | ||
provider = aws.eu_west_2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
output "kms_key_alias_name" { | ||
value = aws_kms_alias.main_eu_west_1.name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
variable "kms_key_policy" { | ||
type = string | ||
description = "Policy json to attach to the KMS key and replica key." | ||
} | ||
|
||
variable "encrypted_resource" { | ||
type = string | ||
description = "The resource that will be encrypted by the KMS key." | ||
} | ||
|
||
variable "kms_key_alias_name" { | ||
type = string | ||
description = "The alias name for the KMS key." | ||
} | ||
|
||
variable "enable_key_rotation" { | ||
type = bool | ||
description = "Whether to enable key rotation for the KMS key." | ||
default = true | ||
} | ||
|
||
variable "enable_multi_region" { | ||
type = bool | ||
description = "Whether to enable multi-region replication for the KMS key." | ||
default = true | ||
} | ||
|
||
variable "deletion_window_in_days" { | ||
type = number | ||
description = "The number of days to retain the KMS key before it is deleted." | ||
default = 10 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
terraform { | ||
required_providers { | ||
aws = { | ||
source = "hashicorp/aws" | ||
version = "~> 5.57.0" | ||
configuration_aliases = [ | ||
aws.eu_west_1, | ||
aws.eu_west_2, | ||
] | ||
} | ||
pagerduty = { | ||
source = "PagerDuty/pagerduty" | ||
version = "3.14.5" | ||
} | ||
} | ||
required_version = "1.9.1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters