title: Security Group and Subnet Belongs to different networks
body: <p>I am creating a basic AWS CloudFormation Template with one VPC, 3 Security Group and 5 EC2 Instances my security group looks something like this -</p>
  
  <pre><code>{
    "WebApplicationServerSG": {
      "Type": "AWS::EC2::SecurityGroup",
      "Properties": {
        "VpcId": {
          "Ref": "DevVpc"
        },
        "GroupDescription": "Enable HTTP, HTTPS and SSH access",
        "Tags": [
          {
            "Key": "Name",
            "Value": "WebApplicationServer Service Group"
          }
        ],
        "SecurityGroupIngress": [
          {
            "IpProtocol": "tcp",
            "FromPort": "443",
            "ToPort": "443",
            "CidrIp": "0.0.0.0/0"
          },
          {
            "IpProtocol": "tcp",
            "FromPort": "80",
            "ToPort": "80",
            "CidrIp": "0.0.0.0/0"
          },
          {
            "IpProtocol": "tcp",
            "FromPort": "22",
            "ToPort": "22",
            "CidrIp": "0.0.0.0/0"
          }
        ],
        "SecurityGroupEgress": [
          {
            "IpProtocol": "tcp",
            "FromPort": "443",
            "ToPort": "443",
            "CidrIp": "0.0.0.0/0"
          },
          {
            "IpProtocol": "tcp",
            "FromPort": "80",
            "ToPort": "80",
            "CidrIp": "0.0.0.0/0"
          },
          {
            "IpProtocol": "tcp",
            "FromPort": "22",
            "ToPort": "22",
            "CidrIp": "0.0.0.0/0"
          }
        ]
      },
      "Metadata": {
        "AWS::CloudFormation::Designer": {
          "id": "a7977f00-48d6-488f-9e23-9bcd0785d399"
        }
      }
    }
  }
  </code></pre>
  
  <p>And the VPC is something like below -</p>
  
  <pre><code>{
    "DevVpc": {
      "Type": "AWS::EC2::VPC",
      "Properties": {
        "CidrBlock": "172.31.0.0/16",
        "EnableDnsSupport": "false",
        "EnableDnsHostnames": "false",
        "InstanceTenancy": "dedicated",
        "Tags": [
          {
            "Key": "Name",
            "Value": "DevStackVpc"
          }
        ]
      }
    }
  }
  </code></pre>
  
  <p>I am getting error while stack creation with the template -</p>
  
  <blockquote>
    <p>Security group sg-31f91b5a and subnet subnet-ea0aa3a7 belong to
    different networks.</p>
  </blockquote>
  
  <pre><code>11:13:01 UTC+0550   CREATE_FAILED   AWS::EC2::Instance  WebApplicationServer    Security group sg-5147a53a and subnet subnet-ea0aa3a7 belong to different networks.
  </code></pre>
  
  <p>And here is a <a href="https://gist.github.com/jeetendra-choudhary/b2ddaa16e4212209dbd41b511e993c98" rel="noreferrer">gist</a> for complete template, any help would really be appreciated.</p>