title: Cloudformation Security Group
body: <p>I am trying to create a cluster of <code>ElasticSearch</code> servers on <code>EC2</code>. <code>ElasticSearch</code> uses a few defined ports to replicate and perform tasks like leader election. I want to create a security group in my <code>CloudFormation‎</code> template that locks down these ports such that only servers in this <code>ElasticSearch</code> server cluster can communicate with each other.  </p>
  
  <p>Is there a simple means by which I can identify a group of servers as a cluster and then assign port access to only those servers?</p>
  
  <p>I may be missing something obvious, but I can't get my <code>CloudFormation‎</code> template to build the model I want.</p>
  
  <p>Updated with my existing SG. This complains about circular reference. </p>
  
  <pre><code>ESSecurityGroup:
      Type: AWS::EC2::SecurityGroup
      Properties:
          GroupDescription: ES Node SG
          VpcId: !FindInMap [ EnvParams,  !Ref EnvironmentName, vpc ]
          SecurityGroupIngress:
              - FromPort: 9200
                ToPort: 9200
                SourceSecurityGroupId: !Ref ESSecurityGroup
                IpProtocol: tcp
              - FromPort: 9300
                ToPort: 9300
                SourceSecurityGroupId: !Ref ESSecurityGroup
                IpProtocol: tcp
  </code></pre>