vatesfr / terraform-provider-xenorchestra

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

Provide possibility to add multiple network interfaces #27

Closed ZegalPL closed 4 years ago

ZegalPL commented 4 years ago

I Would like to add multiple network interfaces while provisioning the VM, could this feature be added?

I've tried various ways and failed, and if this is possible could it be described in documentation?

ddelnano commented 4 years ago

Sorry for the late response! @ZegalPL this is definitely a feature I'm interested in supporting. Unfortunately I don't think this will work with the current terraform code. I don't think the terraform code is making the correct API call to the XO api when multiple network blocks are used. I likely won't have time to work on this since I'm away for the holidays but I will try to prioritize this in early January.

olivierlambert commented 4 years ago

@ddelnano if you need assitance on how to do some calls, feel free to ping @julien-f :+1:

ddelnano commented 4 years ago

@ZegalPL after testing this the feature already works. You just need to specify multiple network blocks in the terraform configuration like the following example.

resource "xenorchestra_vm" "test" {
  memory_max = 4294934528
  cpus = 1
  cloud_config = "${xenorchestra_cloud_config.devbox_config.template}"
  name_label = "network config test"
  template = "${data.xenorchestra_template.puppet_template.id}"

  network {
    network_id = "${data.xenorchestra_pif.eth0.network}"
  }
  network {
    network_id = "${data.xenorchestra_pif.eth1.network}"
  }

  disk {
    sr_id = "7f469400-4a2b-5624-cf62-61e522e50ea1"
    name_label = "devbox disk"
    size = 32212254720
  }
}

This gives me a virtual machine with an eth0 and eth1.

ddelnano@devbox:~$ ip link
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 65536 qdisc noqueue state UNKNOWN mode DEFAULT group default qlen 1000
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP mode DEFAULT group default qlen 1000
    link/ether ae:22:c7:6d:8d:d4 brd ff:ff:ff:ff:ff:ff
3: eth1: <BROADCAST,MULTICAST> mtu 1500 qdisc noop state DOWN mode DEFAULT group default qlen 1000
    link/ether 5e:e8:ce:05:ac:13 brd ff:ff:ff:ff:ff:ff

Have you tried that in your earlier attempts?

ZegalPL commented 4 years ago

@ddelnano You are right, i modified my test setup and added another NIC and syntax with multiple network blocks works.

Previously i tried with second network configured as private, which didn't work, thank You for checking this out! This solves the issue.