export function getSubnetCidrPools()

in src/lib/common-outputs/src/cidr-pools.ts [76:115]


export function getSubnetCidrPools(props: {
  subnetPools: AssignedSubnetCidrPool[];
  accountKey: string;
  region: string;
  vpcName: string;
  subnetName?: string;
  az?: string;
  organizationalUnitName?: string;
}): AssignedSubnetCidrPool[] {
  const { accountKey, region, subnetPools, vpcName, az, organizationalUnitName, subnetName } = props;
  let filteredPools = subnetPools.filter(
    subnetPool =>
      subnetPool['account-Key'] === accountKey &&
      subnetPool['vpc-name'] === vpcName &&
      subnetPool.region === region &&
      ((subnetName && subnetPool['subnet-name'] === subnetName) || !subnetName) &&
      ((az && subnetPool.az === az) || !az),
  );
  if (filteredPools.length === 0) {
    filteredPools = subnetPools.filter(
      subnetPool =>
        subnetPool['account-ou-key'] === `account/${accountKey}` &&
        subnetPool['vpc-name'] === vpcName &&
        subnetPool.region === region &&
        ((subnetName && subnetPool['subnet-name'] === subnetName) || !subnetName) &&
        ((az && subnetPool.az === az) || !az),
    );
  }
  if (filteredPools.length === 0 && organizationalUnitName) {
    filteredPools = subnetPools.filter(
      subnetPool =>
        subnetPool['account-ou-key'] === `organizational-unit/${organizationalUnitName}` &&
        subnetPool['vpc-name'] === vpcName &&
        subnetPool.region === region &&
        ((subnetName && subnetPool['subnet-name'] === subnetName) || !subnetName) &&
        ((az && subnetPool.az === az) || !az),
    );
  }
  return filteredPools;
}