# Packing multiple instances in parallel

**URL:** <https://discuss.hashicorp.com/t/packing-multiple-instances-in-parallel/20306>\
**Category:** Packer\
**Created:** [January 29, 2021, 8:49am UTC](https://discuss.hashicorp.com/t/packing-multiple-instances-in-parallel/20306 "2021-01-29T08:49:54Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![aracloud](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/aracloud/32/16647_2.png) [@aracloud](https://discuss.hashicorp.com/u/aracloud)\
**Post date:** [January 29, 2021, 8:49am UTC](https://discuss.hashicorp.com/t/packing-multiple-instances-in-parallel/20306/1 "2021-01-29T08:49:54Z")

</div>

Hi,

I play arround with packer in order to build up my lab on ESXi:

> **[aracloud/packer-ubuntu](https://github.com/aracloud/packer-ubuntu)**
>
> Contribute to aracloud/packer-ubuntu development by creating an account on GitHub.

I’m struggling with how to build multiple vm on ESXi.  
So far I can only build one instance and I would like to know how to build several and parameterize such a deployment.

Target is to get several equal instances built.

Thx for your help!

---

<div class="post-metadata">

**Author:** ![tbugfinder](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/tbugfinder/32/12689_2.png) [@tbugfinder](https://discuss.hashicorp.com/u/tbugfinder)\
**Post date:** [January 29, 2021, 5:50pm UTC](https://discuss.hashicorp.com/t/packing-multiple-instances-in-parallel/20306/2 "2021-01-29T17:50:22Z")

</div>

Do you want to build images or build instances?

---

<div class="post-metadata">

**Author:** ![Wolfsrudel](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/wolfsrudel/32/28465_2.png) [@Wolfsrudel](https://discuss.hashicorp.com/u/Wolfsrudel)\
**Post date:** [January 29, 2021, 7:10pm UTC](https://discuss.hashicorp.com/t/packing-multiple-instances-in-parallel/20306/3 "2021-01-29T19:10:38Z")

</div>

You’ll have to build an image (as a template) and clone it to one to x vm(s).

But… For the last part you’ll have to use Terraform or something else. Packer won’t do it for you. 😉

This is the way.

---

<div class="post-metadata">

**Author:** ![aracloud](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/aracloud/32/16647_2.png) [@aracloud](https://discuss.hashicorp.com/u/aracloud)\
**Post date:** [January 29, 2021, 9:27pm UTC](https://discuss.hashicorp.com/t/packing-multiple-instances-in-parallel/20306/4 "2021-01-29T21:27:18Z")

</div>

Thx for your replay. I searched and have found following that looks promissing.

> **[Deploying VMware vSphere Virtual Machines with Packer & Terraform](https://gmusumeci.medium.com/deploying-vmware-vsphere-virtual-machines-with-packer-terraform-d0211f72b7f5)**
>
> How to deploy Windows and Linux virtual machines in VMware vSphere using HashiCorp Packer and HashiCorp Terraform.

---

<div class="post-metadata">

**Author:** ![timblaktu](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/timblaktu/32/14584_2.png) [@timblaktu](https://discuss.hashicorp.com/u/timblaktu)\
**Post date:** [February 1, 2021, 8:20pm UTC](https://discuss.hashicorp.com/t/packing-multiple-instances-in-parallel/20306/5 "2021-02-01T20:20:04Z")

</div>

Terraform can certainly do this, but it should be said here that packer’s vsphere-iso builder (and others) can do this without Terraform. Also, a vSphere template is not technically required to get packer to build multiple VMs on ESXi/vSphere. Depending on your use case, using a templated, chained approach might be the way to go, however, as it can save a lot of (build) time.

To my initial point (packer can do this, without TF and without VM templates), you would simply define multiple builders in your packer template, and these will by default be built in parallel.

…and like me, you will likely find that using HCL2 instead of json will pay off in spades, since with HCL2 you can do things like define your builder as a “source” that can be reused across your multiple builders…

---

<div class="post-metadata">

**Author:** ![aracloud](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/aracloud/32/16647_2.png) [@aracloud](https://discuss.hashicorp.com/u/aracloud)\
**Post date:** [February 2, 2021, 12:55pm UTC](https://discuss.hashicorp.com/t/packing-multiple-instances-in-parallel/20306/6 "2021-02-02T12:55:33Z")

</div>

thx for the replay !!!

So, this means it would be possible with HCL2 to  
parameterize one builder in order to build  
several instance from a list, array whatever?

I built a repo with a basic approach but this is more or less static:

> **[aracloud/packer-ubuntu-esxi](https://github.com/aracloud/packer-ubuntu-esxi)**
>
> Contribute to aracloud/packer-ubuntu-esxi development by creating an account on GitHub.

Based on that repo I save the ovf locally but I want to setup three  
VM’s in ESXi and used them right away.

I’m not familar with HCL2 but I need to dig into.

My target would be at the end to install k8s on three nodes.  
One master and two worker nodes.

Thx

---

<div class="post-metadata">

**Author:** ![aracloud](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/aracloud/32/16647_2.png) [@aracloud](https://discuss.hashicorp.com/u/aracloud)\
**Post date:** [February 2, 2021, 11:00pm UTC](https://discuss.hashicorp.com/t/packing-multiple-instances-in-parallel/20306/7 "2021-02-02T23:00:23Z")

</div>

@timblaktu does HCL2 support loops as well?

---

<div class="post-metadata">

**Author:** ![tbugfinder](https://sea2.discourse-cdn.com/hashicorp/user_avatar/discuss.hashicorp.com/tbugfinder/32/12689_2.png) [@tbugfinder](https://discuss.hashicorp.com/u/tbugfinder)\
**Post date:** [February 3, 2021, 7:27pm UTC](https://discuss.hashicorp.com/t/packing-multiple-instances-in-parallel/20306/8 "2021-02-03T19:27:32Z")

</div>

HCL2 syntax includes for, for\_each patterns.  
An intro might be here:

> **[Expressions - Configuration Language | Packer by HashiCorp](https://www.packer.io/docs/from-1.5/expressions#for-expressions)**
>
> HCL allows the use of expressions to access data exported
> by sources and to transform and combine that data to produce other values.

---

<div class="post-metadata">

**Author:** ![eldhosemathewv](https://avatars.discourse-cdn.com/v4/letter/e/97f17d/32.png) [@eldhosemathewv](https://discuss.hashicorp.com/u/eldhosemathewv)\
**Post date:** [July 27, 2023, 3:39pm UTC](https://discuss.hashicorp.com/t/packing-multiple-instances-in-parallel/20306/9 "2023-07-27T15:39:02Z")

</div>

@aracloud , Do you have any reference packer template for parallel packer build to deploy VMs inside the nested esxi? if yes, could you please share,  
I’m working on to get the esxi deployed along with VMs inside to it
