-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecurity_group.tf
48 lines (40 loc) · 1.07 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
# Security group
resource "aws_security_group" "mv_sg_for_elb" {
name = "ELB Security Group"
vpc_id = aws_vpc.my_vpc.id
# Allow only http(80) and https(443)
dynamic "ingress" {
for_each = var.sg_ports_for_internet
content {
from_port = ingress.value
to_port = ingress.value
protocol = "tcp"
description = "Allow all request from anywhere"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_security_group" "mv_sg_for_ec2" {
name = "EC2 Security Group"
vpc_id = aws_vpc.my_vpc.id
ingress {
description = "Allow http request from Load Balancer"
protocol = "tcp"
from_port = 80
to_port = 80
security_groups = [aws_security_group.mv_sg_for_elb.id]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}