hashicorp / packer-plugin-vagrant

Packer plugin for Vagrant
https://packer.io
Mozilla Public License 2.0
15 stars 23 forks source link

Post-Processor: added `vagrantfile_template_content` option to allow for dynamic Vagrantfile content #112

Open VishnuJin opened 8 months ago

VishnuJin commented 8 months ago

As specified in the issue, users can now use templatefile function for dynamic content in Vagrantfile template

Example: A vagrant template file

Vagrant.configure("2") do |config|
  config.ssh.private_key_path = ${my_ssh_key}
  config.ssh.forward_agent = true
end

A packer file with vagrant post processor

locals {
   vagrantfile = templatefile("vagrantfile.pkrtpl.hcl", { 
      my_ssh_key = "~/.ssh/rsa"
    })
 }
 ....
 post-processor "vagrant" {
    vagrantfile_template_content = local.vagrantfile
 } 

Resulting Vagrantfile inside Box file


# The contents below were provided by the Packer Vagrant post-processor

Vagrant.configure("2") do |config|
    config.vm.provider :docker do |docker, override|
        docker.image = "sha256:47045c52cefdfd009eb4cfb69dc7c2ac3b2af7808abb218164a7a2264847c939"
    end
end

# The contents below (if any) are custom contents provided by the
# Packer template during image build.
Vagrant.configure("2") do |config|
  config.ssh.private_key_path = ~/.ssh/rsa
  config.ssh.forward_agent = true
end

Closes #104

nywilken commented 5 months ago

Hi @VishnuJin just want to follow up to see if you would like to continue with this change. Please let me know if you have time to continue pushing it forward and if you have any questions about the provided feedback.

Thank you for your contributions to this plugin.