-
Notifications
You must be signed in to change notification settings - Fork 12
/
security_group.tf
53 lines (51 loc) · 1.36 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
# Allow EC2 instances to receive HTTP/HTTPS/SSH traffic IN and any traffic OUT
resource "aws_security_group" "sg_for_ec2_instances" {
name_prefix = "${var.cluster_name}_sg_for_ec2_instances_"
description = "Security group for EC2 instances within the cluster"
vpc_id = data.aws_vpc.main.id
lifecycle {
create_before_destroy = true
}
tags = {
Name = var.cluster_name
}
}
resource "aws_security_group_rule" "allow_ssh" {
type = "ingress"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = [
"0.0.0.0/0"
]
security_group_id = aws_security_group.sg_for_ec2_instances.id
}
resource "aws_security_group_rule" "allow_http_in" {
from_port = 80
protocol = "tcp"
security_group_id = aws_security_group.sg_for_ec2_instances.id
to_port = 80
cidr_blocks = [
"0.0.0.0/0"
]
type = "ingress"
}
resource "aws_security_group_rule" "allow_https_in" {
protocol = "tcp"
from_port = 443
to_port = 443
cidr_blocks = [
"0.0.0.0/0"
]
security_group_id = aws_security_group.sg_for_ec2_instances.id
type = "ingress"
}
resource "aws_security_group_rule" "allow_egress_all" {
security_group_id = aws_security_group.sg_for_ec2_instances.id
type = "egress"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = [
"0.0.0.0/0"]
}