-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsecurity-group.tf
105 lines (89 loc) · 2.95 KB
/
security-group.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
resource "aws_security_group" "lb" {
name = "${var.name}-nlb-internal"
description = "Security Group RabbitMQ Cluster (nlb internal)"
vpc_id = local.vpc_id
egress {
cidr_blocks = ["0.0.0.0/0"]
protocol = "-1"
from_port = 0
to_port = 0
description = "Enable All Internet Traffic"
}
tags = merge(var.default_tags, {
Account = local.account_alias
Name = var.name
})
lifecycle {
ignore_changes = [ingress]
}
}
resource "aws_security_group" "main" {
name = var.name
description = "Security Group RabbitMQ Cluster"
vpc_id = local.vpc_id
egress {
cidr_blocks = ["0.0.0.0/0"]
protocol = "-1"
from_port = 0
to_port = 0
description = "Enable All Internet Traffic"
}
tags = merge(var.default_tags, {
Account = local.account_alias
Name = var.name
})
lifecycle {
ignore_changes = [ingress]
}
}
### internal comm between nodes from cluster
resource "aws_security_group_rule" "enable_internal_comm" {
type = "ingress"
security_group_id = aws_security_group.main.id
self = true
protocol = "-1"
from_port = 0
to_port = 0
description = "Allow inter node traffic"
}
### internal comm between nlb and ec2
resource "aws_security_group_rule" "enable_ports_to_internal_nlb" {
for_each = local.rabbit_service_ports
type = "ingress"
security_group_id = aws_security_group.main.id
source_security_group_id = aws_security_group.lb.id
protocol = "tcp"
from_port = each.value.port
to_port = each.value.port
description = "Allow traffic to rabbitmq - from inner VPC to internal nlb - ${each.key}"
}
### internal comm between nlb and local vpc
resource "aws_security_group_rule" "enable_ports_vpc" {
for_each = local.nlb_listener_ports
type = "ingress"
security_group_id = aws_security_group.lb.id
cidr_blocks = [local.vpc_cidr]
protocol = "tcp"
from_port = each.value.port
to_port = each.value.port
description = "Allow traffic to rabbitmq - from inner VPC - ${each.key}"
}
#### security group for efs mount
resource "aws_security_group" "efs" {
name = "${var.name}-efs"
description = "Security Group EFS File system for rabbit cluster"
vpc_id = local.vpc_id
tags = merge(var.default_tags, {
Account = local.account_alias
Name = "${var.name}-efs"
})
}
resource "aws_security_group_rule" "enable_comm_from_rabbit_cluster" {
type = "ingress"
security_group_id = aws_security_group.efs.id
source_security_group_id = aws_security_group.main.id
protocol = "TCP"
from_port = 2049 # efs mount port
to_port = 2049 # efs mount port
description = "Allow traffic to rabbitmq instances"
}