forked from cloudposse/terraform-aws-efs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
67 lines (58 loc) · 1.95 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
module "label" {
source = "git::https://github.com/cloudposse/terraform-null-label.git?ref=tags/0.14.1"
enabled = var.enabled
namespace = var.namespace
name = var.name
stage = var.stage
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
performance_mode = var.performance_mode
provisioned_throughput_in_mibps = var.provisioned_throughput_in_mibps
throughput_mode = var.throughput_mode
}
resource "aws_efs_mount_target" "default" {
count = var.enabled && length(var.availability_zones) > 0 ? length(var.availability_zones) : 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.default.*.id)]
}
resource "aws_security_group" "default" {
count = var.enabled ? 1 : 0
name = module.label.id
description = "EFS"
vpc_id = var.vpc_id
lifecycle {
create_before_destroy = true
}
ingress {
from_port = "2049" # NFS
to_port = "2049"
protocol = "tcp"
security_groups = var.security_groups
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = module.label.tags
}
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]
}