hashicorp / packer-plugin-googlecompute

Packer plugin for Google Compute Builder
https://www.packer.io/docs/builders/googlecompute
Mozilla Public License 2.0
25 stars 54 forks source link

Packer returns Powershell Error After Provisioners are complete #108

Open lmayorga1980 opened 2 years ago

lmayorga1980 commented 2 years ago

Overview of the Issue

I am creating a Windows GCP Image and after invoking the GCP Sysprep

    provisioner "powershell"{
            inline = ["GCESysprep -NoShutdown"]
        }

it returns a weird Powershell error

==> googlecompute.vm: . : The term
==> googlecompute.vm: 'c:/Windows/Temp/packer-ps-env-vars-62f10fbc-5827-c4b2-8272-3b1793e96a67.ps1'
==> googlecompute.vm: is not recognized as the name of a cmdlet, function, script file, or operable
==> googlecompute.vm: program. Check the spelling of the name, or if a path was included, verify
==> googlecompute.vm: that the path is correct and try again.
==> googlecompute.vm: At line:1 char:138
==> googlecompute.vm: + ... lyContinue'};.
==> googlecompute.vm: c:/Windows/Temp/packer-ps-env-vars-62f10fbc-5827-c4b2-8272-3b1793 ...
==> googlecompute.vm: +
==> googlecompute.vm: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
==> googlecompute.vm:     + CategoryInfo          : ObjectNotFound: (c:/Windows/Temp...b1793e96a67.p
==> googlecompute.vm:    s1:String) [], CommandNotFoundException
==> googlecompute.vm:     + FullyQualifiedErrorId : CommandNotFoundException

NOTE The image gets built and it works but I would like to get rid of that error

Reproduction Steps

gcp.pkr.hcl

source "googlecompute" "vm" {

  ...
  metadata = {
    windows-startup-script-cmd = local.script_cmd
    windows-shutdown-script-ps1 = "C:/cleanup-packer.ps1"
  }

  account_file = var.account_file_path
}

gcp.build.pkr.hcl

build {
  sources = ["source.googlecompute.vm"]
  provisioner "file" {
            source = "./scripts/cleanup-packer.ps1"
            destination = "C:/cleanup-packer.ps1"
    }

    provisioner "powershell"{
            inline = ["GCESysprep -NoShutdown"]
        }

}

Screen Shot 2022-08-08 at 9 48 37 AM

Plugin and Packer version

packer 1.8.3

The error happened after provisioner GCPSysPrep -NoShutdown command is executed but there are not more scripts to be called.

lmayorga1980 commented 2 years ago

The following fixed my issue but might be related to packer instead of this plugin

  provisioner "powershell" {
    inline = ["GCESysprep -NoShutdown"]
    skip_clean = true
  }