hashicorp / hashicorp/packer-plugin-googlecompute

Packer returns Powershell Error After Provisioners are complete

Open
#108 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Go
Stars
33
Forks
72
Avg merge
6h 47m
Merged PRs (30d)
3

Description

#### 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**

```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**

```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](https://user-images.githubusercontent.com/3172378/183433605-29674973-17c8-4162-8ef3-f086cfb3e589.png)

### 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.