hashicorp / hashicorp/packer-plugin-lxd

Proposal: A dedicated lxc-exec provisioner

Open
#17 0 comments 2 reactions 0 assignees View on GitHub
enhancement good first issue help wanted
Dominant language
Go
Stars
14
Forks
20
PR merge metrics
No merged PRs in 30d

Description

The `lxc exec` command has many powerful flags, including

* `--uid` and `--gid` to set the user and group of the subprocess on the remote container
* `--cwd` to set the working directory
* `--env` for environment variables
* ...and more

Taking advantage of these right now requires the `shell-local` provisioner.

Consider this configuration snippet.

```hcl
locals {
git_script = "/tmp/git-script.sh"
}

source "lxd" "arch" {
image = "images:archlinux/cloud"
}

build {
source "lxd.arch" {
name = "arch-ci"
output_image = "arch-ci"
}

provisioner "file" {
source = "./git-script.sh"
destination = "${local.git_script}"
}

provisioner "shell" {
inline = [
"pacman -Syyu --noconfirm",
"pacman -Sy --noconfirm man make cmake git python python2 ninja clang lld htop jq neovim kitty-terminfo openssh",
"useradd -m builder",
"systemctl enable --now sshd",
]
}

provisioner "shell-local" {
inline = [
"lxc exec packer-arch --env HOME=/home/builder --cwd /home/builder --user 1001 --group 1001 -- mkdir /home/builder/.ssh",
"lxc exec packer-arch --env HOME=/home/builder --cwd /home/builder --user 1001 --group 1001 -- ${local.git_script}",
]
}
}
```

A dedicated `lxc-exec` provisioner would allow reducing this duplication. It would be really useful, because if you don't set these flags, you're running as root in a pretty bare process environment.

#### Potential configuration

```
provisioner "lxc-exec" {
environment_vars = ["HOME=/home/builder"]
user = 1000
group = 1000
working_directory = "/home/builder"
inline = [
"echo I'm run with uid 1000 from /home/builder",
]
}
```

#### Potential References

Potential prior art is the Puppet Bolt plugin https://github.com/puppetlabs/bolt/issues/2311

Contributor guide

Open the contributing guide

Research direction

Start by comparing the existing shell-local approach with the proposed lxc-exec configuration and the referenced Puppet Bolt issue. Done means a dedicated lxc-exec provisioner supports the listed execution options for inline commands; the issue names no repository files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, linux
Domain
infrastructure
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.