-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add EFS (elastic file system) encryption support
- Loading branch information
Umur Coskuncan | Magicorn
committed
Jun 8, 2023
1 parent
8c44ff2
commit 1926fc3
Showing
4 changed files
with
78 additions
and
1 deletion.
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,70 @@ | ||
resource "aws_kms_key" "efs" { | ||
count = (var.efs_encryption == true) ? 1 : 0 | ||
description = "${var.tenant}-${var.name}-efs-kms-${var.environment}" | ||
key_usage = var.key_usage | ||
customer_master_key_spec = var.cmk_spec | ||
deletion_window_in_days = var.deletion_window | ||
is_enabled = var.is_enabled | ||
enable_key_rotation = var.enable_key_rotation | ||
multi_region = var.multi_region | ||
|
||
policy = <<POLICY | ||
{ | ||
"Version": "2012-10-17", | ||
"Id": "auto-elasticfilesystem-1", | ||
"Statement": [ | ||
{ | ||
"Sid": "Allow access to EFS for all principals in the account that are authorized to use EFS", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"AWS": "*" | ||
}, | ||
"Action": [ | ||
"kms:Encrypt", | ||
"kms:Decrypt", | ||
"kms:ReEncrypt*", | ||
"kms:GenerateDataKey*", | ||
"kms:CreateGrant", | ||
"kms:DescribeKey" | ||
], | ||
"Resource": "*", | ||
"Condition": { | ||
"StringEquals": { | ||
"kms:ViaService": "elasticfilesystem.${data.aws_region.current.name}.amazonaws.com", | ||
"kms:CallerAccount": "${data.aws_caller_identity.current.account_id}" | ||
} | ||
} | ||
}, | ||
{ | ||
"Sid": "Allow direct access to key metadata to the account", | ||
"Effect": "Allow", | ||
"Principal": { | ||
"AWS": [ | ||
"arn:aws:iam::${data.aws_caller_identity.current.account_id}:root", | ||
"${data.aws_caller_identity.current.arn}" | ||
] | ||
}, | ||
"Action": [ | ||
"kms:*" | ||
], | ||
"Resource": "*" | ||
} | ||
] | ||
} | ||
POLICY | ||
|
||
tags = { | ||
Name = "${var.tenant}-${var.name}-efs-kms-${var.environment}" | ||
Tenant = var.tenant | ||
Project = var.name | ||
Environment = var.environment | ||
Maintainer = "Magicorn" | ||
Terraform = "yes" | ||
} | ||
} | ||
|
||
resource "aws_kms_alias" "efs" { | ||
count = (var.efs_encryption == true) ? 1 : 0 | ||
name = "alias/${var.tenant}/${var.name}/efs/${var.environment}" | ||
target_key_id = aws_kms_key.efs[0].key_id | ||
} |
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