Powershell provisioner's "environment_vars" configuration does not work when used with "scripts" configuration
- Dominant language
- Go
- Stars
- 15.8k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
#### Community Note
* Please vote on this issue by adding a 👍 [reaction](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to the original issue to help the community and maintainers prioritize this request
* Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
* If you are interested in working on this issue or have submitted a pull request, please leave a comment
#### Overview of the Issue
When using the powershell provisioner to provision your packer deployment, any environment variables configured in the "environment_vars" config are not made available to the powershell scripts that are configured using the "scripts" config. This only occurs with the "scripts" config. The powershell provisioner works as expected (eg. the configured environment variables are made available to the powershell session) when you use the "script" or "inline" configs.
#### Reproduction Steps
1) In a packer config file, in the build block, define a powershell provisioner block that
- configures a couple of environment variables using the "environment_vars" config
- and runs a couple of powershell scripts that utilize the previously configured environment variables using the "scripts" config
2) Build the deployment using packer build .
### Packer version
packer -version
1.9.2
### Simplified Packer Template
https://gist.github.com/youngturk2/2dc369a5bc799f222e6db895d5b373f0
### Operating system and Environment details
The os installed on the packer deployment is windows server 2019. The build server running the packer build is windows server 2016
### Log Fragments and crash.log files
```
==> oracle-oci.server2019: Machine successfully restarted, moving on
==> oracle-oci.server2019: Provisioning with Powershell...
==> oracle-oci.server2019: Provisioning with powershell script: ../powershell/Invoke-DotNetOptimization.ps1
==> oracle-oci.server2019: Provisioning with powershell script: ../powershell/Install-PSResourceGet.ps1
oracle-oci.server2019: ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it is null.
oracle-oci.server2019: At C:\Windows\Temp\script-64d11a98-7a20-a8fa-6a18-135c2da370[97](https://github.com/vertexinc/vod-oseries-oci-na/actions/runs/5787432178/job/15684360688#step:5:98).ps1:8 char:106
oracle-oci.server2019: + ... ial -ArgumentList "NA", (ConvertTo-SecureString $env:THETOKEN -AsPlai ...
oracle-oci.server2019: + ~~~~~~~~~~~~~
oracle-oci.server2019: + CategoryInfo : InvalidData: (:) [ConvertTo-SecureString], ParameterBindingValidationException
oracle-oci.server2019: + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ConvertToSe
oracle-oci.server2019: cureStringCommand
oracle-oci.server2019:
oracle-oci.server2019: ConvertTo-SecureString : Cannot bind argument to parameter 'String' because it is null.
oracle-oci.server2019: At C:\Windows\Temp\script-64d11a[98](https://github.com/vertexinc/vod-oseries-oci-na/actions/runs/5787432178/job/15684360688#step:5:99)-7a20-a8fa-6a18-135c2da37097.ps1:9 char:37
oracle-oci.server2019: + $vaultpass = ConvertTo-SecureString $env:THEVAULTPASS -AsPlainText -F ...
oracle-oci.server2019: + ~~~~~~~~~~~~~~~~~
oracle-oci.server2019: + CategoryInfo : InvalidData: (:) [ConvertTo-SecureString], ParameterBindingValidationException
oracle-oci.server2019: + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.ConvertToSe
oracle-oci.server2019: cureStringCommand
oracle-oci.server2019:
oracle-oci.server2019: Creating a new Microsoft.PowerShell.SecretStore vault. A password is required by the current store configuration.
oracle-oci.server2019: Enter password:
Cancelling build after receiving interrupt
==> oracle-oci.server2019: Terminating instance (ocid1.instance.oc1.iad.anuwcljsf256y7ic3xwr2alpia3jqb5wew4hibzpdrloes4jmnnjiw3bzdmq)...
Error: The operation was canceled.
```
Contributor guide
Assessment
This issue has not been assessed yet.