Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

terraform apply fails Windows during packaging #29

Closed
marcinbelczewski opened this issue Jun 16, 2020 · 7 comments · Fixed by #32
Closed

terraform apply fails Windows during packaging #29

marcinbelczewski opened this issue Jun 16, 2020 · 7 comments · Fixed by #32

Comments

@marcinbelczewski
Copy link

Hi

I'm running Windows 10 with Python 3.8.3 installed via chocolatey (not the Microsoft Store version).
Terraform v0.12.26

  • provider.aws v2.66.0
  • provider.external v1.2.0
  • provider.local v1.4.0
  • provider.null v2.1.2
  • provider.random v2.2.1

I did the following

git clone https://github.com/terraform-aws-modules/terraform-aws-lambda.git
cd .\terraform-aws-lambda\examples\simple\
terraform init
terraform apply

I got

Error: Error running command 'builds\779e75909859de952ef41b10cdbe2d86e96194037c9f626abe157a44728198c0.plan.json': exit status 1. Output: zip: creating 'builds\779e75909859de952ef41b10cdbe2d86e96194037c9f626abe157a44728198c0.zip' archive
zip: adding: index.py
Traceback (most recent call last):
  File "../../package.py", line 1157, in <module>
    main()
  File "../../package.py", line 1153, in main
    exit(args.command(args))
  File "../../package.py", line 1045, in build_command
    bpm.execute(build_plan, zs, query)
  File "../../package.py", line 303, in __exit__
    self.close()
  File "../../package.py", line 292, in close
    os.replace(self._tmp_filename, self.filename)
PermissionError: [WinError 32] The process cannot access the file because it is being used by another process: 'builds\\779e75909859de952ef41b10cdbe2d86e96194037c9f626abe157a44728198c0.zip.tmp' -> 'builds\\779e75909859de952ef41b10cdbe2d86e96194037c9f626abe157a44728198c0.zip'

I'm not fluent in Python by any means but I suspect this is due the zip file not being closed before trying to change it's name from tmp to the final one.
After changing the package.py so that ZipWriteStream.close looks like this:

    def close(self, failed=False):
        self._zip.close()
        self._zip = None
        if failed:
            os.unlink(self._tmp_filename)
        else:
            os.replace(self._tmp_filename, self.filename)

all worked fine.

Also being on Windows, I had to jump through one small hoop to get the module working, as the only python executable installed is python.exe and the module requires:

  • python3 - which on Windows could mean python3.exe
  • for runtime=python3.8 the module requires actual executable with that name - which on Windows could mean python3.8.exe

I've fixed that with hard links so no biggie.

Big thanks for the awesome work on the module!

@antonbabenko
Copy link
Member

oh, Windows... so lovely...

Well, let me see what we can do about this, but I don't want to promise anything yet, because none of us (people developing this module and https://serverless.tf) use Windows, so it may be time-consuming for us to investigate&fix.

I will keep you posted here during the next couple days.

@marcinbelczewski
Copy link
Author

Thank you for your response Anton.
Would you say working on Linux is a safer path? I can't work on MacOS at work but I potentially could work on "Windows Subsystem for Linux" (WSL). And soon enough I should be able to work on WSL 2 which should improve things event more.

@antonbabenko
Copy link
Member

Windows, WSL, WSL2 - are all viable options many people use (or can use).

I am just saying that most often we work or interact with Linux/Mac and not so much with Windows.

I believe you can do the same on Windows, too. We just need to get this one issue fixed first.

@marcinbelczewski
Copy link
Author

Understood - thanks!

@antonbabenko
Copy link
Member

@marcinbelczewski Please give a try to v1.14.0 where this issue has been just fixed.

And thanks again for reporting!

@marcinbelczewski
Copy link
Author

@antonbabenko I just verified and it works flawlessly. Big thanks!

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants