-
Notifications
You must be signed in to change notification settings - Fork 0
/
security-groups.tf
56 lines (50 loc) · 2.25 KB
/
security-groups.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
########################################################################################################################
#### LOAD BALANCER
########################################################################################################################
resource "aws_security_group" "load_balancer_security_group" {
name = "${var.beanstalk_env_name}-load-balancer"
description = "${var.beanstalk_env_name} load balancer security group"
vpc_id = var.vpc_id
tags = {
Name = "${var.beanstalk_env_name}-load-balancer"
}
}
resource "aws_security_group_rule" "allow_http_traffic_to_lb" {
description = "Allow HTTP inbound traffic to ${var.beanstalk_env_name} load balancer on port 80"
type = "ingress"
from_port = 80
to_port = 80
protocol = "TCP"
security_group_id = aws_security_group.load_balancer_security_group.id
cidr_blocks = ["0.0.0.0/0"]
}
resource "aws_security_group_rule" "allow_https_traffic_to_lb" {
description = "Allow HTTPS inbound traffic to ${var.beanstalk_env_name} load balancer on port 443"
type = "ingress"
from_port = 443
to_port = 443
protocol = "TCP"
security_group_id = aws_security_group.load_balancer_security_group.id
cidr_blocks = ["0.0.0.0/0"]
}
resource "aws_security_group_rule" "allow_all_outbound_traffic_from_lb" {
description = "Allow outbound traffic from ${var.beanstalk_env_name} load balancer on port 80"
type = "egress"
from_port = 80
to_port = 80
protocol = "TCP"
security_group_id = aws_security_group.load_balancer_security_group.id
source_security_group_id = module.beanstalk.instances_security_group_id
}
########################################################################################################################
#### BEANSTALK INSTANCES
########################################################################################################################
resource "aws_security_group_rule" "allow_traffic_from_lb_to_beanstalk_instances" {
description = "Allow inbound traffic to ${var.beanstalk_env_name} beanstalk instances on port 80 from the load balancer"
protocol = "TCP"
type = "ingress"
security_group_id = module.beanstalk.instances_security_group_id
to_port = 80
source_security_group_id = aws_security_group.load_balancer_security_group.id
from_port = 80
}