diff --git a/CHANGELOG.md b/CHANGELOG.md index 08229c25e..4e8cad4f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ IMPROVEMENTS: * core: built with Go 1.1.2 * core: packer help output now loads much faster. +* builder/virtualbox: guest_additions_url can now use the `Version` + variable to get the VirtualBox version. [GH-272] * builder/virtualbox: Do not check for VirtualBox as part of template validation; only check at execution. * builder/vmware: Do not check for VMware as part of template validation; diff --git a/builder/virtualbox/builder.go b/builder/virtualbox/builder.go index a7b7cdd51..0dab4476e 100644 --- a/builder/virtualbox/builder.go +++ b/builder/virtualbox/builder.go @@ -132,8 +132,6 @@ func (b *Builder) Prepare(raws ...interface{}) error { // Errors templates := map[string]*string{ - "guest_additions_path": &b.config.GuestAdditionsPath, - "guest_additions_url": &b.config.GuestAdditionsURL, "guest_additions_sha256": &b.config.GuestAdditionsSHA256, "guest_os_type": &b.config.GuestOSType, "http_directory": &b.config.HTTPDir, @@ -160,6 +158,18 @@ func (b *Builder) Prepare(raws ...interface{}) error { } } + validates := map[string]*string{ + "guest_additions_path": &b.config.GuestAdditionsPath, + "guest_additions_url": &b.config.GuestAdditionsURL, + } + + for n, ptr := range validates { + if err := b.config.tpl.Validate(*ptr); err != nil { + errs = packer.MultiErrorAppend( + errs, fmt.Errorf("Error parsing %s: %s", n, err)) + } + } + for i, command := range b.config.BootCommand { if err := b.config.tpl.Validate(command); err != nil { errs = packer.MultiErrorAppend(errs, diff --git a/builder/virtualbox/step_download_guest_additions.go b/builder/virtualbox/step_download_guest_additions.go index 9f0c23cf4..0f0504a29 100644 --- a/builder/virtualbox/step_download_guest_additions.go +++ b/builder/virtualbox/step_download_guest_additions.go @@ -21,6 +21,10 @@ var additionsVersionMap = map[string]string{ "4.1.23": "4.1.22", } +type guestAdditionsUrlTemplate struct { + Version string +} + // This step uploads a file containing the VirtualBox version, which // can be useful for various provisioning reasons. // @@ -69,7 +73,19 @@ func (s *stepDownloadGuestAdditions) Run(state map[string]interface{}) multistep // Use the provided source (URL or file path) or generate it url := config.GuestAdditionsURL - if url == "" { + if url != "" { + tplData := &guestAdditionsUrlTemplate{ + Version: version, + } + + url, err = config.tpl.Process(url, tplData) + if err != nil { + err := fmt.Errorf("Error preparing guest additions url: %s", err) + state["error"] = err + ui.Error(err.Error()) + return multistep.ActionHalt + } + } else { url = fmt.Sprintf( "http://download.virtualbox.org/virtualbox/%s/%s", version,