canonical / terraform-provider-maas

Terraform MAAS provider
Mozilla Public License 2.0
60 stars 43 forks source link

cannot enable hardware sync when deploying a machine (maas_instance resource) #57

Closed pescobar closed 1 year ago

pescobar commented 1 year ago

Hi,

When deploying a new machine using terraform there is no option to enable hardware sync as you can do when using the webui (see screenshot)

deploy-maas

Would it be possible to extend the maas_instance resource so it allows to enable hardware sync on deployment?

My test environment is MAAS 3.3.2 with terraform v1.4.2 and maas provider 1.1.0

mastier commented 1 year ago

It should be quite straight forward as this is covered via MAAS api

POST /MAAS/api/2.0/machines/{system_id}/op-deploy: Deploy a machine

It would be somewhere here resource_maas_instance.go#L83-L108 in the code

mastier commented 1 year ago

@pescobar I was not able to test it thoroughly, but you may compile it from my fork

Here's PR : https://github.com/maas/terraform-provider-maas/pull/59

pescobar commented 1 year ago

I tried this patch and the terraform provider accepted the new argument enable_hw_sync = true . I used these deploy_params in the maas_instance resource:

     deploy_params {
         distro_series = "jammy"
         user_data     = file("cloud-init/users.yml")
         enable_hw_sync = true
     }

But still the hardware sync is not enabled for the deployed maas_instance

I think interaction with the MAAS api is handled by gomaasclient and I have seen these lines

I have no experience with golang but my guess is that the gomaasclient also needs to be updated for this feature to work. Could it be?

mastier commented 1 year ago

Yes, of course. Good find! Could you please provide me a simple but full terraform example to test. I might check if this is possible to be implemented easily.

pescobar commented 1 year ago

this is the terraform code I am testing (you will need to adapt it to your env)

Once terraform is working you should be able to do terraform apply to register the physical machine in maas and deploy it. Let me know if you want more details about terraform setup.

# maas_machine.node08:
resource "maas_machine" "node08" {
    architecture     = "amd64/generic"
    domain           = "maas"
    hostname         = "node08"
    pool             = "default"
    power_parameters = {
      cipher_suite_id = "3"
      k_g             =  ""
      mac_address     = "18:C0:4D:AA:AA:AA"
      power_address   = "192.168.34.34"
      power_boot_type = "efi"
      power_driver    = "LAN_2_0"
      power_pass      = "xxxxxxxxxx",
      power_user      = "yyyyyyyyyy"
      privilege_level = "ADMIN"

    }
    power_type       = "ipmi"
    pxe_mac_address  = "b4:96:91:BB:BB:BB"
    zone             = "default"

    timeouts {}
}

resource "maas_instance" "node08" {
    depends_on = [maas_machine.node08]
    allocate_params {
        hostname = maas_machine.node08.hostname
        pool     = "default"
        zone     = "default"
    }
    deploy_params {
        distro_series = "jammy"
        enable_hw_sync = true
    }
}

I am trying to patch the gomaasclient (see https://github.com/maas/gomaasclient/compare/master...pescobar:gomaasclient:master) but I am probably doing it wrong, fist time I ready golang ;)

troyanov commented 1 year ago

This issue is resolved in 1.2.0 release.