pulumi-templates/pve-ct-python/__main__.py

71 lines
2.1 KiB
Python

"""A ProxmoxVE VM template with Python"""
import yaml
from dotmap import DotMap
import pulumi
import pulumi_proxmoxve as proxmox
conf = DotMap(yaml.safe_load(open("input.yaml").read()))
config = pulumi.Config()
provider = proxmox.Provider("proxmoxve",
virtual_environment = {
"endpoint": conf.pve.url,
"insecure": conf.pve.insecure,
"username": conf.pve.username,
"password": config.require_secret("password")
}
)
ct = proxmox.ct.Container(conf.ct.name,
clone = proxmox.ct.ContainerCloneArgs(
vm_id = conf.ct.clone,
full = True
),
console = proxmox.ct.ConsoleArgs(
type = "serial",
tty_count = 1,
enabled = True
),
cpu = proxmox.ct.ContainerCpuArgs(cores = conf.ct.cores),
disk = proxmox.ct.ContainerDiskArgs(datastore_id = conf.pve.storage),
initialization = proxmox.ct.ContainerInitializationArgs(
hostname = conf.ct.name,
ip_configs = [
proxmox.ct.ContainerInitializationIpConfigArgs(
ipv4 = proxmox.ct.ContainerInitializationIpConfigIpv4Args(
address = "dhcp"
)
)
],
user_account = proxmox.ct.ContainerInitializationUserAccountArgs(
password = conf.ct.password,
keys = conf.ct.sshkeys
),
),
memory = proxmox.ct.ContainerMemoryArgs(
dedicated = conf.ct.ram,
swap = conf.ct.ram
),
network_interfaces = [
proxmox.ct.ContainerNetworkInterfaceArgs("mynic",
bridge = "vmbr0",
enabled = True
)
],
node_name = conf.pve.nodename,
operating_system = proxmox.ct.ContainerOperatingSystemArgs(
template_file_id = "debian-11-standard_11.3-1_amd64.tar.zst"
),
started = True,
opts = pulumi.ResourceOptions(
provider = provider
)
)
# Getting local IP
# First item of the ipv4_addresses is of the loopback interface (so the usual 127.0.0.1). Let's get the second and grab only the text.
lanip = ct.initialization["ip_configs"]["ipv4"]["address"][0]
pulumi.export("ip", lanip)