Packer Validation/Build Dependent Concept?

In Terraform there is a concept of dependency (depends option) that allows you to specify modules to be dependent on other modules.

Is there such a concept in Packer?

Use case:

  1. Create source based on template
  2. Build file based on the source template
  3. Use that file within the build of a VM’s provisioner section


  • When you run the validation test, it will fail saying the ‘var.vm_local_setup_default_profile_ps1’ does not exist.
  • When you run the build process the 1st time, it will fail saying the same thing but will build the templated files correctly.
==> Wait completed after 6 milliseconds 165 microseconds
==> Builds finished. The artifacts of successful builds are:
--> file.local_setup_bginfo_templatefile_create: Stored file: /storage/lvm_packerrepo01/packer_cache/temp/floppy/testdeploy01/setup-bginfo.ps1
--> file.local_setup_default_profile_templatefile_create: Stored file: /storage/lvm_packerrepo01/packer_cache/temp/floppy/testdeploy01/setup-default-profile.ps1
--> file.local_unattend_templatefile_create: Stored file: /storage/lvm_packerrepo01/packer_cache/temp/floppy/testdeploy01/Autounattend.xml
  • When you run the build process the 2nd+ times, it works fine as the ‘var.vm_local_setup_default_profile_ps1’ file already exists in the location

Environment :
Packer: v1.7.5
plugin: vsphere v1.0.1
provisioner: powershell

Code snippet:
(built before the VM build process)

# Create setup-default-profile.ps1 from template
source "file" "local_setup_default_profile_templatefile_create" {
  target  = var.vm_local_setup_default_profile_ps1
  content = templatefile(var.local_setup_default_profile_templatefile,
      "autowebrepo_root_url" = var.autowebrepo_root_url
# Build templated files locally
build {
  sources = [

Provision section after VM is built

build {
  sources = ["source.vsphere-iso.ton_default_win2019_vm"]
  ## Provisioners will run once 'Communicator' has established a connection
  ## Restart target system - release default profile
  provisioner "windows-restart" {}
  ## Configure WinOS default profile
  provisioner "powershell" {
    elevated_user = local.vm_winrm_user_copyprofile
    elevated_password = local.vm_winrm_user_copyprofile_creds
    execution_policy = "bypass"
    script = var.vm_local_setup_default_profile_ps1
  ## Restart target system - release default profile
  provisioner "windows-restart" {}
  ## Confirmation target system is back up
  provisioner "windows-shell" {
    inline = ["dir c:\\"]