forked from cloudposse/terraform-aws-efs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
82 lines (72 loc) · 2.62 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
module "label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.16.0"
enabled = var.enabled
namespace = var.namespace
name = var.name
stage = var.stage
environment = var.environment
delimiter = var.delimiter
attributes = var.attributes
tags = var.tags
}
locals {
dns_name = "${join("", aws_efs_file_system.default.*.id)}.efs.${var.region}.amazonaws.com"
}
resource "aws_efs_file_system" "default" {
count = var.enabled ? 1 : 0
tags = module.label.tags
encrypted = var.encrypted
kms_key_id = var.kms_key_id
performance_mode = var.performance_mode
provisioned_throughput_in_mibps = var.provisioned_throughput_in_mibps
throughput_mode = var.throughput_mode
dynamic "lifecycle_policy" {
for_each = var.transition_to_ia == "" ? [] : [1]
content {
transition_to_ia = var.transition_to_ia
}
}
}
resource "aws_efs_mount_target" "default" {
count = var.enabled && length(var.subnets) > 0 ? length(var.subnets) : 0
file_system_id = join("", aws_efs_file_system.default.*.id)
ip_address = var.mount_target_ip_address
subnet_id = var.subnets[count.index]
security_groups = [join("", aws_security_group.efs.*.id)]
}
resource "aws_security_group" "efs" {
count = var.enabled ? 1 : 0
name = format("%s-efs", module.label.id)
description = "EFS Security Group"
vpc_id = var.vpc_id
lifecycle {
create_before_destroy = true
}
tags = module.label.tags
}
resource "aws_security_group_rule" "ingress" {
count = var.enabled ? length(var.security_groups) : 0
type = "ingress"
from_port = "2049" # NFS
to_port = "2049"
protocol = "tcp"
source_security_group_id = var.security_groups[count.index]
security_group_id = join("", aws_security_group.efs.*.id)
}
resource "aws_security_group_rule" "egress" {
count = var.enabled ? 1 : 0
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = join("", aws_security_group.efs.*.id)
}
module "dns" {
source = "git::https://github.com/cloudposse/terraform-aws-route53-cluster-hostname.git?ref=tags/0.3.0"
enabled = var.enabled && length(var.zone_id) > 0 ? true : false
name = var.dns_name == "" ? module.label.id : var.dns_name
ttl = 60
zone_id = var.zone_id
records = [local.dns_name]
}