terraform-provider-maas
terraform-provider-maas copied to clipboard
Many functions are calling the machine listing to retrieve a single machine, overloading the MAAS regions
I found out that in TF there are many calls to
func getMachine(client *client.Client, identifier string) (*entity.Machine, error) {
machines, err := client.Machines.Get(&entity.MachinesParams{})
if err != nil {
return nil, err
}
for _, m := range machines {
if m.SystemID == identifier || m.Hostname == identifier || m.FQDN == identifier || m.BootInterface.MACAddress == identifier {
return &m, nil
}
}
return nil, fmt.Errorf("machine (%s) not found", identifier)
}
which means that in order to get a single machine the machine listing is called. The machine listing is the most expensive operation and for this reason it should be avoided as much as possible.
Instead, these functions should specify the identifiers in the machine listing so to perform the lookup on the server and improve a lot the server performances. If some identifiers are not supported by the current API, we should improve the API so to make it possible.