2017-04-06 05:19:17 -04:00
|
|
|
package vagrant
|
|
|
|
|
|
|
|
import (
|
|
|
|
"bytes"
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
"text/template"
|
2018-04-18 17:53:59 -04:00
|
|
|
|
2020-11-19 14:54:31 -05:00
|
|
|
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
2017-04-06 05:19:17 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
type scalewayVagrantfileTemplate struct {
|
|
|
|
Image string ""
|
|
|
|
Region string ""
|
|
|
|
}
|
|
|
|
|
|
|
|
type ScalewayProvider struct{}
|
|
|
|
|
|
|
|
func (p *ScalewayProvider) KeepInputArtifact() bool {
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
2020-11-19 15:17:11 -05:00
|
|
|
func (p *ScalewayProvider) Process(ui packersdk.Ui, artifact packersdk.Artifact, dir string) (vagrantfile string, metadata map[string]interface{}, err error) {
|
2017-04-06 05:19:17 -04:00
|
|
|
// Create the metadata
|
|
|
|
metadata = map[string]interface{}{"provider": "scaleway"}
|
|
|
|
|
|
|
|
// Determine the image and region...
|
|
|
|
tplData := &scalewayVagrantfileTemplate{}
|
|
|
|
|
|
|
|
parts := strings.Split(artifact.Id(), ":")
|
|
|
|
if len(parts) != 2 {
|
|
|
|
err = fmt.Errorf("Poorly formatted artifact ID: %s", artifact.Id())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
tplData.Region = parts[0]
|
|
|
|
tplData.Image = parts[1]
|
|
|
|
|
|
|
|
// Build up the Vagrantfile
|
|
|
|
var contents bytes.Buffer
|
|
|
|
t := template.Must(template.New("vf").Parse(defaultScalewayVagrantfile))
|
|
|
|
err = t.Execute(&contents, tplData)
|
|
|
|
vagrantfile = contents.String()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
var defaultScalewayVagrantfile = `
|
|
|
|
Vagrant.configure("2") do |config|
|
|
|
|
config.vm.provider :scaleway do |scaleway|
|
|
|
|
scaleway.image = "{{ .Image }}"
|
|
|
|
scaleway.region = "{{ .Region }}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
`
|