oVirt/terraform-provider-ovirt

Add MAC address(es) to either ovirt_nic or ovirt_wait_for_ip

phunyguy opened this issue · 5 comments

Please describe what you would like to see

in ovirt_wait_for_ip, or during ovirt_nic creation, I would like the mac address of the nic to be returned as an output.

I appreciate that the IP addresses are returned, and would love to see this expanded out to return the mac address.

If the mac address is provided, it can be used to populate DHCP leases for created ovirt VMs.
My initial solution I was using is an external data provider that I wrote myself to hook into the ovirt API with python, and give me the IP and mac of the VM, so that I can create a lease, but I am now moving to gitlab workflow for ci/cd, and the terraform docker image it uses does not have python, so I am stuck.

Please describe the solution you'd like

Just a way to return the VM mac address that corresponds to the returned IPs as usable data to call in additional steps.

Currently what I use:

data "external" "system" {
  program = ["python", "ovirtvmnicprops"]
  query = {
    api       = var.ovirt_url
    username  = var.ovirt_username
    password  = var.ovirt_password
    vm_id     = ovirt_vm.system.id
    nic_id    = ovirt_nic.system.id
    noverify  = true
    mac       = true
    ipv4      = true
  }
  depends_on = [data.ovirt_wait_for_ip.system]
}

Provided by: ovirtvmnicprops
But this is not possible on gitlab ci/cd. with their terraform integration. So this feature request would make ovirtvmnicprops obsolete, which I will gladly welcome.

Please describe your use case

My use case is an on-premise ovirt cluster, with automatically created VMs that have DHCP static leases in mikrotik or any other system that terraform has hooks for.

I ran into the exact same issue.
At the moment, I use the built-in http module to get information about the MAC address.
It would be very useful to receive this information without crutches...

The only thing about the implementation: it seems to me that MAC address must return during ovirt_nic creation, cause we may have OS without guest-agent yet. And also no reason to wait for IP from guest agent, cause MAC address we know in nic creation.

I am perfectly fine with it being returned from ovirt_nic creation, but I do also need the IP, because that's how I am converting the dynamic dhcp lease to static with the mikrotik bit of my configuration... I just..... need the mac address to show its face at some point during the process, and it currently does not.

Hey folks, with RHV being sunset in Red Hat, we have little capacity to develop new features for this provider. However, we can review if anyone wants to contribute a change to this effect.

As far as I understood this new feature, the following changes would be required to implement this new feature:

Would you be up for it? @Vatson112 @phunyguy
Unfortunately, we have little capacity, but would be happy to support you.

Hello, @engelmi.

Yes, I think I can do it.

I alreay wrote working prototype, but it work kinda strange:

I see my new key (mac) in .tfstate file:

{
      "module": "module.ovirt-vm-provision",
      "mode": "managed",
      "type": "ovirt_nic",
      "name": "test",
      "provider": "provider[\"local/ovirt/ovirt\"]",
      "instances": [
        {
          "schema_version": 0,
          "attributes": {
            "id": "cf549f1e-42fc-457f-ba62-d24a5e3c3ed6",
            "mac": "56:6f:1d:0b:00:2d",
            "name": "eth0",
            "vm_id": "c2dcc92d-bdd4-46ff-b39b-42695a1dbe15",
            "vnic_profile_id": "c1596a1e-51bf-4cdf-a89b-92c1b9308f6a"
          },
          "sensitive_attributes": [],
          "dependencies": [
            "module.ovirt-vm-provision.data.ovirt_templates.template",
            "module.ovirt-vm-provision.ovirt_vm.test"
          ]
        }
      ]
    }

but not in output:

ovirt-vm-net = {
  "mac" = tostring(null)
  "vm_ip" = toset([
    {
      "ipv4_addresses" = toset([
        "10.195.16.46",
      ])
      "ipv6_addresses" = toset([])
      "name" = "eth0"
    },
  ])
}

So, I need to deeply look at it, and I think I`ll do PR in few days.