generated from dxw/terraform-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Conditionally create EFS for ECS cluster
* Conditionally creates an EFS file system. This can be used as a shared filesystem between the container instances. * If the ECS cluster has been enabled, it will mount the EFS file system onto the instances at `/mnt/efs` * A list of directories can be provided, which will be created within the EFS file system * A security group is added that allows access from the ECS container instances security group. A rule is also added to the ECS container instances securit group to allow outbound to the EFS security group.
- Loading branch information
Showing
6 changed files
with
118 additions
and
0 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
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,48 @@ | ||
resource "aws_efs_file_system" "infrastructure_ecs_cluster" { | ||
count = local.enable_infrastructure_ecs_cluster_efs ? 1 : 0 | ||
|
||
encrypted = local.infrastructure_kms_encryption | ||
kms_key_id = local.infrastructure_kms_encryption ? aws_kms_key.infrastructure[0].id : null | ||
performance_mode = local.ecs_cluster_efs_performance_mode | ||
throughput_mode = local.ecs_cluster_efs_throughput_mode | ||
|
||
dynamic "lifecycle_policy" { | ||
for_each = local.ecs_cluster_efs_infrequent_access_transition != 0 ? [1] : [] | ||
content { | ||
transition_to_ia = local.ecs_cluster_efs_infrequent_access_transition | ||
transition_to_primary_storage_class = "AFTER_1_ACCESS" | ||
} | ||
} | ||
} | ||
|
||
resource "aws_efs_mount_target" "infrastructure_ecs_cluster" { | ||
for_each = local.enable_infrastructure_ecs_cluster_efs ? local.infrastructure_vpc_network_enable_private ? [ | ||
for subnet in aws_subnet.infrastructure_private : subnet.id | ||
] : local.infrastructure_vpc_network_enable_public ? [ | ||
for subnet in aws_subnet.infrastructure_private : subnet.id | ||
] : [] : [] | ||
|
||
file_system_id = aws_efs_file_system.infrastructure_ecs_cluster[0].id | ||
subnet_id = each.value | ||
security_groups = local.enable_infrastructure_ecs_cluster ? [aws_security_group.infrastructure_ecs_cluster_efs[0].id] : [] | ||
} | ||
|
||
resource "aws_security_group" "infrastructure_ecs_cluster_efs" { | ||
count = local.enable_infrastructure_ecs_cluster_efs && local.enable_infrastructure_ecs_cluster ? 1 : 0 | ||
|
||
name = "${local.resource_prefix}-infrastructure-ecs-cluster-efs" | ||
description = "Infrastructure ECS cluster EFS" | ||
vpc_id = aws_vpc.infrastructure[0].id | ||
} | ||
|
||
resource "aws_security_group_rule" "infrastructure_ecs_cluster_efs_ingress_nfs_tcp" { | ||
count = local.enable_infrastructure_ecs_cluster_efs && local.enable_infrastructure_ecs_cluster ? 1 : 0 | ||
|
||
description = "Allow ECS instances access to EFS (NFS) tcp" | ||
type = "ingress" | ||
from_port = 2049 | ||
to_port = 2049 | ||
protocol = "tcp" | ||
source_security_group_id = aws_security_group.infrastructure_ecs_cluster_container_instances[0].id | ||
security_group_id = aws_security_group.infrastructure_ecs_cluster_efs[0].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