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

Question: how to get root module absolute path #218

Closed
Vince-Chenal opened this issue Nov 14, 2022 · 4 comments · Fixed by #224
Closed

Question: how to get root module absolute path #218

Vince-Chenal opened this issue Nov 14, 2022 · 4 comments · Fixed by #224

Comments

@Vince-Chenal
Copy link

Vince-Chenal commented Nov 14, 2022

Hey,

In order to enforce terraform folders location (for example .infra at the root of git repo), I'd like to be able to get the root module absolute path. I can't find another solution than getting the current workdir (which can be wrong if tflint is executed from another directory).
There's the GetFiles() function but it only give the filenames.

Is there another way?

@wata727
Copy link
Member

wata727 commented Nov 17, 2022

Unfortunately there doesn't seem to be a good way to do it.
Getting the current directory is probably the best way. The filename retrieved by GetFiles() is the relative path of the current directory, so you may be able to use it. However, this is not the spec and is subject to change in the near future, so I wouldn't recommend it unless absolutely necessary.

I'm not sure how it should be, but I have some ideas in mind:

  • Makes the filename retrieved by GetFiles() an absolute path.
    • It eliminates ambiguity due to dependencies on the current directory. It is also good for the recursive inspection planned in the future.
  • GetModulePath() not only returns the path of the module tree, but also the absolute path on filesystem.

@Vince-Chenal
Copy link
Author

Thanks for your answer
Ok I guess I'll go with current directory for now and follow sdk evolution 👍

@wata727
Copy link
Member

wata727 commented Dec 26, 2022

SDK v0.15 introduces runner.GetOriginalwd(). Better to use this than os.Getwd().

@Vince-Chenal
Copy link
Author

Oh nice did not see this one, thank you 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants