Skip to content

Instantly share code, notes, and snippets.

@SharmilaS22
Created June 18, 2023 15:16
Show Gist options
  • Select an option

  • Save SharmilaS22/226f14f60ae2d26b87143d5553068284 to your computer and use it in GitHub Desktop.

Select an option

Save SharmilaS22/226f14f60ae2d26b87143d5553068284 to your computer and use it in GitHub Desktop.
Security groups for EC2 and Application Load Balancer
resource "aws_security_group" "sh_sg_for_elb" {
name = "sharmi-sg_for_elb"
vpc_id = aws_vpc.sh_main.id
ingress {
description = "Allow http request from anywhere"
protocol = "tcp"
from_port = 80
to_port = 80
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}
ingress {
description = "Allow https request from anywhere"
protocol = "tcp"
from_port = 443
to_port = 443
cidr_blocks = ["0.0.0.0/0"]
ipv6_cidr_blocks = ["::/0"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_security_group" "sh_sg_for_ec2" {
name = "sharmi-sg_for_ec2"
vpc_id = aws_vpc.sh_main.id
ingress {
description = "Allow http request from Load Balancer"
protocol = "tcp"
from_port = 80 # range of
to_port = 80 # port numbers
security_groups = [aws_security_group.sh_sg_for_elb.id]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment