Skip to content

Commit babbada

Browse files
committed
IA-1708: Swapping volume id to fs-id+md5(path)
1 parent efbcf51 commit babbada

File tree

3 files changed

+90
-16
lines changed

3 files changed

+90
-16
lines changed

examples/efs/efs.tf

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# Configure two EFS mounts, a security group, and some mount targets
2+
3+
data "aws_vpc" "default" {
4+
default = true
5+
}
6+
data "aws_subnet_ids" "default" {
7+
vpc_id = data.aws_vpc.default.id
8+
}
9+
10+
resource "aws_security_group" "efs" {
11+
description = "easy-fargate-efs EFS"
12+
vpc_id = data.aws_vpc.default.id
13+
}
14+
15+
resource "aws_efs_file_system" "efs-one" {
16+
creation_token = "easy-fargate-efs-one"
17+
18+
tags = {
19+
Name = "easy-fargate-efs-one"
20+
}
21+
}
22+
23+
resource "aws_efs_mount_target" "efs-one" {
24+
for_each = data.aws_subnet_ids.default.ids
25+
file_system_id = aws_efs_file_system.efs-one.id
26+
subnet_id = each.key
27+
security_groups = [aws_security_group.efs.id]
28+
}
29+
30+
resource "aws_efs_file_system" "efs-two" {
31+
creation_token = "easy-fargate-efs-two"
32+
33+
tags = {
34+
Name = "easy_fargate-efs-two"
35+
}
36+
}
37+
38+
resource "aws_efs_mount_target" "efs-two" {
39+
for_each = data.aws_subnet_ids.default.ids
40+
file_system_id = aws_efs_file_system.efs-two.id
41+
subnet_id = each.key
42+
security_groups = [aws_security_group.efs.id]
43+
}

examples/efs/main.tf

+45-14
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,55 @@
1-
resource "aws_efs_file_system" "efs-task" {
2-
creation_token = "my-efs-task"
3-
4-
tags = {
5-
Name = "my-efs-task"
6-
}
7-
}
8-
91
module "efs-task" {
102
#source = "USSBA/easy-fargate/aws"
113
#version = "~> 2.0"
124
source = "../../"
135

14-
name = "my-efs-task"
15-
container_image = "ubuntu:latest"
16-
container_command = ["curl", "https://www.google.com"]
6+
name = "easy-fargate-efs-task"
7+
container_image = "ubuntu:latest"
8+
container_command = ["bash", "-cx", <<-EOT
9+
apt update;
10+
apt install tree -y;
11+
tree /mnt;
12+
touch /mnt/one_a/foo-`date -Iminutes`;
13+
tree /mnt;
14+
touch /mnt/one_b/bar-`date -Iminutes`;
15+
tree /mnt;
16+
touch /mnt/two/baz-`date -Iminutes`;
17+
tree /mnt;
18+
EOT
19+
]
1720
efs_configs = [
21+
# Mount 1: efs-one:/ => container:/mnt/one_a
22+
# Mount 2: efs-one:/ => container:/mnt/one_b
23+
# Shares a task Volume with Mount 1
24+
# Mount 3: efs-two:/ => container:/mnt/two
25+
# Container will have access to directories:
26+
# /mnt/one_a
27+
# /mnt/one_b
28+
# /mnt/two
29+
{
30+
file_system_id = aws_efs_file_system.efs-one.id
31+
root_directory = "/"
32+
container_path = "/mnt/one_a"
33+
},
34+
{
35+
file_system_id = aws_efs_file_system.efs-one.id
36+
root_directory = "/"
37+
container_path = "/mnt/one_b"
38+
},
1839
{
19-
file_system_id = aws_efs_file_system.efs-task.id
40+
file_system_id = aws_efs_file_system.efs-two.id
2041
root_directory = "/"
21-
container_path = "/mounted-efs"
22-
}
42+
container_path = "/mnt/two"
43+
},
2344
]
2445
}
46+
47+
# Allow Fargate task into EFS
48+
resource "aws_security_group_rule" "allow_fargate_into_efs" {
49+
type = "ingress"
50+
from_port = 2049
51+
to_port = 2049
52+
protocol = "tcp"
53+
security_group_id = aws_security_group.efs.id
54+
source_security_group_id = module.efs-task.security_group_ids[0]
55+
}

main.tf

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,13 @@ resource "aws_iam_role_policy" "ecs_task_execution_role_policy" {
132132

133133
locals {
134134
efs_volumes = distinct([for config in var.efs_configs : {
135-
vol_id = md5("${config.file_system_id}-${config.root_directory}")
135+
vol_id = "${config.file_system_id}-${md5(config.root_directory)}"
136136
file_system_id = config.file_system_id
137137
root_directory = config.root_directory
138138
}])
139139
efs_mountpoints = [for config in var.efs_configs : {
140140
containerPath = config.container_path
141-
sourceVolume = md5("${config.file_system_id}-${config.root_directory}")
141+
sourceVolume = "${config.file_system_id}-${md5(config.root_directory)}"
142142
readOnly = false
143143
}]
144144
}

0 commit comments

Comments
 (0)