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

Support folder-level -var-file setting #1478

Open
anilkumarmyla opened this issue Jun 11, 2023 · 2 comments
Open

Support folder-level -var-file setting #1478

anilkumarmyla opened this issue Jun 11, 2023 · 2 comments
Labels
enhancement New feature or request

Comments

@anilkumarmyla
Copy link
Contributor

Versions

Extension

v2.26.1

Problem Statement

We have an unorthodox file structure for terraform project as follows

├── backend.tf
├── main.tf
├── tfvars
│   ├── dev.tfvars
│   ├── prod.tfvars
│   └── stage.tfvars
├── variables.tf
└── versions.tf

where we store tfvars for different environments in a subfolder and pass them to terraform plan as -var-file tfvars/{env}.tfvars.

This workflow works fair but with vscode references to variables don't show anything from tfvars/{env}.tfvars since the extension expects tfvars to be in the same folder. If we move the tfvars files up one level where the root module is, vscode does indeed show the references in {env}.tfvars files. But moving these files one level above clutters the project with too many files and distinction between config and code is lost.

Expected User Experience

Reference to tfvars file in a subfolder should be resolved and shown

Proposal

Don't have enough knowledge on the internals to propose something

References

#636 has resolved tfvars support but that only works if tfvars files are in root module folder

@anilkumarmyla anilkumarmyla added the enhancement New feature or request label Jun 11, 2023
@radeksimko
Copy link
Member

radeksimko commented Jun 12, 2023

Hi @anilkumarmyla
I wouldn't say the directory structure is unorthodox. That said, it does make it more difficult for the IDE/LS to understand the relationship, as technically every folder/level is a different module.

I'm afraid that there isn't any good way of making this work "out of the box" the way you suggest where "go-to-reference/definition" brings up the relationship between your tfvars/*.tfvars and variables in *.tf as that would mean that all *.tfvars files anywhere in the workspace hierarchy are potentially candidates for any variable anywhere. For workspaces with deep hierarchies this would likely result in a confusing UX with lots of false positives.


I'm curious if having some settings and/or environment variables to give the extension/LS hints would be a good compromise?

I'm wondering how do your team members know how exactly to execute plan or apply, i.e. what exact -var-file to pass and when? Do you have this codified anywhere?

@anilkumarmyla
Copy link
Contributor Author

@radeksimko Thanks for the quick response

I'm curious if having some settings and/or environment variables to give the extension/LS hints would be a good compromise?

Yes, this would be a good comprose like say scan this subdirectory for this root-module for additional files, something along the lines of terraform.languageServer.rootModules (which I tried and got deprecated warning)

I'm wondering how do your team members know how exactly to execute plan or apply, i.e. what exact -var-file to pass and when? Do you have this codified anywhere?

Our automation takes care of substituting the right var-file for supported environments, most team members only work on the dev environment where they have sufficient privileges, rest of them are handled by automation

@radeksimko radeksimko changed the title Reference to tfvars file in a subfolder Support folder-level -var-file setting Jun 12, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants