Add vagrant post-processor support for Google

Add the ability to create Google vagrant boxes
using the vagrant post-processor. The Google
plugin for vagrant is linked below.

https://github.com/mitchellh/vagrant-google
This commit is contained in:
Sean Malloy 2017-12-23 00:13:17 -06:00
parent a67d4024b3
commit e47bd65986
3 changed files with 48 additions and 2 deletions

View File

@ -0,0 +1,42 @@
package vagrant
import (
"bytes"
"text/template"
"github.com/hashicorp/packer/packer"
)
type googleVagrantfileTemplate struct {
Image string ""
}
type GoogleProvider struct{}
func (p *GoogleProvider) KeepInputArtifact() bool {
return true
}
func (p *GoogleProvider) Process(ui packer.Ui, artifact packer.Artifact, dir string) (vagrantfile string, metadata map[string]interface{}, err error) {
// Create the metadata
metadata = map[string]interface{}{"provider": "google"}
// Build up the template data to build our Vagrantfile
tplData := &googleVagrantfileTemplate{}
tplData.Image = artifact.Id()
// Build up the Vagrantfile
var contents bytes.Buffer
t := template.Must(template.New("vf").Parse(defaultGoogleVagrantfile))
err = t.Execute(&contents, tplData)
vagrantfile = contents.String()
return
}
var defaultGoogleVagrantfile = `
Vagrant.configure("2") do |config|
config.vm.provider :google do |google|
google.image = "{{ .Image }}"
end
end
`

View File

@ -25,6 +25,7 @@ var builtins = map[string]string{
"mitchellh.vmware": "vmware", "mitchellh.vmware": "vmware",
"mitchellh.vmware-esx": "vmware", "mitchellh.vmware-esx": "vmware",
"pearkes.digitalocean": "digitalocean", "pearkes.digitalocean": "digitalocean",
"packer.googlecompute": "google",
"packer.parallels": "parallels", "packer.parallels": "parallels",
"MSOpenTech.hyperv": "hyperv", "MSOpenTech.hyperv": "hyperv",
"transcend.qemu": "libvirt", "transcend.qemu": "libvirt",
@ -232,6 +233,8 @@ func providerForName(name string) Provider {
return new(HypervProvider) return new(HypervProvider)
case "libvirt": case "libvirt":
return new(LibVirtProvider) return new(LibVirtProvider)
case "google":
return new(GoogleProvider)
default: default:
return nil return nil
} }

View File

@ -32,6 +32,7 @@ providers.
- AWS - AWS
- DigitalOcean - DigitalOcean
- Google
- Hyper-V - Hyper-V
- Parallels - Parallels
- QEMU - QEMU
@ -100,8 +101,8 @@ Specify overrides within the `override` configuration by provider name:
In the example above, the compression level will be set to 1 except for VMware, In the example above, the compression level will be set to 1 except for VMware,
where it will be set to 0. where it will be set to 0.
The available provider names are: `aws`, `digitalocean`, `virtualbox`, `vmware`, The available provider names are: `aws`, `digitalocean`, `google`, `virtualbox`,
and `parallels`. `vmware`, and `parallels`.
## Input Artifacts ## Input Artifacts