-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
107 lines (94 loc) · 2.52 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# Create EFS
resource "aws_efs_file_system" "efs_storage" {
creation_token = "${var.name}-efs"
performance_mode = var.performance_mode_mode
provisioned_throughput_in_mibps = var.provisioned_throughput_in_mibps
throughput_mode = var.throughput_mode
encrypted = var.encrypted
kms_key_id = var.kms_key_id
dynamic "lifecycle_policy" {
for_each = var.lifecycle_policy
content {
transition_to_ia = lifecycle_policy.key == "transition_to_ia" ? lifecycle_policy.value : null
transition_to_primary_storage_class = lifecycle_policy.key == "transition_to_primary_storage_class" ? lifecycle_policy.value : null
}
}
tags = merge(
{
Name = var.name
},
var.tags
)
}
# Create Mount Targets for EFS
resource "aws_efs_mount_target" "efs_storage_mount_target" {
count = length(var.subnet_ids)
file_system_id = aws_efs_file_system.efs_storage.id
subnet_id = var.subnet_ids[count.index]
security_groups = [aws_security_group.nfs_sg.id]
}
# Create SG for EFS
resource "aws_security_group" "nfs_sg" {
name = "${var.name}-sg"
vpc_id = var.vpc_id
dynamic "ingress" {
for_each = length(var.whitelist_cidr) == 0 ? [] : var.whitelist_cidr
content {
cidr_blocks = var.whitelist_cidr
from_port = local.port
to_port = local.port
protocol = "tcp"
}
}
dynamic "egress" {
for_each = length(var.whitelist_cidr) == 0 ? [] : var.whitelist_cidr
content {
cidr_blocks = var.whitelist_cidr
from_port = 0
to_port = 0
protocol = "-1"
}
}
dynamic "ingress" {
for_each = length(var.whitelist_sg) == 0 ? [] : var.whitelist_sg
content {
security_groups = var.whitelist_sg
from_port = local.port
to_port = local.port
protocol = "tcp"
}
}
dynamic "egress" {
for_each = length(var.whitelist_sg) == 0 ? [] : var.whitelist_sg
content {
security_groups = var.whitelist_sg
from_port = 0
to_port = 0
protocol = "-1"
}
}
tags = merge(
{
Name = var.name
},
var.tags
)
}
resource "aws_efs_access_point" "permissions" {
count = var.create_efs_ap ? 1 : 0
file_system_id = aws_efs_file_system.efs_storage.id
root_directory {
path = "/"
creation_info {
owner_gid = var.owner_gid
owner_uid = var.owner_uid
permissions = var.root_permissions
}
}
tags = merge(
{
Name = var.name
},
var.tags
)
}