toowoxx / terraform-provider-packer

Terraform Provider for HashiCorp Packer
Mozilla Public License 2.0
32 stars 7 forks source link

windows - access denied error without admin access on packer provisioners #9

Closed domoran closed 2 years ago

domoran commented 2 years ago

Short Description:

when using provisioners under packer and executing the build via terraform, it seems packer uses as a current directory the Windows directory. This leads to an access denied error, when terraform is not invoked with admin access.

My Environment:

Steps to reproduce:

Expected behaviour:

both builds succeed, terraform plugin will pass the current work directory to the invoked packer process.

Observed behaviour:

Provisioner fails with error message:

Build 'docker.example' errored after 16 seconds 355 milliseconds: Error preparing shell script: open C:\Windows\packer-shell2326743061: Zugriff verweigert

which shows that the provisioner tries to place the script command file in the C:\Windows directory which needs elevated rights to write to.

I attached the relevant files to the issue.

main.tf bug.pkr.hcl log.txt

domoran commented 2 years ago

Note: Using the "directory" parameter on the terraform resource to explicitly set the working directory does not help. Using process explorer it seems that the "tmp" environment variable was missing on the packer environment, making the provisioner place temp files inside the SYSTEMROOT directory (C:\Windows). Passing a "TMP=..." variable on the environment works around the problem. So maybe tmp and path should be passed by default inside the environment of the packer build.

simaotwx commented 2 years ago

Thank you for your report. This seems to be related to https://github.com/toowoxx/terraform-provider-packer/issues/8

Please try the keep_environment attribute. If you set it to true, all env variables should get passed through.

simaotwx commented 2 years ago

Fixing #8 fixes #9