title: Terraform AWS Security Group settings to allow all ports between all VMS
body: <p>I'm kinda stumped. I have a custom service (named bacalhau) running on each of three machines in a security group on 54545. I also have SSH running on all machines. Here's what my terraform looks like:</p>
  <pre><code>
  resource &quot;aws_security_group&quot; &quot;allow_ssh_and_bacalhau&quot; {
    vpc_id      = aws_vpc.bacalhau_vpc.id
    name        = &quot;allow_ssh_and_bacalhau&quot;
    description = &quot;security group that allows ssh and bacalhau and all egress traffic&quot;
  
  }
  resource &quot;aws_security_group_rule&quot; &quot;egress_all&quot; {
    type              = &quot;egress&quot;
    from_port         = 0
    to_port           = 0
    protocol          = &quot;-1&quot;
    cidr_blocks       = [&quot;0.0.0.0/0&quot;]
    security_group_id = aws_security_group.allow_ssh_and_bacalhau.id
  }
  
  
  resource &quot;aws_security_group_rule&quot; &quot;ingress_ssh&quot; {
    type              = &quot;ingress&quot;
    from_port         = 22
    to_port           = 22
    protocol          = &quot;-1&quot;
    cidr_blocks       = [&quot;0.0.0.0/0&quot;]
    security_group_id = aws_security_group.allow_ssh_and_bacalhau.id
  }
  
  resource &quot;aws_security_group_rule&quot; &quot;ingress_bacalhau&quot; {
    type              = &quot;ingress&quot;
    from_port         = 54545
    to_port           = 54545
    protocol          = &quot;-1&quot;
    self              = true
    security_group_id = aws_security_group.allow_ssh_and_bacalhau.id
  }
  </code></pre>
  <p>SSH works fine - including inter-traffic between machines, but the bacalhau (54545) service doesn't show up.</p>
  <p>E.g.</p>
  <pre><code>ubuntu@ip-10-0-1-219:~$ nmap ec2-18-202-245-138.eu-west-1.compute.amazonaws.com
  Starting Nmap 7.80 ( https://nmap.org ) at 2022-03-19 18:07 UTC
  Nmap scan report for ec2-18-202-245-138.eu-west-1.compute.amazonaws.com (10.0.1.237)
  Host is up (0.0022s latency).
  rDNS record for 10.0.1.237: ip-10-0-1-237.eu-west-1.compute.internal
  Not shown: 999 closed ports
  PORT   STATE SERVICE
  22/tcp open  ssh
  
  Nmap done: 1 IP address (1 host up) scanned in 0.08 seconds
  ubuntu@ip-10-0-1-219:~$
  </code></pre>
  <p><strong>EDIT</strong> The nmap is running from a VM inside the security group.</p>
  <p>Am I doing something wrong? Is this a security group, vpc, or ec2 mistake? I <em>can</em> access the service from the node itself through localhost loop back.</p>
  <p><strong>EDIT 2</strong> Confirmed this is a security group issue - I turned on accepting inbound from everywhere [0.0.0.0/0] and it worked fine.</p>