boxcutter / windows

Virtual machine templates for Windows written in legacy JSON and Batch Scripting/JScript
Apache License 2.0
756 stars 264 forks source link

Update all the templates so that the vm_name and suffix are defined in user variables #217

Closed arizvisa closed 4 years ago

arizvisa commented 4 years ago

This PR simply replaces all of the vm_name keys defined in the builders with a user-variable vm_name. This makes it easier to change the "vm_name" by only needing to update it in one place.

The suffix for the *-cygwin.json and *-ssh.json templates was also made into a user variable (vm_suffix) in case the full name is desired to be controlled. As another benefit, this gives the user the ability to fully control the name of the box that is emitted.

The vagrantfile_template and any files that re-use the template name are not included as these are specific to the the template and so were considered part of the actual template. The output name in the post-processors is now 100% controlled by the user variables (excluding the hyphens).

arizvisa commented 4 years ago

All of the templates seem to validate w/o issue, just need to do a few test builds to 100% confirm the paths are the same.

arizvisa commented 4 years ago

Seems to work. Original template name was defined as the following which should emit the box under box/vmware/whatever.box. In the following tests, cm=salt (or cm=nocm), cm_version is undefined, and version=0.1.0. The value for the Provider template variabale is vmware (for the vmware-iso builder), and box_directory=box/.

      "output": "{{ user `box_directory` }}{{.Provider}}/eval-win7x86-enterprise-{{user `cm`}}{{user `cm_version`}}-{{user `version`}}.box",

Here's an example of the emitted box when using a template that specifies an empty vm_suffix.

$ packer build -only vmware-iso -var cpus=1 -var disk_size=102400 -var cm=salt eval-win7x86-enterprise.json
...
$ ls -l box/vmware/*.box
-rw-r--r-- 1 user None 3168410082 Jan 13 03:23 box/vmware/eval-win7x86-enterprise-salt-0.1.0.box

Here's an example of the emitted box when using a template that specifies a default vm_suffix (-ssh)

$ packer build -only vmware-iso -var cpus=1 -var disk_size=102400 -var cm=salt eval-win7x86-enterprise-ssh.json
...
$ ls -l box/vmware/*.box
-rw-r--r-- 1 user None 3168410082 Jan 13 03:23 box/vmware/eval-win7x86-enterprise-salt-0.1.0.box
-rw-r--r-- 1 user None 3144674582 Jan 13 03:42 box/vmware/eval-win7x86-enterprise-ssh-salt-0.1.0.box

And here's an example of the emitted box with an explicitly specified vm_suffix (-hithere). Ftr this build had to be pushed along by starting ssh due to issue #218 for the cygwin templates.

$ packer build -only vmware-iso -var cpus=1 -var disk_size=102400 -var cm=nocm -var vm_suffix=-hithere eval-win7x86-enterprise-cygwin.json
...
$ ls -l box/vmware/*.box
-rw-r--r-- 1 user None 5660928617 Jan 13 06:23 box/vmware/eval-win7x86-enterprise-hithere-nocm-0.1.0.box
-rw-r--r-- 1 user None 3168410082 Jan 13 03:23 box/vmware/eval-win7x86-enterprise-salt-0.1.0.box
-rw-r--r-- 1 user None 3144674582 Jan 13 03:42 box/vmware/eval-win7x86-enterprise-ssh-salt-0.1.0.box
arizvisa commented 4 years ago

...and to demonstrate fully controlling the name (after rm'ing the boxes made by the prior tests):

$ packer build -only vmware-iso -var cpus=1 -var disk_size=102400 -var cm=nocm -var vm_suffix=-mysuffix -var vm_name=myprefix-w7x64 eval-win7x64-enterprise-ssh.json
...
$ ls -l box/vmware/*.box
-rw-r--r-- 1 user None 4189152572 Jan 13 07:00 box/vmware/myprefix-w7x64-mysuffix-nocm-0.1.0.box