-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsecurity_group.tf
85 lines (85 loc) · 3.54 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
75
76
77
78
79
80
81
82
83
84
85
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/default_security_group
resource "aws_default_security_group" "default" {
vpc_id = aws_vpc.this.id
}
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group
resource "aws_security_group" "custom_sg" {
name = "${var.name}_allow_inbound_access"
description = "allow inbound traffic"
vpc_id = aws_vpc.this.id
tags = {
"Name" = "${var.name}-lb-sg"
}
}
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule
resource "aws_security_group_rule" "ingress_load_balancer" {
description = "allow traffic into the load balancer"
type = "ingress"
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = aws_security_group.custom_sg.id
#checkov:skip=CKV_AWS_260: "Ensure no security groups allow ingress from 0.0.0.0:0 to port 80"
#This is non prod and hence enabled.
}
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule
resource "aws_security_group_rule" "egress_load_balancer" {
description = "allow traffic to reach outside the vpc"
type = "egress"
from_port = 0
to_port = 65535
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = aws_security_group.custom_sg.id
}
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group
resource "aws_security_group" "container_sg" {
name = "${var.name}_container_allow_inbound_access"
description = "allow inbound traffic to the containers"
vpc_id = aws_vpc.this.id
tags = {
"Name" = "${var.name}-container-sg"
}
#checkov:skip=CKV2_AWS_5: "Ensure that Security Groups are attached to another resource"
#This security group is required in the deploy stack.
}
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule
resource "aws_security_group_rule" "ingress_container" {
description = "allow traffic into the containers from the vpc"
type = "ingress"
from_port = 8080
to_port = 8080
protocol = "tcp"
source_security_group_id = aws_security_group.custom_sg.id
security_group_id = aws_security_group.container_sg.id
}
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule
resource "aws_security_group_rule" "egress_container" {
description = "allow traffic to reach the vpc from the container"
type = "egress"
from_port = 0
to_port = 65535
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
security_group_id = aws_security_group.container_sg.id
}
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group
resource "aws_security_group" "endpoint_sg" {
name = "endpoint_access"
description = "allow inbound traffic"
vpc_id = aws_vpc.this.id
tags = {
"Name" = "${var.name}-endpoint-sg"
}
}
#https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule
resource "aws_security_group_rule" "ingress_vpc_endpoint" {
description = "Enable access for the endpoints."
type = "ingress"
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = [aws_vpc.this.cidr_block]
security_group_id = aws_security_group.endpoint_sg.id
}