Crates.io | packer_rs |
lib.rs | packer_rs |
version | |
source | src |
created_at | 2024-12-12 06:00:28.147633 |
updated_at | 2024-12-12 06:00:28.147633 |
description | A Rust wrapper for HashiCorp Packer CLI |
homepage | |
repository | https://github.com/tristanpoland/packer_rs |
max_upload_size | |
id | 1480882 |
Cargo.toml error: | TOML parse error at line 18, column 1 | 18 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
A simple Rust wrapper around HashiCorp Packer CLI. This lets you run Packer commands from your Rust code without dealing with raw command line stuff.
First, make sure you have the Packer CLI installed and available in your project directory (as packer
on Linux/Mac or packer.exe
on Windows).
Add this to your Cargo.toml
:
[dependencies]
packer_rs = "0.1"
Here's a quick example:
use packer_rs::{Packer, BuildOptionsBuilder};
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create a new Packer instance
let packer = Packer::new()?;
// Set up some build options
let options = BuildOptionsBuilder::default()
.debug(true)
.vars(vec![("region", "us-west-2")])
.build()?;
// Build your template
packer.build("template.pkr.hcl", &options)?;
Ok(())
}
The wrapper supports the main Packer commands:
build
: Build images from a templateinit
: Set up a new templatevalidate
: Check if a template is validinspect
: Look at template detailsfix
: Fix old templatesconsole
: Start Packer consoleplugin
: Manage Packer pluginsWhen building templates, you can set various options using BuildOptionsBuilder
:
let options = BuildOptionsBuilder::default()
.debug(true) // Enable debug mode
.force(true) // Force builds
.parallel_builds(2) // Run 2 builds at once
.timestamp_ui(true) // Show timestamps
.vars(vec![ // Set variables
("region", "us-west-2"),
("instance_type", "t2.micro")
])
.var_files(vec!["vars.json".into()]) // Load vars from files
.build()?;
You can set a different working directory for commands:
let packer = Packer::new()?
.with_working_dir("./my-templates");
The wrapper returns proper Rust errors that tell you what went wrong. Main error types:
NotFound
: Can't find the Packer executableExecutionError
: Command failed to runConfigError
: Something wrong with the configurationIoError
: File system problemsFeel free to open issues or send pull requests if you find bugs or want to add features.
MIT licensed. Do what you want with it.