Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: commission machines in New state by their PXC MAC #192

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 22 additions & 3 deletions maas/resource_maas_machine.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,37 @@ func resourceMaasMachine() *schema.Resource {
}

func resourceMachineCreate(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
var machine *entity.Machine
client := meta.(*client.Client)

// Create MAAS machine
powerParams, err := getMachinePowerParams(d)
machines, err := client.Machines.Get(&entity.MachinesParams{MACAddress: []string{d.Get("pxe_mac_address").(string)}})
if err != nil {
return diag.FromErr(err)
}
machine, err := client.Machines.Create(getMachineParams(d), powerParams)

powerParams, err := getMachinePowerParams(d)
if err != nil {
return diag.FromErr(err)
}

if len(machines) == 1 && machines[0].StatusName == "New" {
// Update MAAS machine with Terraform configuration
if machine, err = client.Machine.Update(machines[0].SystemID, getMachineParams(d), powerParams); err != nil {
return diag.FromErr(err)
}
// Commission MAAS machine
machine, err = client.Machine.Commission(machine.SystemID, &entity.MachineCommissionParams{})
if err != nil {
return diag.FromErr(err)
}
} else {
// Create MAAS machine
machine, err = client.Machines.Create(getMachineParams(d), powerParams)
if err != nil {
return diag.FromErr(err)
}
}

// Save Id
d.SetId(machine.SystemID)

Expand Down
Loading