hashicorp / packer-plugin-proxmox

Packer plugin for Proxmox Builder
https://www.packer.io/docs/builders/proxmox
Mozilla Public License 2.0
159 stars 70 forks source link

Builders for creating/cloning containers (CTs) #190

Open chrisbenincasa opened 1 year ago

chrisbenincasa commented 1 year ago

Please search the existing issues for relevant feature requests, and use the reaction feature (https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to add upvotes to pre-existing requests.

Community Note

Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request. Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request. If you are interested in working on this issue or have submitted a pull request, please leave a comment.

Description

New builders for creating and cloning CTs (containers) and / or converting them into templates

Use Case(s)

Containers are a core feature of Proxmox, alongside VMs. It would be useful to automate the creation of container templates, etc.

Potential configuration

I have a minimal working version of container creation in my fork of the plugin. I'd be happy to take a stab at implementing the new builders! The configuration I have looks like:

source "proxmox-ct" "test" {
  username                 = "${var.pve_api_token_id}"
  token                    = "${var.pve_api_token_secret}"
  proxmox_url              = "${var.pve_url}"
  node                     = "zeus"
  insecure_skip_tls_verify = true
  os_template              = "local:vztmpl/debian-11-standard_11.6-1_amd64.tar.zst"
  storage                  = "local-zfs"

  cores     = 1
  cpu_limit = 500
  memory    = 512

  network_interfaces {
    name     = "eth0"
    bridge   = "vmbr0"
    firewall = false
    ip       = "dhcp"
  }

  user_password = "${var.user_password}"

  start = true
}

build {
  sources = ["sources.proxmox-ct.test"]

  provisioner "shell" {
    inline = [
      "ls /"
    ]
  }
}

Potential References

https://pve.proxmox.com/pve-docs/api-viewer/#/nodes/{node}/lxc https://pve.proxmox.com/pve-docs/api-viewer/#/nodes/{node}/lxc/{vmid}/template

chrisbenincasa commented 1 year ago

Update on my attempt here, here's the WIP: https://github.com/hashicorp/packer-plugin-proxmox/compare/main...chrisbenincasa:packer-plugin-proxmox:ct-create?expand=1

Few notes:

newedgex commented 1 year ago

This is a very good improvement , it's a must have to automate basically everything with packer

haxwithaxe commented 10 months ago

It appears the missing piece is in APIv2 https://pve.proxmox.com/pve-docs/api-viewer/index.html#/nodes/{node}/lxc/{vmid}/interfaces

chrisbenincasa commented 10 months ago

It's been a while but if I remember correctly, that API endpoint will only return an IP address if it was statically assigned by the host node and not if DHCP was used

haxwithaxe commented 10 months ago

I just tested with an LXC container configured to use DHCP. The API gives me the IP given by DHCP. :)

pvesh get /nodes/ank/lxc/104/interfaces --noborder
hwaddr            name inet              inet6
00:00:00:00:00:00 lo   127.0.0.1/8       ::1/128
bc:24:11:39:62:84 eth0 192.168.10.219/24 fe80::be24:11ff:fe39:6284/64
chrisbenincasa commented 10 months ago

Oh that's awesome! That will definitely simplify the implementation

emaiax commented 3 weeks ago

hey @chrisbenincasa, outstanding work you have in the PR. This is definitely a must have to build images and container templates on my homelab. Do you know if it's far from stable or it can be used as is?