项目作者: ryan4yin

项目描述 :
A Pulumi Provider which adds support for Proxmox solutions.
高级语言: Go
项目地址: git://github.com/ryan4yin/pulumi-proxmox.git
创建时间: 2020-12-13T05:23:30Z
项目社区:https://github.com/ryan4yin/pulumi-proxmox

开源协议:Other

下载


Pulumi Provider for Proxmox

master branch status
PYPI Version

A Pulumi Provider which adds support for Proxmox solutions.

based on danitso/terraform-provider-proxmox, read its docs for details.

TODO

  • fix Bug: cannot read configuration from EnvVars PROXMOX_VE_ENDPOINT PROXMOX_VE_USERNAME etc.
  • fix github actions, build and upload resource plugin to github releases automatically.
  • set resource plugin download url(github releases).

Installation

  1. Resources plugin for Linux are available as tarballs in the release page.
  2. Follow the installation instructions in release page to install the resource plugin and the python sdk.
  3. for other languages, ​​please install sdk from source in the sdk folder.

Build and Install the provider From Source

In order to properly build the sdks, the following tools are expected:

to build all the sdks, you need install and set up all the 4 language sdks first: go/dotnet/python/nodejs.

then use the following command to build the resource plugin and all the sdks:

  1. make build_sdks

Install Resource Plugin

first, build and install resource plugin:

  1. make install_resource_plugin

Note: Installing package directly from the package registry like pypi/npm/nuget is not supported yet, you need to install package from source via make.

Node.js (Java/TypeScript)

  1. make install_nodejs_sdk

Python

  1. make install_python_sdk

Go

To use from Go, use go get to grab the latest version of the library

  1. $ go get github.com/ryan4yin/pulumi-proxmox/sdk/go/...

.NET

To use from .NET, use the following command:

  1. $ make install_dotnet_sdk

Configuration

In addition to terraform generic provider arguments (e.g. alias and version), the following arguments are supported in the Proxmox provider block:

  • virtual_environment - (Optional) The Proxmox Virtual Environment configuration.
    • endpoint - (Required) The endpoint for the Proxmox Virtual Environment API (can also be sourced from PROXMOX_VE_ENDPOINT).
    • insecure - (Optional) Whether to skip the TLS verification step (can also be sourced from PROXMOX_VE_INSECURE). If omitted, defaults to false.
    • otp - (Optional) The one-time password for the Proxmox Virtual Environment API (can also be sourced from PROXMOX_VE_OTP).
    • password - (Required) The password for the Proxmox Virtual Environment API (can also be sourced from PROXMOX_VE_PASSWORD).
    • username - (Required) The username and realm for the Proxmox Virtual Environment API (can also be sourced from PROXMOX_VE_USERNAME).

Examples

set pve Environment variables first:

  1. export PROXMOX_VE_ENDPOINT="https://<server-host>:8006"
  2. export PROXMOX_VE_INSECURE=true
  3. export PROXMOX_VE_USERNAME=root@pam
  4. export PROXMOX_VE_PASSWORD="<password>"

Create VirtualMachine using Python SDK(writing in other languages ​​is almost the same):

  1. import os
  2. from pathlib import Path
  3. import pulumi
  4. from pulumi_proxmox import Provider, ProviderVirtualEnvironmentArgs
  5. from pulumi_proxmox.vm import *
  6. # this provider cannot read configuration from Environment variables yet,
  7. # You must manually pass parameters by instantiating a custom provider
  8. proxmox_provider = Provider(
  9. "proxmox-provider",
  10. virtual_environment=ProviderVirtualEnvironmentArgs(
  11. endpoint=os.getenv("PROXMOX_VE_ENDPOINT"),
  12. insecure=os.getenv("PROXMOX_VE_INSECURE") == "true",
  13. username=os.getenv("PROXMOX_VE_USERNAME"),
  14. password=os.getenv("PROXMOX_VE_PASSWORD")
  15. )
  16. )
  17. # create a virtual machine
  18. VirtualMachine(
  19. "ubuntu-vm-0",
  20. name="ubuntu-vm-0",
  21. description="a ubuntu vm for test",
  22. node_name="pve",
  23. on_boot=True, # start the vm during system bootup
  24. reboot=False, # reboot the vm after it was created successfully
  25. started=True, # start the vm after it was created successfully
  26. # clone from a vm template
  27. clone=VirtualMachineCloneArgs(
  28. vm_id=9000, # template's vmId
  29. full=True, # full clone, not linked clone
  30. datastore_id="local-lvm", # template's datastore
  31. node_name="pve", # template's node name
  32. ),
  33. # resource pool name
  34. pool_id="test-resource",
  35. cpu=VirtualMachineCpuArgs(
  36. cores=2,
  37. sockets=2,
  38. type="kvm64", # set it to kvm64 for better vm migration
  39. ),
  40. memory=VirtualMachineMemoryArgs(
  41. dedicated="4096", # unit: MB
  42. shared="4096"
  43. ),
  44. operating_system=VirtualMachineOperatingSystemArgs(
  45. type="l26" # l26: linux2.6-linux5.x
  46. ),
  47. agent=VirtualMachineAgentArgs(
  48. # please confirm you have qemu-guest-agent in your vm before enable this!
  49. # otherwise this may cause the vm to fail to shutdown/reboot!
  50. enabled=False,
  51. timeout="60s", # timeout
  52. ),
  53. disks=[
  54. VirtualMachineDiskArgs(
  55. interface="scsi0",
  56. datastore_id="local-lvm",
  57. size="30", # unit: GB
  58. )
  59. ],
  60. network_devices=[
  61. VirtualMachineNetworkDeviceArgs(
  62. enabled=True,
  63. bridge="vmbr0",
  64. model="virtio",
  65. vlan_id=0,
  66. )
  67. ],
  68. # cloud init configuration
  69. initialization=VirtualMachineInitializationArgs(
  70. type="nocloud", # 'nocloud' for linux, 'configdrive2' for windows
  71. datastore_id="local-lvm",
  72. dns=VirtualMachineInitializationDnsArgs(
  73. # dns servers,
  74. server="114.114.114.114,8.8.8.8",
  75. ),
  76. ip_configs=[
  77. VirtualMachineInitializationIpConfigArgs(
  78. ipv4=VirtualMachineInitializationIpConfigIpv4Args(
  79. address="192.168.1.111/24",
  80. gateway="192.168.1.1"
  81. )
  82. )
  83. ],
  84. user_account=VirtualMachineInitializationUserAccountArgs(
  85. # set root's ssh key
  86. keys=[
  87. Path("ssh-common.pub").read_text()
  88. ],
  89. password="chage_me", # needed when login from console
  90. username="root",
  91. )
  92. ),
  93. # use custom provider
  94. opts=pulumi.ResourceOptions(
  95. provider=proxmox_provider
  96. )
  97. )

Reference

please read danitso/terraform-provider-proxmox‘s docs for details.

Developing the Provider

all information about sdks are configured in provider/resources.go, if you want to help me, take a look at it.

pulumi providers:

terraform providers: