|
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 |
| - |
9 | 1 | module "efs-task" {
|
10 | 2 | #source = "USSBA/easy-fargate/aws"
|
11 | 3 | #version = "~> 2.0"
|
12 | 4 | source = "../../"
|
13 | 5 |
|
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 | + ] |
17 | 20 | 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 | + }, |
18 | 39 | {
|
19 |
| - file_system_id = aws_efs_file_system.efs-task.id |
| 40 | + file_system_id = aws_efs_file_system.efs-two.id |
20 | 41 | root_directory = "/"
|
21 |
| - container_path = "/mounted-efs" |
22 |
| - } |
| 42 | + container_path = "/mnt/two" |
| 43 | + }, |
23 | 44 | ]
|
24 | 45 | }
|
| 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 | +} |
0 commit comments