Skip to content

Commit dcb1f24

Browse files
committed
Add managed storage encryption
1 parent 6ce1780 commit dcb1f24

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

README.md

+5-4
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ performance and health.
4747
| <a name="input_enable_container_insights"></a> [enable\_container\_insights](#input\_enable\_container\_insights) | Enable CloudWatch Container Insights for the cluster. | `bool` | `true` | no |
4848
| <a name="input_encrypt_ephemeral_storage"></a> [encrypt\_ephemeral\_storage](#input\_encrypt\_ephemeral\_storage) | Encrypt the ECS ephemeral storage for the cluster. | `bool` | `false` | no |
4949
| <a name="input_encrypt_execute_command_session"></a> [encrypt\_execute\_command\_session](#input\_encrypt\_execute\_command\_session) | Encrypt execute command session for the cluster. | `bool` | `false` | no |
50+
| <a name="input_encrypt_managed_storage"></a> [encrypt\_managed\_storage](#input\_encrypt\_managed\_storage) | Encrypt the ECS managed storage for the cluster. | `bool` | `false` | no |
5051
| <a name="input_logging_execute_command_session"></a> [logging\_execute\_command\_session](#input\_logging\_execute\_command\_session) | Log execute command session for the cluster. | `string` | `"DEFAULT"` | no |
5152
| <a name="input_name"></a> [name](#input\_name) | Name of the ECS cluster. | `string` | n/a | yes |
5253
| <a name="input_tags"></a> [tags](#input\_tags) | Tags to add to the ECS cluster. | `map(any)` | `{}` | no |
@@ -68,11 +69,11 @@ performance and health.
6869

6970
## Resources
7071

71-
- resource.aws_cloudwatch_log_group.container_insights (main.tf#75)
72-
- resource.aws_cloudwatch_log_group.main (main.tf#68)
72+
- resource.aws_cloudwatch_log_group.container_insights (main.tf#80)
73+
- resource.aws_cloudwatch_log_group.main (main.tf#73)
7374
- resource.aws_ecs_cluster.main (main.tf#10)
74-
- data source.aws_caller_identity.current (main.tf#95)
75-
- data source.aws_iam_policy_document.kms_ephemeral (main.tf#96)
75+
- data source.aws_caller_identity.current (main.tf#100)
76+
- data source.aws_iam_policy_document.kms_ephemeral (main.tf#101)
7677

7778
# Examples
7879
### Basic Example

main.tf

+12-7
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,13 @@ resource "aws_ecs_cluster" "main" {
1919
}
2020
}
2121

22-
2322
dynamic "configuration" {
24-
for_each = var.encrypt_execute_command_session || var.logging_execute_command_session != "DEFAULT" ? [true] : []
23+
for_each = (
24+
var.encrypt_execute_command_session ||
25+
var.logging_execute_command_session != "DEFAULT" ||
26+
var.encrypt_ephemeral_storage ||
27+
var.encrypt_managed_storage
28+
) ? [true] : []
2529

2630
content {
2731
dynamic "execute_command_configuration" {
@@ -43,10 +47,11 @@ resource "aws_ecs_cluster" "main" {
4347
}
4448

4549
dynamic "managed_storage_configuration" {
46-
for_each = var.encrypt_ephemeral_storage ? [true] : []
50+
for_each = var.encrypt_ephemeral_storage || var.encrypt_managed_storage ? [true] : []
4751

4852
content {
49-
fargate_ephemeral_storage_kms_key_id = module.kms_ephemeral[0].key_id
53+
kms_key_id = var.encrypt_managed_storage ? module.kms[0].key_id : null
54+
fargate_ephemeral_storage_kms_key_id = var.encrypt_ephemeral_storage ? module.kms_ephemeral[0].key_id : null
5055
}
5156
}
5257
}
@@ -82,19 +87,19 @@ resource "aws_cloudwatch_log_group" "container_insights" {
8287
}
8388

8489
module "kms_ephemeral" {
85-
count = var.encrypt_ephemeral_storage ? 1 : 0
90+
count = var.encrypt_ephemeral_storage || var.encrypt_managed_storage ? 1 : 0
8691

8792
source = "geekcell/kms/aws"
8893
version = ">= 1.0.0, < 2.0.0"
8994
policy = data.aws_iam_policy_document.kms_ephemeral[0].json
9095

91-
alias = "ecs/cluster/${var.name}/ephemeral-storage"
96+
alias = "ecs/cluster/${var.name}/managed-storage"
9297
tags = var.tags
9398
}
9499

95100
data "aws_caller_identity" "current" {}
96101
data "aws_iam_policy_document" "kms_ephemeral" {
97-
count = var.encrypt_ephemeral_storage ? 1 : 0
102+
count = var.encrypt_ephemeral_storage || var.encrypt_managed_storage ? 1 : 0
98103

99104
statement {
100105
sid = "Enable IAM User Permissions."

variables.tf

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ variable "encrypt_ephemeral_storage" {
2929
type = bool
3030
}
3131

32+
variable "encrypt_managed_storage" {
33+
description = "Encrypt the ECS managed storage for the cluster."
34+
default = false
35+
type = bool
36+
}
37+
3238
variable "logging_execute_command_session" {
3339
description = "Log execute command session for the cluster."
3440
default = "DEFAULT"

0 commit comments

Comments
 (0)