vatesfr / terraform-provider-xenorchestra

Xen Orchestra provider for Terraform
MIT License
150 stars 32 forks source link

Ensure terraform provider passes properly formatted mac address to XO api #114

Closed Vagrantin closed 3 years ago

Vagrantin commented 3 years ago

Hello, First of all thank you for this great plugin !

 I’m currently testing it and I have notice that the Mac Address format is important, where you should use colon : instead of dash -.

I believe this is a Terraform limitation with identifiers Since Go doesn’t have any issue to parse any common type of Mac Address

Maybe good to mention it in the documentation.

This does work correctly.

data "xenorchestra_template" "template" {
    name_label = "windows_2012_r2_Galaxy_Template"
}

data "xenorchestra_network" "net" {
  name_label = "ETH"
}

resource "xenorchestra_vm" "bar" {
    memory_max = 1073733632
    cpus  = 1
    name_label = "MyName"
    name_description = "Mydescription"
    template = data.xenorchestra_template.template.id
    network {
      network_id = data.xenorchestra_network.net.id
    mac_address = "6E:84:EE:7B:33:25"
    }

    disk {
      sr_id = "c7e5cf80-2b3e-c0ed-6f1e-09f1417b7d24"
      name_label = "W2012Disk"
      size = 62212254720
    }
}

but this doesn’t work

data "xenorchestra_template" "template" {
    name_label = "windows_2012_r2_Galaxy_Template"
}

data "xenorchestra_network" "net" {
  name_label = "ETH"
}

resource "xenorchestra_vm" "bar" {
    memory_max = 1073733632
    cpus  = 1
    name_label = "MyName"
    name_description = "Mydescription"
    template = data.xenorchestra_template.template.id
    network {
      network_id = data.xenorchestra_network.net.id
    mac_address = "6E-84-EE-7B-33-25"
    }

    disk {
      sr_id = "c7e5cf80-2b3e-c0ed-6f1e-09f1417b7d24"
      name_label = "W2012Disk"
      size = 62212254720
    }
}

hope that help

ddelnano commented 3 years ago

This has nothing to do with the HCL language itself. The provider's validation allows for all possible mac address inputs but the XO api needs a mac address with colons.

The provider needs to convert all mac addresses to use colons before making the request to XO. I found this from looking at the XO server's logs while creating a VM.

Jan 28 01:12:17 xoa xo-server[510]: 2021-01-28T06:12:17.182Z - xo:api - [WARN] admin@admin.net | vm.create(...) [55s] =!> XapiError: MAC_INVALID(6E-84-EE-7B-33-25)
ddelnano commented 3 years ago

@Vagrantin #115 should fix this problem. Thanks for highlighting this issue!

Vagrantin commented 3 years ago

Super thank you ! Once PR is done will test it and let you know.

ddelnano commented 3 years ago

This is available in v0.13.1