private void configureSecurityGroups(List<VPNEndpoint> vpnEndpoints) {
    for (VPNEndpoint vpnEndpoint : vpnEndpoints) {
      ec2Client.setEndpoint(vpnEndpoint.getRegion().getEndpoint());

      String securityGroupName = vpc2vpcId;

      // Create Security Group
      CreateSecurityGroupRequest createSecGrpReq = new CreateSecurityGroupRequest();
      createSecGrpReq.setGroupName(securityGroupName);
      createSecGrpReq.setDescription("vpc2vpc Security Group");
      createSecGrpReq.setVpcId(vpnEndpoint.getVpc().getVpcId());
      LOG.debug("Creating security group in " + vpnEndpoint.getRegion().getRegionName());
      CreateSecurityGroupResult createSecGrpResult = ec2Client.createSecurityGroup(createSecGrpReq);
      String securityGroupId = createSecGrpResult.getGroupId();
      LOG.debug("Created security group " + securityGroupId + " in " + vpnEndpoint.getRegion().getRegionName());

      // Set the endpoint's security group
      vpnEndpoint.setSecurityGroupId(securityGroupId);

      // Get a list of external endpoint's EIPs
      List<String> ipRanges = new ArrayList();
      for (VPNEndpoint extVpnEndpoint : vpnEndpoints) {
        if (!vpnEndpoint.equals(extVpnEndpoint)) {
          ipRanges.add(extVpnEndpoint.getElasticIPAddress() + "/32");
        }
      }

      List<String> localIpRanges = new ArrayList();
      localIpRanges.add(vpnEndpoint.getVpc().getCidrBlock());

      // Create the IpPermissions
      List<IpPermission> ipPermissions = new ArrayList();

      IpPermission allTcpTraffic = new IpPermission();
      allTcpTraffic.setIpRanges(localIpRanges);
      allTcpTraffic.setIpProtocol("tcp");
      allTcpTraffic.setFromPort(1);
      allTcpTraffic.setToPort(65535);
      ipPermissions.add(allTcpTraffic);

      IpPermission allUdpTraffic = new IpPermission();
      allUdpTraffic.setIpRanges(localIpRanges);
      allUdpTraffic.setIpProtocol("udp");
      allUdpTraffic.setFromPort(1);
      allUdpTraffic.setToPort(65535);
      ipPermissions.add(allUdpTraffic);

      IpPermission allIcmpTraffic = new IpPermission();
      allIcmpTraffic.setIpRanges(localIpRanges);
      allIcmpTraffic.setIpProtocol("icmp");
      allIcmpTraffic.setFromPort(-1);
      allIcmpTraffic.setToPort(-1);
      ipPermissions.add(allIcmpTraffic);

      IpPermission ipPermUdp500 = new IpPermission();
      ipPermUdp500.setIpProtocol("udp");
      ipPermUdp500.setFromPort(500);
      ipPermUdp500.setToPort(500);
      ipPermUdp500.setIpRanges(ipRanges);
      ipPermissions.add(ipPermUdp500);

      IpPermission ipPermTcp500 = new IpPermission();
      ipPermTcp500.setIpProtocol("tcp");
      ipPermTcp500.setFromPort(500);
      ipPermTcp500.setToPort(500);
      ipPermTcp500.setIpRanges(ipRanges);
      ipPermissions.add(ipPermTcp500);

      IpPermission ipPermUdp4500 = new IpPermission();
      ipPermUdp4500.setIpProtocol("udp");
      ipPermUdp4500.setFromPort(4500);
      ipPermUdp4500.setToPort(4500);
      ipPermUdp4500.setIpRanges(ipRanges);
      ipPermissions.add(ipPermUdp4500);

      // Set permissions on security group
      AuthorizeSecurityGroupIngressRequest authSecGrpIngressReq = new AuthorizeSecurityGroupIngressRequest();
      authSecGrpIngressReq.setGroupId(securityGroupId);
      authSecGrpIngressReq.setIpPermissions(ipPermissions);
      LOG.debug("About to authorize SecurityGroup Ingress on : " + securityGroupId);

      // Apply security group rules.  Need to retry a few times since API takes a bit of time to realize the SG really does exist
      int retryCount = 0;
      boolean done = false;
      while (!done && retryCount < 3) {
        try {
          ec2Client.authorizeSecurityGroupIngress(authSecGrpIngressReq);
          done = true;
        } catch (Exception e) {
          try {
            Thread.sleep(5000);
          } catch (Exception ie) {
            // Eat it
          }
          if (retryCount > 3) {
            LOG.debug("Exceeded retries.  Throwing exception");
            throw new RuntimeException(e);
          } else {
            retryCount = retryCount + 1;
            LOG.debug("Caught exception.  Going to retry request.  Exception: " + e.getMessage());
          }
        }
      }
    }
  }