Example repo to use packer against a VMware environment without DHCP and then setup instances using terraform and VM Customisation Spec.
- Install packer. We used v1.4.5 from here
- Install the JetBrains packer-builder-vsphere-iso module into ~/.packer.d/plugins - fetch from here
- An account in vSphere with the correct permissions
- A copy of the Ubuntu 18.04 Server iso. We use 18.04.3 from here. If you change that, update the shasum in ubuntu-18.json
- Enter the packer/ubuntu-18 directory
- Setup all the vars in the variables-lab.json to meet your environment. Do not store your vcs creds in your variables!
- Export the creds in your cli session
export PACKER_USER='packer@vsphere.local'
export PACKER_PASS='lololololololololo10!'
- Run the packer validate proces
packer validate -var-file variables-lab.json ubuntu-18.json
- Assuming you have a valid template, execute.
packer build -var-file variables-lab.json ubuntu-18.json
Packer will now take about 15 mins to build your image and mark it as a template
- Install terraform. We used v1.12.13 from here
- An account in vSphere with the correct permissions
- A VM Customisation spec in vCenter for Ubuntu-18 - we used this doc
- Enter the terraform/lab directory
- Setup all the vars in globals.tf Do not store your vcs creds in your variables!
- Validate/extend the vcs_data.tf to include any additional assets (like datastores/vm port groups) you want to reference in your builds
- Setup your instance(s) you will build in inst_my_vm.tf
- export the creds in your cli session
export TF_VAR_vsphere_user='terraform@vsphere.local'
export TF_VAR_vsphere_password='lololololololololololo10!'
- Run a terraform init
terraform init
- Run a terraform validate
terraform validate
- Assuming you have a valid tf env, execute a plan
terraform plan
- Assuming your plan worked and you got the outcomes you expected, execute an apply
terraform apply
Since the JetBrains vSphere clone module doesnt support vm customisation, we just made a copy of the same ubuntu-18 folder, making a new one like ubuntu-18-k8s-node, (updating the name of the .json manifest as well), and then amending the ansible playbook section to include additional roles. There is a PR open for the inclusion of vm customisation in the vsphere-clone method, but as yet, no interest from the maintainers (seems they dont have the problem, so fair enough). I have no Go chops or I would have a spin at it. Maybe one day.