muhlba91/pulumi-proxmoxve

initialise provider with python

Closed this issue · 5 comments

Not sure if this is a bug or my coding:
I get this:
Diagnostics:
proxmoxve:VM:VirtualMachine (vm-1):
error: You must specify the virtual environment details in the provider configuration

After exporting the variables in the shell, this what I have for the provider:
import os
import pulumi
import pulumi_proxmoxve as proxmox

provider_ve = proxmox.Provider('proxmoxve',
virtual_environment=proxmox.ProviderVirtualEnvironmentArgs(
endpoint=os.environ['PROXMOX_VE_ENDPOINT'],
insecure=os.environ['PROXMOX_VE_INSECURE'],
username=os.environ['PROXMOX_VE_USERNAME'],
password=os.environ['PROXMOX_VE_PASSWORD']
),
),

I have vm config args and attempt to deploy with:
vm_1 = proxmox.vm.VirtualMachine("vm-1", args=vm1_conf_args,provider=provider_ve)

After chat on pulumi slack tried:
vm_1 = proxmox.vm.VirtualMachine("vm-1",args=vm1_conf_args,opts=pulumi.ResourceOptions(provider=provider_ve)) which threw this error:
File "./main.py", line 70, in
vm_1 = proxmox.vm.VirtualMachine("vm-1",args=vm1_conf_args,opts=pulumi.ResourceOptions(provider=provider_ve))
File "/home/admin-cs97/pulumi/talos-1/venv/lib/python3.8/site-packages/pulumi_proxmoxve/vm/virtual_machine.py", line 1176, in init
self._internal_init(resource_name, opts, **resource_args.dict)
File "/home/admin-cs97/pulumi/talos-1/venv/lib/python3.8/site-packages/pulumi_proxmoxve/vm/virtual_machine.py", line 1260, in _internal_init
super(VirtualMachine, self).init(
File "/home/admin-cs97/pulumi/talos-1/venv/lib/python3.8/site-packages/pulumi/resource.py", line 1081, in init
Resource.init(self, t, name, True, props, opts, False, dependency)
File "/home/admin-cs97/pulumi/talos-1/venv/lib/python3.8/site-packages/pulumi/resource.py", line 914, in init
if self._provider and self._provider.package != pkg:
AttributeError: 'tuple' object has no attribute 'package'

Hi,

your provider initialization looks good to me.

You should be able to initialize a VM like this:

VirtualMachine(
    "ubuntu-vm-0",
    name="ubuntu-vm-0",
    description="a ubuntu vm for test",
    # any other required and optional args…
    
    # use custom provider
    opts=pulumi.ResourceOptions(
        provider=proxmox_provider
    )
)

Alternatively, you can also pass in the VM args object (VirtualMachineArgs) as VirtualMachine("name", args=args_object, opts=…).

Hi,

I've tried what you suggest - see code here:

import os
import pulumi
import pulumi_proxmoxve as proxmox
# from pulumi_proxmoxve import ProviderVirtualEnvironmentArgs
# from pulumi_proxmoxve.vm import *

provider = proxmox.Provider('proxmoxve',
     virtual_environment=proxmox.ProviderVirtualEnvironmentArgs(
     endpoint=os.environ['PROXMOX_VE_ENDPOINT'],
     insecure=os.environ['PROXMOX_VE_INSECURE'],
     username=os.environ['PROXMOX_VE_USERNAME'],
     password=os.environ['PROXMOX_VE_PASSWORD'],
     ),
),

vm1_conf_args = proxmox.vm.VirtualMachineArgs(
        node_name="d08793",
        agent=proxmox.vm.VirtualMachineAgentArgs(
            enabled=False,
            trim=True,
            type="virtio",
            ),
        bios="seabios",
        cpu=proxmox.vm.VirtualMachineCpuArgs(
            cores=2,
            sockets=1
            ),
        clone=proxmox.vm.VirtualMachineCloneArgs(
            node_name="d08793",
            vm_id=10103,
            full=True
            ),
        disks=[
            proxmox.vm.VirtualMachineDiskArgs(
                interface="scsi0",
                datastore_id="netapp",
                size=32,
                file_format="qcow2"
                )
            ],
        memory=proxmox.vm.VirtualMachineMemoryArgs(
            dedicated=8192
            ),
        name="talos-vm-1",
        network_devices=[
            proxmox.vm.VirtualMachineNetworkDeviceArgs(
                bridge="vmbr0",
                model="virtio",
                vlan_id="2968",
                )
            ],
        on_boot=True,
        operating_system=proxmox.vm.VirtualMachineOperatingSystemArgs(
            type="l26"
            ),
        opts=pulumi.ResourceOptions(
             provider=provider
             )
        
        
    )

vm_1 = proxmox.vm.VirtualMachine("vm-1",args=vm1_conf_args)

This the error that is thrown:

 File "/home/admin-cs97/.pulumi/bin/pulumi-language-python-exec", line 110, in <lambda>
        coro = pulumi.runtime.run_in_stack(lambda: runpy.run_path(args.PROGRAM, run_name='__main__'))
      File "/usr/lib/python3.8/runpy.py", line 280, in run_path
        return _run_code(code, mod_globals, init_globals,
      File "/usr/lib/python3.8/runpy.py", line 86, in _run_code
        exec(code, run_globals)
      File "./__main__.py", line 23, in <module>
        vm1_conf_args = proxmox.vm.VirtualMachineArgs(
    TypeError: __init__() got an unexpected keyword argument 'opts'

If I do it this way:

vm_1 = proxmox.vm.VirtualMachine("vm-1",args=vm1_conf_args,opts=pulumi.ResourceOptions(provider=provider) )

I get this error:

File "./__main__.py", line 70, in <module>
        vm_1 = proxmox.vm.VirtualMachine("vm-1",args=vm1_conf_args,opts=pulumi.ResourceOptions(provider=provider) )
      File "/home/admin-cs97/pulumi/talos-1/venv/lib/python3.8/site-packages/pulumi_proxmoxve/vm/virtual_machine.py", line 1176, in __init__
        __self__._internal_init(resource_name, opts, **resource_args.__dict__)
      File "/home/admin-cs97/pulumi/talos-1/venv/lib/python3.8/site-packages/pulumi_proxmoxve/vm/virtual_machine.py", line 1260, in _internal_init
        super(VirtualMachine, __self__).__init__(
      File "/home/admin-cs97/pulumi/talos-1/venv/lib/python3.8/site-packages/pulumi/resource.py", line 1081, in __init__
        Resource.__init__(self, t, name, True, props, opts, False, dependency)
      File "/home/admin-cs97/pulumi/talos-1/venv/lib/python3.8/site-packages/pulumi/resource.py", line 914, in __init__
        if self._provider and self._provider.package != pkg:
    AttributeError: 'tuple' object has no attribute 'package'

Ok - seems I found the problem - I removed a comma after the initialisation of the provider and that has worked.

thanks for the update - great to hear! :)
if that‘s solved and working, can you please close the issue?