github.com/raghuse92/packer@v1.3.2/post-processor/vagrant/digitalocean.go (about) 1 package vagrant 2 3 import ( 4 "bytes" 5 "fmt" 6 "strings" 7 "text/template" 8 9 "github.com/hashicorp/packer/packer" 10 ) 11 12 type digitalOceanVagrantfileTemplate struct { 13 Image string "" 14 Region string "" 15 } 16 17 type DigitalOceanProvider struct{} 18 19 func (p *DigitalOceanProvider) KeepInputArtifact() bool { 20 return true 21 } 22 23 func (p *DigitalOceanProvider) Process(ui packer.Ui, artifact packer.Artifact, dir string) (vagrantfile string, metadata map[string]interface{}, err error) { 24 // Create the metadata 25 metadata = map[string]interface{}{"provider": "digital_ocean"} 26 27 // Determine the image and region... 28 tplData := &digitalOceanVagrantfileTemplate{} 29 30 parts := strings.Split(artifact.Id(), ":") 31 if len(parts) != 2 { 32 err = fmt.Errorf("Poorly formatted artifact ID: %s", artifact.Id()) 33 return 34 } 35 tplData.Region = parts[0] 36 tplData.Image = parts[1] 37 38 // Build up the Vagrantfile 39 var contents bytes.Buffer 40 t := template.Must(template.New("vf").Parse(defaultDigitalOceanVagrantfile)) 41 err = t.Execute(&contents, tplData) 42 vagrantfile = contents.String() 43 return 44 } 45 46 var defaultDigitalOceanVagrantfile = ` 47 Vagrant.configure("2") do |config| 48 config.vm.provider :digital_ocean do |digital_ocean| 49 digital_ocean.image = "{{ .Image }}" 50 digital_ocean.region = "{{ .Region }}" 51 end 52 end 53 `