hashicorp / packer-plugin-vagrant

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

Allow specifying content for vagrantfile_template #104

Open flmmartins opened 1 year ago

flmmartins commented 1 year ago

Community Note

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.

Description

Today vagrantfile_template needs to be a file path.

Allow to specify vagrantfile_template_content in Vagrant post processor so I can use templatefile with it.

Use Case(s)

I want to specify my own SSH to be used in Vagrant instead of the public one therefore I would like to inject a vagrant with the following:

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

This could be applied many configurations in the Vagrantfile. This is only an example.

Potential configuration

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

Potential References

https://developer.hashicorp.com/packer/integrations/hashicorp/vagrant/latest/components/post-processor/vagrant

lbajolet-hashicorp commented 1 year ago

Hi @flmmartins,

Thanks for the suggestion, this is a Vagrant plugin specific issue so I'll transfer it to the plugin now.

This is likely simple to implement, would you be interested in contributing it potentially? We'd happily help if so, and review the code for certain!

flmmartins commented 1 year ago

Sure. I will see if I can propose a PR although I don't have experience with Go but it will be a good learning opportunity.

lbajolet-hashicorp commented 1 year ago

Awesome, thanks @flmmartins

Don't hesitate to reach out if you need some help, happy to provide!