title: Terraform - allow all outbound ports except specific ports?
body: <p>I have this AWS security group defined in terraform:</p>
  
  <pre><code>resource "aws_security_group" "sg" {
    name = "${var.name}"
    description = "${var.description}"
    vpc_id = "${data.terraform_remote_state.vpc.vpc_id}"
  
    ingress {
      from_port   = 80
      to_port     = 80
      protocol    = "tcp"
      cidr_blocks = ["0.0.0.0/0"]
    }
  
    ingress {
      from_port   = 443
      to_port     = 443
      protocol    = "tcp"
      cidr_blocks = ["0.0.0.0/0"]
    }
  
    ingress {
      from_port   = 22
      to_port     = 22
      protocol    = "tcp"
      cidr_blocks = ["${var.ext_blocks}"]
    }
  
    egress {
      from_port       = 0
      to_port         = 0
      protocol        = "-1"
      cidr_blocks     = ["0.0.0.0/0"]
    }
  }
  </code></pre>
  
  <p>With this configartion, any port can be used as outgoing/outbound. But if I want to exclude some ports, what would be the recommended way?</p>
  
  <p>Let say I want to exclude ports 25 and 465, so I could do something like (instead of using that one egress rule that allows any port):</p>
  
  <pre><code>  egress {
      from_port       = 0
      to_port         = 24
      protocol        = "-1"
      cidr_blocks     = ["0.0.0.0/0"]
    }
    egress {
      from_port       = 26
      to_port         = 464
      protocol        = "-1"
      cidr_blocks     = ["0.0.0.0/0"]
    }
    egress {
      from_port       = 466
      to_port         = 65535
      protocol        = "-1"
      cidr_blocks     = ["0.0.0.0/0"]
    }
  </code></pre>
  
  <p>But this needs to define specific ranges, which require to define some extra egress rules. Is there a better way maybe? For example where I can define rule to allow all ports and then exclude some?</p>