forked from Nova-reward/Nova-Rewards
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecurity_groups.tf
More file actions
105 lines (93 loc) · 2.25 KB
/
Copy pathsecurity_groups.tf
File metadata and controls
105 lines (93 loc) · 2.25 KB
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# Security Group for ALB
resource "aws_security_group" "alb_sg" {
name_prefix = "${var.app_name}-alb-"
description = "Security group for ALB"
vpc_id = var.vpc_id
ingress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
description = "HTTPS from anywhere"
}
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
description = "HTTP from anywhere (for redirect to HTTPS)"
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
description = "Allow all outbound traffic"
}
tags = merge(
var.tags,
{
Name = "${var.app_name}-alb-sg"
}
)
}
# Security Group for EC2 instances
resource "aws_security_group" "ec2_sg" {
name_prefix = "${var.app_name}-ec2-"
description = "Security group for EC2 instances"
vpc_id = var.vpc_id
# Inbound from ALB only
ingress {
from_port = var.app_port
to_port = var.app_port
protocol = "tcp"
security_groups = [aws_security_group.alb_sg.id]
description = "Application port from ALB"
}
# Outbound to RDS
egress {
from_port = var.rds_port
to_port = var.rds_port
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
description = "RDS database access"
}
# Outbound to Redis
egress {
from_port = var.redis_port
to_port = var.redis_port
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
description = "Redis cache access"
}
# Outbound for DNS (required for service discovery)
egress {
from_port = 53
to_port = 53
protocol = "udp"
cidr_blocks = ["0.0.0.0/0"]
description = "DNS queries"
}
# Outbound for HTTPS (for external APIs, package downloads, etc.)
egress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
description = "HTTPS outbound"
}
# Outbound for HTTP (for external APIs, package downloads, etc.)
egress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
description = "HTTP outbound"
}
tags = merge(
var.tags,
{
Name = "${var.app_name}-ec2-sg"
}
)
}