-
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.
feat: add ability to mount EFS volume in app containers
This is useful for debugging, like in the case where we would want to persist some generated data on instance stop like a heap dump. A single EFS volume for the entire stack was chosen instead of volume per service as ECS containers can only allow 1 EFS volume mount, so with a single mount, all of the various container's EFS data can be read from the bigeye-admin container. EFS access point per service gives us logical separation of data between the different services, so each service can only read/write its own data (except the admin container which can mount the root "/" so will see them all). Also note it is not possible to disable AZ redundancy by using "one zone" mode to save on costs as we run into problems with EFS mount points not existing in the various AZ's since we don't allow constraining ECS tasks to a single AZ.
- Loading branch information
Showing
10 changed files
with
296 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
resource "aws_security_group" "efs" { | ||
count = var.create_security_groups && local.efs_volume_enabled ? 1 : 0 | ||
name = "${local.name}-efs" | ||
vpc_id = local.vpc_id | ||
|
||
tags = merge(local.tags, { | ||
Name = local.name | ||
}) | ||
} | ||
|
||
resource "aws_vpc_security_group_ingress_rule" "efs" { | ||
count = var.create_security_groups && local.efs_volume_enabled ? 1 : 0 | ||
description = "Allow NFS" | ||
security_group_id = aws_security_group.efs[0].id | ||
from_port = 2049 # NFS | ||
to_port = 2049 # NFS | ||
ip_protocol = "TCP" | ||
cidr_ipv4 = var.vpc_cidr_block | ||
} | ||
|
||
resource "aws_efs_file_system" "this" { | ||
count = local.efs_volume_enabled ? 1 : 0 | ||
throughput_mode = "elastic" | ||
encrypted = true | ||
lifecycle_policy { | ||
transition_to_ia = "AFTER_7_DAYS" | ||
} | ||
tags = merge(local.tags, { | ||
Name = local.name | ||
}) | ||
} | ||
|
||
resource "aws_efs_file_system_policy" "this" { | ||
count = local.efs_volume_enabled ? 1 : 0 | ||
file_system_id = aws_efs_file_system.this[0].id | ||
policy = jsonencode( | ||
{ | ||
"Version" : "2012-10-17", | ||
"Statement" : [ | ||
{ | ||
"Sid" : "allow-root-access", | ||
"Effect" : "Allow", | ||
"Principal" : { | ||
"AWS" : "*" | ||
}, | ||
"Action" : [ | ||
"elasticfilesystem:ClientRootAccess", | ||
"elasticfilesystem:ClientWrite", | ||
"elasticfilesystem:ClientMount" | ||
], | ||
"Resource" : aws_efs_file_system.this[0].arn, | ||
"Condition" : { | ||
"Bool" : { | ||
"elasticfilesystem:AccessedViaMountTarget" : "true" | ||
} | ||
} | ||
}, | ||
{ | ||
"Sid" : "deny-unencrypted-transport", | ||
"Effect" : "Deny", | ||
"Principal" : { | ||
"AWS" : "*" | ||
}, | ||
"Action" : "*", | ||
"Resource" : aws_efs_file_system.this[0].arn, | ||
"Condition" : { | ||
"Bool" : { | ||
"aws:SecureTransport" : "false" | ||
} | ||
} | ||
} | ||
] | ||
} | ||
|
||
) | ||
} | ||
|
||
resource "aws_efs_mount_target" "this" { | ||
for_each = local.efs_volume_enabled ? toset(local.application_subnet_ids) : [] | ||
file_system_id = aws_efs_file_system.this[0].id | ||
subnet_id = each.value | ||
security_groups = concat(var.efs_volume_extra_security_group_ids, [one(aws_security_group.efs[*].id)]) | ||
} | ||
|
||
resource "aws_efs_access_point" "bigeye_admin" { | ||
count = local.efs_volume_enabled && var.enable_bigeye_admin_module ? 1 : 0 | ||
file_system_id = aws_efs_file_system.this[0].id | ||
root_directory { | ||
path = "/" | ||
} | ||
tags = merge(local.tags, { | ||
Name = "${local.name}-bigeye-admin" | ||
app = "bigeye-admin" | ||
}) | ||
} | ||
|
||
resource "aws_efs_access_point" "this" { | ||
for_each = local.efs_volume_enabled ? toset(var.efs_volume_enabled_services) : [] | ||
file_system_id = aws_efs_file_system.this[0].id | ||
root_directory { | ||
creation_info { | ||
owner_gid = 0 | ||
owner_uid = 0 | ||
permissions = "777" | ||
} | ||
path = "/${each.value}" | ||
} | ||
tags = merge(local.tags, { | ||
Name = "${local.name}-${each.value}" | ||
app = each.value | ||
}) | ||
} |
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
Oops, something went wrong.