-
Notifications
You must be signed in to change notification settings - Fork 1
/
security_group.tf
74 lines (65 loc) · 1.9 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
resource "aws_security_group" "main_sg" {
name = var.application_name
description = "Allows traffic from load balancer"
vpc_id = var.vpc_id
ingress {
description = ""
from_port = 0
to_port = 0
protocol = "-1"
security_groups = [var.alb_security_group_id]
cidr_blocks = []
ipv6_cidr_blocks = []
prefix_list_ids = []
self = false
}
egress {
description = ""
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
prefix_list_ids = []
security_groups = []
self = false
}
tags = {
Name = var.application_name
Environment = var.environment_name
}
}
#
# INGRESS SECURITY GROUPS RULES
#
data "aws_security_group" "ingress_sg" {
count = length(var.ingress_security_groups)
name = var.ingress_security_groups[count.index]
}
resource "aws_security_group_rule" "local_ingress_traffic" {
count = length(data.aws_security_group.ingress_sg)
type = "ingress"
from_port = 0
to_port = 65535
protocol = "tcp"
source_security_group_id = data.aws_security_group.ingress_sg[count.index].id
prefix_list_ids = []
security_group_id = aws_security_group.main_sg.id
}
#
# REMOTE SECURITY GROUPS
#
data "aws_security_group" "remote_sg" {
count = length(var.remote_ingress_security_groups)
name = var.remote_ingress_security_groups[count.index]
}
resource "aws_security_group_rule" "remote_ingress_traffic" {
count = length(data.aws_security_group.remote_sg)
type = "ingress"
from_port = 0
to_port = 65535
protocol = "tcp"
source_security_group_id = aws_security_group.main_sg.id
prefix_list_ids = []
security_group_id = data.aws_security_group.remote_sg[count.index].id
}