Skip to content

Instantly share code, notes, and snippets.

@rivernews
Created February 28, 2019 02:00
Show Gist options
  • Save rivernews/c43319f3d950b7a1e2ba09d2a1ba7957 to your computer and use it in GitHub Desktop.
Save rivernews/c43319f3d950b7a1e2ba09d2a1ba7957 to your computer and use it in GitHub Desktop.
Security group that protects EC2 instances behind Application Load Balancer.
...
resource "aws_security_group" "behind_alb_sg" {
name = "${var.project_name}_ec2_behind_alb"
description = "Protect EC2 instances from public traffic and set them behind Application Load Balancer."
vpc_id = "${var.vpc_id}"
ingress {
from_port = 0
to_port = 0
protocol = "-1"
security_groups = ["${aws_security_group.public_alb.id}"] // only from alb
}
# allow all traffic
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