resource "aws_security_group" "egress_all" {
  name = "demo-egress-all-web"
  description = "Allow all egress on web ports 443/80"
  vpc_id = aws_vpc.demo.id

  tags = {
    Name = "egress-all-web"
  }

  egress {
    from_port       = 18000
    to_port         = 18000
    protocol        = "tcp"
    cidr_blocks     = ["0.0.0.0/0"]
  }
  egress {
    from_port       = 443
    to_port         = 443
    protocol        = "tcp"
    cidr_blocks     = ["0.0.0.0/0"]
  }

  egress {
    from_port       = 80
    to_port         = 80
    protocol        = "tcp"
    cidr_blocks     = ["0.0.0.0/0"]
  }

}

resource "aws_security_group" "allow_self_web" {
  name = "demo-allow-self"
  description = "Allow all egress"
  vpc_id = aws_vpc.demo.id

  tags = {
    Name = "demo-allow-self"
  }

  ingress {
    from_port = local.appetizer_port
    to_port   = local.appetizer_port
    protocol  = "tcp"
    // cidr_blocks = ["0.0.0.0/0"]
    self = true
  }

  ingress {
    from_port = 443
    to_port   = 443
    protocol  = "tcp"
    self = true
  }

}

resource "aws_security_group" "allow_443_from_anywhere" {
  name = "demo-allow-443-from-anywhere"
  description = "Allow 443 from the world"
  vpc_id = aws_vpc.demo.id

  tags = {
    Name = "demo-allow-443-from-anywhere"
  }

  ingress {
    from_port = 443
    to_port   = 443
    protocol  = "tcp"
    cidr_blocks     = ["0.0.0.0/0"]
  }

//  ingress {
//    from_port = local.appetizer_port
//    to_port   = local.appetizer_port
//    protocol  = "tcp"
//    cidr_blocks = ["0.0.0.0/0"]
//  }

}
