forked from hashicorp/terraform-aws-waypoint-ecs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecurity_groups.tf
53 lines (45 loc) · 1.51 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
resource "aws_security_group" "app" {
name = "${local.waypoint_name}_internal"
description = "Security group for waypoint project ${var.waypoint_project}"
vpc_id = var.vpc_id
# Allow egress to anything
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}
# Allow ingress from ALB. App serves non-tls inside the VPC.
ingress {
description = "internal [[traffic"
from_port = var.application_port
to_port = var.application_port
protocol = "tcp"
security_groups = [aws_security_group.lb.id]
}
tags = local.tags
}
resource "aws_security_group" "lb" {
name = "${local.waypoint_name}_external"
description = "Allow all external traffic and designed to be attached to the ALB"
vpc_id = var.vpc_id
# Egress managed by external rule to avoid circular dependency
ingress {
description = "internal traffic"
from_port = var.alb_port
to_port = var.alb_port
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}
tags = local.tags
}
resource "aws_security_group_rule" "external_egress" {
type = "egress"
from_port = var.application_port
to_port = var.application_port
protocol = "tcp"
source_security_group_id = aws_security_group.app.id
security_group_id = aws_security_group.lb.id
}