Terraform v0.12.4
Just need an empty file named, for example, test
.
https://gist.github.com/javaJake/88dc0939ccba72a4a091736cb1190fdc
There should be an error with a little more usage information sprinkled in, such as:
zip: not a valid zip file
There was an error reading the plan file "test". Plan files are created by running "terraform plan".
I got just the cryptic error:
zip: not a valid zip file
echo > test
terraform apply test
I forgot to include a little background:
I got to this point of confusion because I followed the automation documentation and skipped the "plan" step as recommended because the .tf file is autogenerated in my setup. I misread the command in the documentation as merely an example and included far more arguments than I should have, such as the .tf file.
Hi,
I have the same issue when I run terraform from the command window of Microsoft Visual Code.
Visual code is running on Centos 7.6. Visual Code - Insiders 1.38 version.
However when I run the command from a bash shell outside of VS Code, I get no error.
Any thughts?
Johnson
All,
BTW - if I run the tsch shell in VS code the issue goes away. Just another thought ;-)
Johnson
Hello, I'm currently having this error, please how can it be fixed
You are getting the error because "terraform apply" only works with files made by "terraform plan".
I was also getting the same error zip: not a valid zip file
This is specifically because of mistakenly providing the tf filename in your command.
E.g.
$ terraform plan terra.tf
zip: not a valid zip file
So remove the tf filename from the command and check. Terraform command automatically detect the files with .tf extention, you don't have to explicitly mention that.
$ terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
Seems like your plugins have become broken.
Try this first:
$ terraform init
I was also getting the same error zip: not a valid zip file
This is specifically because of mistakenly providing the tf filename in your command.
E.g.
$ terraform plan terra.tf
zip: not a valid zip file
So remove the tf filename from the command and check. Terraform command automatically detect the files with .tf extention, you don't have to explicitly mention that.
$ terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.
You need to move your individual tf files to their own directories, and then you can point terraform to that directory. The plan
command only accepts directories, and the apply
command will only take the entire dir, or plan output file (use -out
on plan
). I think this limitation is due to the fact that terraform requires a state file for each plan. Here is how I've setup my terraform project, note secrets.tfvars
and terraform.tfvars
are common between both terraform plans.
$ tree
.
โโโ 1-base
โย ย โโโ provider.tf
โย ย โโโ backend.tf
โย ย โโโ core.tf
โโโ 2-k8s
โย ย โโโ 1-k8s.tf
โย ย โโโ 2-helm.tf
โย ย โโโ apps
โย ย โโโ provider.tf
โย ย โโโ backend.tf
โย ย โโโ chart-builds
โย ย โโโ charts
โโโ secrets.tfvars
โโโ terraform.tfvars
โโโ todo.md
From here I can run:
$ terraform init -var-file=secrets.tfvars ./1-base
$ terraform plan -var-file=secrets.tfvars ./1-base
or
$ terraform apply -var-file=secrets.tfvars ./1-base
I can obviously repeat this process on 2-k8s dir.
I was getting the error
"zip: not a valid zip file" when running the plan
terraform plan -var-file=....environmentlab21a.tfvars
Adding the quotes around the file fixed it.
terraform plan -var-file="....environmentlab21a.tfvars"
I had the same error on this command :
terraform plan -var-file= "./variables/integration.tfvars"
zip: not a valid zip file
For me it is the white space after the "=" sign that causes this error. After removing this white space I have this command terraform plan -var-file="./variables/integration.tfvars"
that runs well
I got "zip: not a valid zip file" for using '
instead of of "
around my -var
argument (i.e. -var='<value>'
). Thanks everyone for hints as to why.
I had the same error on this command :
terraform plan -var-file= "./variables/integration.tfvars"
zip: not a valid zip file
For me it is the white space after the "=" sign that causes this error. After removing this white space I have this command
terraform plan -var-file="./variables/integration.tfvars"
that runs well
Thank you so much for the hint. After spending so many hours I also actually able to resolve by removing white spaces around "="
Most helpful comment
I was also getting the same error zip: not a valid zip file
This is specifically because of mistakenly providing the tf filename in your command.
E.g.
$ terraform plan terra.tf
zip: not a valid zip file
So remove the tf filename from the command and check. Terraform command automatically detect the files with .tf extention, you don't have to explicitly mention that.
$ terraform plan
Refreshing Terraform state in-memory prior to plan...
The refreshed state will be used to calculate this plan, but will not be
persisted to local or remote state storage.