terraform-provider-maas icon indicating copy to clipboard operation
terraform-provider-maas copied to clipboard

Many functions are calling the machine listing to retrieve a single machine, overloading the MAAS regions

Open r00ta opened this issue 1 year ago • 6 comments

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.

r00ta avatar Oct 25 '24 17:10 r00ta