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

Builders for creating/cloning containers (CTs) #190

Open
chrisbenincasa opened this issue May 6, 2023 · 6 comments
Open

Builders for creating/cloning containers (CTs) #190

chrisbenincasa opened this issue May 6, 2023 · 6 comments

Comments

@chrisbenincasa
Copy link

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
Copy link
Author

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:

  • Currently, this is able to create CT templates, very similar to how the ISO builder works for VMs
  • It requires SSH access to the Proxmox host itself, which is sort of unfortunate. This is necessary because the Proxmox API does not expose the DHCP-assigned IP addresses for a container in the same way it does for VMs that have the QEMU agent running. This is a long standing issue in Proxmox itself: https://bugzilla.proxmox.com/show_bug.cgi?id=2602
    • The provisioning method works by SSH'ing into the host and then proxying a series of pct exec commands to run inside of the container. This functionality also isn't exposed by the API
    • I'm still working on some of the more complex interactions, like uploading an entire directory into the container. pct push / pull is limited to single files and working within the confines of running these over SSH is even more limiting.

@newedgex
Copy link

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

@haxwithaxe
Copy link

@chrisbenincasa
Copy link
Author

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
Copy link

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
Copy link
Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants