Closed apparentlymart closed 5 years ago
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.
If the header of a resource declaration block contains a syntax error, the HCL parser attempts recovery in order to parse the rest of the file and find any other potential errors. The result in this case is an incomplete parse tree and some diagnostic messages.
Terraform is currently then still attempting to decode such incomplete blocks during its later validation pass, again attempting to collect as many errors as possible at once before returning.
Unfortunately, Terraform is not being defensive enough about the possibility of an incomplete data structure, leading to a crash.
For example:
This leads to a panic during config loading:
We addressed a previous error of this type by paired fixes in both HCL and Terraform: HCL ought to produce a valid but incomplete block in this case, rather than an invalid one (with a nil body), which then allows callers to do careful partial analysis without tripping over this nil. However, some additional care within Terraform itself may also be warranted here. We'll use this issue to track the Terraform-facing problem, though the bulk of the fix here will probably be over in the HCL2 repository.
(The above stack trace came from Terraform v0.12.0-alpha2.)