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

Get config of existing vm #162

Open
henningphan opened this issue Oct 28, 2023 · 7 comments
Open

Get config of existing vm #162

henningphan opened this issue Oct 28, 2023 · 7 comments
Labels
potential-upstream-issue The issue is potentially upstream wontfix This will not be worked on

Comments

@henningphan
Copy link

Hi, Im new to this so my assumptions might be wrong, but I got 2 vms, and want to create the third vm with pulumi.
Im hoping its possible to look-up an existing vm, modify that config to create the code to generate the third.

https://www.pulumi.com/registry/packages/proxmoxve/api-docs/vm/virtualmachine/#look-up

I have attached my code and the error message I get, seems to complain I dont pass node_name, which I have set to proxmox, unless there is a config somewhere Im missing.

pulumi-proxmoxve==5.13.1

import pulumi
import pulumi_proxmoxve as proxmoxve

ubuntu_vms = proxmoxve.vm.get_virtual_machines()
vm = proxmoxve.vm.get_virtual_machine(node_name="proxmox", vm_id=100)
pulumi.export("vms", ubuntu_vms)
pulumi.export("vm", vm)

nixos=proxmoxve.vm.VirtualMachine.get(resource_name="nixos1", id=100, node_name="proxmox")
pulumi.export("nixos", nixos)
[pulumi:~/repo/pulumi]$ pulumi up
Previewing update (prod)

View in Browser (Ctrl+O): https://app.pulumi.com/henning/proxmox/prod/previews/f5ac0b9c-6044-4f69-9350-f5a1c84ad655

     Type                 Name          Plan     Info
     pulumi:pulumi:Stack  proxmox-prod           1 error


Diagnostics:
  pulumi:pulumi:Stack (proxmox-prod):
    error: Program failed with an unhandled exception:
    Traceback (most recent call last):
      File "/Users/phan/repo/pulumi/./__main__.py", line 11, in <module>
        nixos=proxmoxve.vm.VirtualMachine.get(resource_name="nixos1", id=100, node_name="proxmox")
      File "/Users/phan/repo/pulumi/.venv/lib/python3.9/site-packages/pulumi_proxmoxve/vm/virtual_machine.py", line 2366, in get
        return VirtualMachine(resource_name, opts=opts, __props__=__props__)
      File "/Users/phan/repo/pulumi/.venv/lib/python3.9/site-packages/pulumi_proxmoxve/vm/virtual_machine.py", line 2016, in __init__
        VirtualMachineArgs._configure(_setter, **kwargs)
    TypeError: _configure() missing 1 required positional argument: 'node_name'

Outputs:
  + vm : {
      + id       : "100"
      + name     : "nixos1"
      + node_name: "proxmox"
      + tags     : []
      + vm_id    : 100
    }
  + vms: {
      + id       : "e3d65838-d207-419d-9396-0816753adf7c"
      + node_name: <null>
      + tags     : <null>
      + vms      : [
      +     [0]: {
              + name     : "nixos1"
              + node_name: "proxmox"
              + tags     : []
              + vm_id    : 100
            }
      +     [1]: {
              + name     : "nixos-practice"
              + node_name: "proxmox"
              + tags     : []
              + vm_id    : 101
            }
        ]
    }

@muhlba91
Copy link
Owner

can you please check again with the newest version? i just tried to import one of my VMs and it worked without any problems.

my code was:

"""A Python Pulumi program"""

import pulumi
import pulumi_proxmoxve as proxmoxve

test_vm = proxmoxve.vm.get_virtual_machine(node_name="pve", vm_id=100)
pulumi.export("vm", test_vm)

the output of a preview was:

Previewing update (dev)

View in Browser (Ctrl+O): https://app.pulumi.com/muhlba91/pulumi-python/dev/previews/c87efab6-c1c2-4262-971b-f37de3b79c40

     Type                 Name               Plan
 +   pulumi:pulumi:Stack  pulumi-python-dev  create

Outputs:
    vm: {
        id       : "100"
        name     : "OPNSense"
        node_name: "pve"
        tags     : [
            [0]: "infrastructure"
            [1]: "prod"
        ]
        vm_id    : 100
    }

Resources:
    + 1 to create

my environment variables are (redacted):

export PROXMOX_VE_USERNAME="root@pam"
export PROXMOX_VE_PASSWORD="<PASSWORD>"
export PROXMOX_VE_ENDPOINT="https://<IP_ADDRESS>:8006/"
export PROXMOX_VE_INSECURE="true"

@muhlba91 muhlba91 added help wanted Extra attention is needed cannot-reproduce labels Oct 29, 2023
@henningphan
Copy link
Author

Your code worked, after changing the parameters. The output didnt really contain much information.

Is it possible to query an existing vm of its config so I can fill in the values requested of me when creating a new vm, like what bios, network configs, bridge etc...

See link for values of interest
https://www.pulumi.com/registry/packages/proxmoxve/

@muhlba91
Copy link
Owner

this extension needs to be filed in the upstream provider (https://github.com/bpg/terraform-provider-proxmox).
basically, this provider maps the terraform provider's actions and resources for pulumi.

you can see the relevant resource/datasource in upstream here: https://github.com/bpg/terraform-provider-proxmox/blob/main/proxmoxtf/datasource/vm.go#L29
the upstream datasource needs to be extended here before the pulumi provider can pick it up as well.

can you create an upstream issue and cross-reference it for tracking purposes?

@muhlba91 muhlba91 added potential-upstream-issue The issue is potentially upstream wontfix This will not be worked on and removed help wanted Extra attention is needed cannot-reproduce labels Oct 31, 2023
@henningphan henningphan reopened this Oct 31, 2023
@henningphan
Copy link
Author

henningphan commented Oct 31, 2023

Sorry for opening and closing, im pressing the wrong button...

Im not familiar with cross referencing issues in github, a fast google didnt make me any wiser. Is it just linking the issue here or do you want me to do something else?

Issue created
bpg/terraform-provider-proxmox#674

@muhlba91
Copy link
Owner

no worries, and thanks for the cross-referencing by posting the upstream issue link! it‘s just that one finds the upstream issue when checking that one out. 👍🏻

@henningphan
Copy link
Author

Do you want a new issue for implementing that, I take it as this issue has been resolved, and can be closed after agreeing on what to do with the upstream issue

@muhlba91
Copy link
Owner

just keep this one open. 🙂

once the upstream issue has been resolved/implemented and this provider updated, i‘ll close it as resolved.
until then everyone finding this issue knows that it‘s still open, and can find the link to the upstream issue for reference.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
potential-upstream-issue The issue is potentially upstream wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

2 participants