Vscode-terraform: "templatefile" function parsed paths incorrectly

Created on 15 Oct 2019  ยท  8Comments  ยท  Source: hashicorp/vscode-terraform

This bit of code in a Terraform file:

templatefile("${path.module}/files/launch-template-user-data.tpl", {

...is parsed incorrectly, and claims the file doesn't exist on disk:

Call to function "templatefile" failed: no file exists at /files/launch-template-user-data.tpl.

The file actually does exist, and the Terraform template finds the file and applies correctly.

Most helpful comment

I'm seeing similar behavior with the file() statement:
file("${path.root}/testfile.xml") returns

This object does not have an attribute named "root".

file("testfile.xml") returns

Call to function "file" failed: no file exists at testfile.xml.

If I hardcode the full path, it works.

vscode: 1.39.2
mauve.terraform: 1.4.0

All 8 comments

I confirm the same experience

| sofware | version |
| :---: | :---: |
| vscode | 1.39.1 |
| mauve.terraform | 1.4.0 |

I'm seeing similar behavior with the file() statement:
file("${path.root}/testfile.xml") returns

This object does not have an attribute named "root".

file("testfile.xml") returns

Call to function "file" failed: no file exists at testfile.xml.

If I hardcode the full path, it works.

vscode: 1.39.2
mauve.terraform: 1.4.0

Same issue as @voodevil , file is not parsing relative file paths correctly. If I make the file path relative to the root of the workspace it's fine but if it's relative to the file itself it fails. We only run terraform from the folder that contains the file, not the workspace root, so in our use case it should not give an error.

I can confirm the same issue

template = "${file("${path.module}/tasks/task_definition.json")}"

we don't run from the workspace root either and rely on ${path.module}

I can confirm the same as well

content = file("${path.module}/configs/ch2-asw-01.conf")

Throws the same error

Is there a way to disable the warning?

We just released v2.0.0-rc.1 of the extension. The main features include:

  • Added syntax support for 0.12
  • Added terraform-ls usage by default (currently on 0.3.0, which offers basic provider code completion)

You can find additional information and specifics in the release notes and CHANGELOG.

With this release we expect that many of the prior issues and PRs are no longer relevant or have been addressed, and are therefore being closed. If you feel the action taken on an issue or PR is in error, please comment as such and we can figure out the appropriate way to address it.

We plan to add the final 2.0.0 release to the marketplace soon, but are actively seeking your feedback now on the release candidates. You can download the .vsix from the releases page and manually install it in VS Code to try it out.

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 context necessary to investigate further.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

visokoo picture visokoo  ยท  3Comments

LogicNinja picture LogicNinja  ยท  3Comments

renanaraujo picture renanaraujo  ยท  5Comments

brodster2 picture brodster2  ยท  5Comments

NeckBeardPrince picture NeckBeardPrince  ยท  4Comments