Created
February 6, 2025 08:35
-
-
Save achenchi7/d04383f8275f4cf062ca701368907ae6 to your computer and use it in GitHub Desktop.
3-tier -> Security groups
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Security group for app tier | |
resource "aws_security_group" "app-tier-sg" { | |
name = "${var.vpc_name}-app-tier-sg" | |
vpc_id = aws_vpc.main-vpc.id | |
tags = { | |
Name = "${var.vpc_name}-app-tier-sg" | |
} | |
ingress { | |
from_port = 0 | |
to_port = 65535 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
egress { | |
from_port = 0 | |
to_port = 0 | |
protocol = "-1" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
} | |
# Security group for web tier | |
resource "aws_security_group" "web-subnet1-sg" { | |
name = "${var.vpc_name}-web-tier-sg" | |
vpc_id = aws_vpc.main-vpc.id | |
tags = { | |
Name = "${var.vpc_name}-web-tier-sg" | |
} | |
} | |
resource "aws_security_group" "web-subnet2-sg" { | |
name = "${var.vpc_name}-bastion-sg" | |
vpc_id = aws_vpc.main-vpc.id | |
tags = { | |
Name = "${var.vpc_name}-bastion-sg" | |
} | |
} | |
# Security group for db tier | |
resource "aws_security_group" "db-sg" { | |
vpc_id = aws_vpc.main-vpc.id | |
egress { | |
from_port = 0 | |
to_port = 0 | |
protocol = "-1" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
ingress { | |
from_port = 3306 | |
to_port = 3306 | |
protocol = "tcp" | |
security_groups = [aws_security_group.app-tier-sg.id] | |
} | |
tags = { | |
Name = "${var.vpc_name}-db-sg" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment