-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmain.tf
59 lines (52 loc) · 1.57 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
locals {
id = "${replace(var.name, " ", "-")}"
}
# ----------------------------------------
# CREATE AND MOUNT EFS
# ----------------------------------------
resource "aws_efs_file_system" "this" {
creation_token = "${local.id}"
tags = "${merge(var.tags, map("Name", var.name))}"
encrypted = true
dynamic "lifecycle_policy" {
for_each = var.efs_transition_to_ia != "" ? list(var.efs_transition_to_ia) : []
content {
transition_to_ia = "${var.efs_transition_to_ia}"
}
}
}
# Security group EFS access
resource "aws_security_group" "this" {
name = "${local.id}-EFS"
description = "Access to ports EFS (2049)"
vpc_id = "${var.vpc_id}"
ingress {
from_port = 2049
to_port = 2049
protocol = "tcp"
security_groups = "${var.access_sg_ids}"
description = "Open to incoming EFS traffic from App instances"
}
ingress {
from_port = 111
to_port = 111
protocol = "tcp"
security_groups = "${var.access_sg_ids}"
description = "Open to incoming EFS traffic from App instances"
}
egress {
from_port = 0
to_port = 0
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
description = "Open to all outgoing traffic"
}
tags = "${merge(var.tags, map("Name", "${var.name} EFS"))}"
}
#Terraform Does not support an array for "subnet_id" by now create 3 targets should be used instead.
resource "aws_efs_mount_target" "this" {
count = "${length(var.subnets)}"
file_system_id = "${aws_efs_file_system.this.id}"
subnet_id = "${element(var.subnets, count.index)}"
security_groups = ["${aws_security_group.this.id}"]
}