Skip to content

Example repo to use packer and terraform to build baselined templates and instances against a VMware environment without DHCP

Notifications You must be signed in to change notification settings

fatred/packer-build-staticip

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

packer-build-staticip

Example repo to use packer against a VMware environment without DHCP and then setup instances using terraform and VM Customisation Spec.

How to use me

Packer

Pre-reqs:

  • 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

Process

  1. Enter the packer/ubuntu-18 directory
  2. Setup all the vars in the variables-lab.json to meet your environment. Do not store your vcs creds in your variables!
  3. Export the creds in your cli session
export PACKER_USER='packer@vsphere.local'
export PACKER_PASS='lololololololololo10!'
  1. Run the packer validate proces
packer validate -var-file variables-lab.json ubuntu-18.json
  1. 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

Terraform

Pre-reqs

  • 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

Process

  1. Enter the terraform/lab directory
  2. Setup all the vars in globals.tf Do not store your vcs creds in your variables!
  3. Validate/extend the vcs_data.tf to include any additional assets (like datastores/vm port groups) you want to reference in your builds
  4. Setup your instance(s) you will build in inst_my_vm.tf
  5. export the creds in your cli session
export TF_VAR_vsphere_user='terraform@vsphere.local'
export TF_VAR_vsphere_password='lololololololololololo10!'
  1. Run a terraform init
terraform init
  1. Run a terraform validate
terraform validate
  1. Assuming you have a valid tf env, execute a plan
terraform plan
  1. Assuming your plan worked and you got the outcomes you expected, execute an apply
terraform apply

How to extend me

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.

About

Example repo to use packer and terraform to build baselined templates and instances against a VMware environment without DHCP

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages