$ terraform -v
Terraform v0.9.11
Link to gist: https://gist.github.com/jonaf/1878f34bcb6f35a55539d61288ce922b
When I encountered #1497 , I thought it might be related, so I tried changing this line of my configuration:
aliases = ["${split("\n", "${trimspace(file("${path.module}/../data/distributions/hostname_${count.index}.txt"))}")}"]
to this:
aliases = "${split("\n", "${trimspace(file("${path.module}/../data/distributions/hostname_${count.index}.txt"))}")}"
Both of these produce the same plan, but neither of them actually works. Somehow, validate and apply consider the resulting plan to be unparseable.
$ TF_LOG=TRACE terraform validate terraform
2017/07/28 14:04:04 [INFO] Terraform version: 0.9.11
2017/07/28 14:04:04 [INFO] Go runtime version: go1.8.3
2017/07/28 14:04:04 [INFO] CLI args: []string{"/usr/local/Cellar/terraform/0.9.11/bin/terraform", "validate", "terraform"}
2017/07/28 14:04:04 [DEBUG] Detected home directory from env var: /Users/jona.fenocchi
2017/07/28 14:04:04 [DEBUG] Detected home directory from env var: /Users/jona.fenocchi
2017/07/28 14:04:04 [DEBUG] Attempting to open CLI config file: /Users/jona.fenocchi/.terraformrc
2017/07/28 14:04:04 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2017/07/28 14:04:04 [DEBUG] Detected home directory from env var: /Users/jona.fenocchi
2017/07/28 14:04:04 [INFO] CLI command args: []string{"validate", "terraform"}
2017/07/28 14:04:04 [DEBUG] plugin: waiting for all plugin processes to complete...
Error loading files Error parsing ./terraform/plan.tf: At 1:7: illegal char
None
terraform validate should have come said that the terraform configurations were OK. It does do this before terraform plan is invoked.
terraform validate fails with this error after a terraform plan is produced:
Error loading files Error parsing ./terraform/plan.tf: At 1:7: illegal char
However, terraform show ./terraform/plan.tf is able to parse the plan correctly:
terraform plan -out=terraform/plan.tfterraform validate terraform/ (terraform apply will yield the same error)terraform show terraform/plan.tf (works just fine!)I was unable to find any open or closed GitHub issues with this error message or similar steps to reproduce. #1497 was the closest thing I found.
Hi @jonaf! Sorry for this confusing behavior.
I think what's actually going on here is that you named the plan with a .tf extension and thus Terraform is trying to treat it as a configuration file. The "illegal char" error here is coming from the configuration parser, not the plan parser. I think if you choose a different name for your plan file this problem will go away.
Oh, interesting. I wonder, what extension should a plan file have? Maybe Terraform shouldn't have such a sharp edge for this (admittedly dense) user error. :)
Yep, that was it! I changed the file to plan.tfplan and everything is working fine now. Thanks, @apparentlymart !
Hi @jonaf,
Since there's generally only _one_ plan around at a time, I generally just call it tfplan with no extension.
In the forthcoming 0.10.0 release we're introducing (behind an opt-in flag, for the moment) a new workflow that avoids the need to create the temporary plan file when using Terraform interactively in a terminal. This is intended to make this common case smoother:
$ terraform apply -auto-approve=false
The above command prints out the plan, stops to wait for you to type yes in confirmation, and then applies the plan, without the need to ever write the plan file to disk. We're planning to make this the default workflow in a future version, at which point terraform plan -out=tfplan will be used only when running Terraform in some sort of orchestration tool (e.g. a CI system, or Terraform Enterprise) where the plan needs to be stashed somewhere to make it available to a later terraform apply process.
If you're able to use Terraform in an experimental way, you may wish to give the latest release candidate a try to preview the above behavior. The final 0.10.0 release is coming very soon, so it won't be long before this new functionality is available in a stable release.
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.
Most helpful comment
Hi @jonaf! Sorry for this confusing behavior.
I think what's actually going on here is that you named the plan with a
.tfextension and thus Terraform is trying to treat it as a configuration file. The "illegal char" error here is coming from the configuration parser, not the plan parser. I think if you choose a different name for your plan file this problem will go away.