#!/bin/env zx
import fs from "fs"

const regions = JSON.parse(await $`aws ec2 describe-regions`).Regions.map(r => r.RegionName);

console.log("Available regions:", regions);


const instanceMap = {}

for (const region of regions) {
    console.log("Fetching instance types for region", region)
    const instanceTypes = JSON.parse(await $`aws ec2 describe-instance-types --filters Name=network-info.ipv6-supported,Values=true --region ${region}`).InstanceTypes

    for (const instance of instanceTypes) {
        if (!instance.ProcessorInfo.SupportedArchitectures.includes("x86_64")) continue
        instanceMap[instance.InstanceType + "-" + region] = instance
    }
}
fs.writeFileSync("instance-types.json", JSON.stringify(instanceMap, null, 2), "utf-8")
