-
Notifications
You must be signed in to change notification settings - Fork 9.6k
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
Use xdg basedir spec on linux #15389
Comments
Thanks for pointing this out, @jleclanche. This seems like a reasonable idea as long as we can find a way to get there without breaking things for people already using the current paths, though should think about whether it makes sense to adopt this just for Linux (and thus have to document another platform-specific difference) or across all UNIX-flavored platforms (where it might seem more alien). I'd like to let this one soak for a little while before we take any action. Thanks again for pointing it out! |
👍 |
Ah sorry, i see in |
Yeah, indeed... seems worth thinking about splitting the cache-ish things from the settings-ish things too, like you said. |
Is there an environment variable to customize the location of this directory? I switch between OSX and Linux and I like to use environment variables to keep the location of config files consistent. |
@apparentlymart I see you've been working on the config lately, any chance this is going in too? |
Hi again @jleclanche! Sorry for leaving this here so long. We've been adding some more stuff into this dir in the mean time, such as more config files ( I do like the idea of following the relevant standards and of distinguishing config from cache, but I want to go into it with a stronger idea of how this changes all of our supported platforms, rather than just changing it for Linux, or indeed forcing Linux-specific conventions on other platforms. I think to properly support this we need to alter our model to separately account for a config and cache dir on each platform, and then use the appropriate directory for each case. AFAICT on Mac OS X the appropriate directories are:
To get the migration path we need, and also to meet @jcrben's reasonable request at being able to use common directories across both OS X and Linux, I think we'd need to continue looking for config-ish things in AFAICT the BSDs also don't really use XDG and so continuing to use I wasn't able to get a read on whether Solaris users expect XDG support. While we're doing this, we should also check if there's a config vs. cache dir distinction to be made for Windows systems as well. We currently use the same prefix for both on Windows. I can't promise working on this soon since there are many other things competing for attention, but if we can get some consensus on what the most natural thing is on each platform then at least when someone has some time to look at this we'll have a reasonably-clear path forward. |
If you want to look at how to implement it cross-platform, I recommend looking at the QStandardPaths implementation from Qt: https://doc.qt.io/qt-5/qstandardpaths.html This follows XDG standards on Linux and other platform-specific quirks for macOS and Windows. |
Awesome... thanks for that pointer, @jleclanche! |
In the case of a fair number of my tools, such as git, if I define the XDG variables, they are used on OSX as well. See https://git-scm.com/docs/git-config#git-config---global A simpler place to start is to just let me place the entire directory into a different place. |
As a Mac user, I am against The actual change does not appear difficult, relative to the docs and migration. I might try submitting a PR for this once I'm more proficient at Go. `rg 'terraform\.d' terraform/ -c` on 69c647cterraform/plugins.go:1 terraform/config_windows.go:1 terraform/CHANGELOG.md:1 terraform/config_unix.go:1 terraform/command/command.go:1 terraform/website/upgrade-guides/0-7.html.markdown:1 terraform/website/guides/running-terraform-in-automation.html.md:1 terraform/website/docs/plugins/basics.html.md:2 terraform/website/docs/configuration/providers.html.md:4 terraform/website/docs/commands/cli-config.html.markdown:1 terraform/website/docs/commands/init.html.markdown:2 `rg 'terraform\.d' terraform/` on 69c647cterraform/plugins.go 18: // Look in ~/.terraform.d/plugins/ , or its equivalent on non-UNIX |
Hi all, We're intentionally not making any changes related to this right now because we're trying to wrap up development of the v0.12.0 release, which already has a large scope and so we'd prefer not to make changes to how Terraform interacts with the host system at the same time. However, I'd love to dive into this some more after that and see what makes sense here. Given that there are a few different options, I think the best way to proceed here is to come to some consensus on what behavior is desirable first and only then move forward to implementation. I am open to using XDG on OS X if that is emerging as a de-facto standard in other tools, but I'd like to go into that with a fully-detailed idea of exactly what paths that will end up using on each of the different platforms Terraform supports, including figuring out what makes sense for all of the non-Linux and non-MacOS unix flavors, and seeing also if any changes are warranted on Windows at the same time so that we can make all necessary changes of this kind in a single release. In the mean time it'd be helpful to collect here links to existing precedent for how other software is handling these concerns across platforms, since I think consistency with common behavior will be the primary deciding factor in what path we take here. |
Check this out: https://wiki.archlinux.org/index.php/XDG_Base_Directory This is a list of Software Conforming to the XDG Base Directory Standard. If the Source was avail at the time in a git/svn repo, the pr/merge/commit is linked there. Ex: https://cgit.freedesktop.org/libreoffice/ure/commit/?id=a6f56f7 Those have OSX Examples https://src.chromium.org/viewvc/chrome/trunk/src/chrome/common/chrome_paths.cc?r1=23057&r2=23056&pathrev=23057 https://gitlab.gnome.org/GNOME/gimp/commit/60e0cfe I think that is the best approach here. |
In reference to macOS. Since the ~/Library is by default hidden on Mac, the XDG should be used by command line applications leaving the ~/Library to native macOS applications . |
I've got plenty of programs that are as native as terraform that output to
etc. It doesn't really make sense to use the XDG standards for MacOS when MacOS already has it's own. this Go XDG library accounts for Mac & Windows: OpenPeeDeeP/xdg |
Three of those are gui apps or have a GUI over a cmdline executable. I guess i am out of touch with the macOS community. |
I honestly find the basedirs more useful because of the reduced cognitive
load when performing backup and/or synchronization. Instead of
cherry-picking from `~/Library`, we just have the XDG directories.
|
So instead of applications on MacOS conforming to the OS's official standards they should move to match XDG?... The only reason for cognitive load is because of people not following the OS's standards. If all Linux programs followed XDG, Windows programs go to There is more cognitive load due to the mishmash caused by ignoring the OS's standards and having them go in various different locations on one OS The standard config for terraform should match the OS's standards, then env variables should just allow you to put the config in whatever non-standard location you like. |
Look in your ~/Library/Preferences I looked at mine. Nearly only macOS GUI apps. Where are the rest? dotfiles in ~/ or a few, that I think are well behaved, in ~/.config. among those in ~/ items provided by Apple as it ships. I return to where I started, macOS native apps in the ~/Library and command line executables following XDG. |
Well I listed both non native apps & some cli apps that follow that spec. Additionally my ZSH setup has I'm going to start working on this to strictly respect XDG. Maybe later we can have a further chat about Mac standard dirs but even then |
In the PR I've explained the flow of priorities/preference. Please see the flows & the note in the first section and give me your thoughts. |
As per the spec, the alternate directories should be I am strongly against |
Where did I miss the dot in zsh keeps the dot in The only issue with the env var taking highest priority is if people already have config at |
macOS's difference comes up every time in issues about adhering to XDG... essentially I think there's two camps:
The really easy resolution is simply to respect (resp. |
I've changed the code to only keep the |
Is there any known workaround for this? It's very annoying to have |
I would be great if you fixed this in nearest update |
@apparentlymart What is the latest thought on this? Now that 1.0 is out it should really be evaluated. |
Also interested in the latest movement on this, or a workaround until its correctly supported. |
Can we actually get this fixed on Linux while we continue to discuss the other platforms? The decision and solution seems really cut and dry when it comes to Linux. |
More recently we implemented a new directory structure for locally-mirrored provider plugins as part of introducing registry hostnames and namespaces to the provider addresses, and since we were effectively building on greenfield there we did adopt the XDG conventions on "Linux and other Unix-like systems" (as the documentation currently describes it), along with some paths on macOS and Windows that matched what we learned from researching those platforms' typical conventions. That does at least mean that we now have some plumbing in place for implementing this sort of thing, via a "third-party" library (where the third party happens to be me wearing a different hat). However, I believe there are some remaining design decisions for us to decide and so far we've not been able to prioritize this largely because there is already a solution for specifying CLI configuration files via the environment (the From my memory (which is likely incomplete, since I'm just replying here off the top of my head), the two main decisions I remember us planning to research more here were:
With all of that said then, I would not expect to see Terraform start searching new directories on any platform in the immediate future, so that we can be sure to definitively answer these remaining questions (which requires research and design tradeoffs) before doing so. In the mean time, if you need to place the Terraform CLI configuration at a different location than Terraform will search by default, the |
[emphasis added] edit: Oh! Sorry, I forgot about |
Which is really nice and I appreciate the work.
I have a vested interest in not having dotfiles in the home directory because it messes with my backup plans (among other problems). However, I do understand that this issue might not sit high up in the priority list for hashicorp devs. But I appreciate you being open to looking into this and having this discussion continuing. |
In my earlier research I observed that some Linux distribution packages make use of the system-wide (rather than user-specific) directories to install system-level configuration files which the user-specific directories (including the "config home") can add to or override. I no longer have my notes about exactly which application packages they were, but I considered being a good citizen in Linux distributions to be one of the benefits of following the de-facto platform spec, and thus fully supporting This may also prove useful for any organization building their own local system-level packages with Terraform providers and special configurations as part of a systematic configuration management strategy, though I don't have any specific data about that. |
Both |
Go has a standardized way to get this information: |
Sorry, if i'm wrong, but read whole thread and still don't get: diff --git a/internal/command/cliconfig/config_unix.go b/internal/command/cliconfig/config_unix.go
index 6dc1450b23..a0187c225e 100644
--- a/internal/command/cliconfig/config_unix.go
+++ b/internal/command/cliconfig/config_unix.go
@@ -20,6 +20,9 @@ func configFile() (string, error) {
}
func configDir() (string, error) {
+ if home := os.Getenv("TF_HOME_DIR"); home != "" {
+ return home, nil
+ }
dir, err := homeDir()
if err != nil {
return "", err Looks like it would solve people's pain, which is keeping $HOME clean from any dotfiles/dotdirs as possible, in the easiest way. So, is any progress here anyway? |
you can try submit a PR, I'll take anything that gets it out of ~ |
@apparentlymart, please, could you recap what should (those) MacOS' users (who are also fans of XDG) should do to keep the home clean of the Would the following workaround do trick? cf. Terraform Docs export TF_CLI_CONFIG_FILE=$XDG_CONFIG_HOME/terraform/terraform.rc
cat <<EOF > "$XDG_CONFIG_HOME/terraform/terraform.rc"
plugin_cache_dir = "$XDG_CACHE_HOME/terraform/plugin-cache"
disable_checkpoint = true
EOF Can we safely remove |
Terraform Version
0.9.8
https://specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html
TLDR: Instead of ~/.terraform.d, configuration should be in the
$XDG_CONFIG_HOME/terraform/
and cache (safely-deletable files) should be in$XDG_CACHE_HOME/terraform
. If not defined,$XDG_CONFIG_HOME
should be defaulted to$HOME/.config
and$XDG_CACHE_HOME
should be defaulted to$HOME/.cache
.I believe everything currently in .terraform.d is considered cache, therefore there's just $XDG_CACHE_HOME to worry about.
This is pretty standard and helps keep clutter out of the homedir :)
The text was updated successfully, but these errors were encountered: