feat: first-class OpenTofu support in status - #22
Conversation
OpenTofu discovers credentials helpers in the same plugin directory and naming as Terraform, so install already covers it; status however only read $TF_CLI_CONFIG_FILE / ~/.terraformrc. It now inspects the CLI configs of both tools (~/.terraformrc, ~/.tofurc and $XDG_CONFIG_HOME/opentofu/tofurc; $TF_CLI_CONFIG_FILE overrides both) and labels each registration with the tool that reads it. Health is "at least one existing CLI config registers tfvault": an OpenTofu-only machine with just ~/.tofurc now passes, and a stray tofurc without a helper block gets a warning — important because OpenTofu ignores ~/.terraformrc entirely once a tofurc exists. README gains an OpenTofu section documenting all of this.
There was a problem hiding this comment.
Code Review
This pull request adds support for OpenTofu to tfvault by updating the status command to inspect OpenTofu configuration files (.tofurc and the XDG config path) alongside Terraform's .terraformrc. It also updates the documentation and adds corresponding unit tests. Feedback on the changes suggests handling the default fallback to ~/.config/opentofu/tofurc when the XDG_CONFIG_HOME environment variable is unset or empty.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| if x := os.Getenv("XDG_CONFIG_HOME"); x != "" { | ||
| cands = append(cands, rcCandidate{filepath.Join(x, "opentofu", "tofurc"), "opentofu"}) | ||
| } |
There was a problem hiding this comment.
According to the OpenTofu specification, if the XDG_CONFIG_HOME environment variable is not set or is empty, OpenTofu falls back to looking for the configuration file at ~/.config/opentofu/tofurc.
Currently, the code only checks the XDG path if XDG_CONFIG_HOME is explicitly set to a non-empty value. This means that on standard systems where XDG_CONFIG_HOME is not set, tfvault status will fail to inspect the default ~/.config/opentofu/tofurc location.
We should fall back to ~/.config when XDG_CONFIG_HOME is empty.
xdgConfig := os.Getenv("XDG_CONFIG_HOME")
if xdgConfig == "" {
xdgConfig = filepath.Join(home, ".config")
}
cands = append(cands, rcCandidate{filepath.Join(xdgConfig, "opentofu", "tofurc"), "opentofu"})There was a problem hiding this comment.
Checked this against OpenTofu's actual implementation before applying, and the claim doesn't hold: there is no fallback to ~/.config when XDG_CONFIG_HOME is unset. From internal/command/cliconfig/config_unix.go:
if xdgDir := os.Getenv("XDG_CONFIG_HOME"); xdgDir != "" && !cl.pathExists(legacyConfigFile) && !cl.pathExists(newConfigFile) {
// a fresh install should not use terraform naming
return filepath.Join(xdgDir, "opentofu", "tofurc"), nil
}OpenTofu only consults the XDG path when XDG_CONFIG_HOME is explicitly non-empty (and neither ~/.tofurc nor ~/.terraformrc exists). With the variable unset, ~/.config/opentofu/tofurc is never read — so adding the suggested fallback would make status report a file the tool doesn't actually use. The current candidate logic intentionally mirrors the implementation, and cliConfigCandidates' doc comment describes exactly this. Keeping as is.
Summary
OpenTofu discovers credentials helpers in the same
~/.terraform.d/pluginsdirectory under the sameterraform-credentials-<name>naming (verified against OpenTofu source:internal/plugin/discovery/find.go,cmd/tofu/plugins.go), sotfvault installalready works fortofu— butstatusonly read$TF_CLI_CONFIG_FILE/~/.terraformrcand reported OpenTofu-only setups as broken.statusnow inspects the CLI configs of both tools:$TF_CLI_CONFIG_FILEwhen set (honored by both tools — OpenTofu kept theTF_name), as the sole candidate~/.terraformrc(terraform),~/.tofurc(opentofu), and$XDG_CONFIG_HOME/opentofu/tofurc(opentofu, when the env var is set)Each found file gets the existing registration checks, labeled with the tool that reads it. Health semantics: at least one existing CLI config must register tfvault.
~/.tofurc) now reports healthy — previouslystatusfailed on the missing~/.terraformrc~/.tofurcthat exists without acredentials_helperblock gets a warning without failing terraform-side health. This case matters: once a tofurc exists, OpenTofu ignores~/.terraformrcentirely, silently disabling the helper for tofuREADME gains an
## OpenTofusection documenting the shared plugin dir, the tofurc/terraformrc fallback and the both-files caveat.Test plan
TestStatusTofurcOnly: tofu-only machine → healthy, tofurc ok line, profile from tofurc argsTestStatusTofurcNotRegistered: terraform wired + stray tofurc → exit 0 with tofurc warningTF_CLI_CONFIG_FILEsingle-candidate path, zero-config "missing" path)go test ./...,go vet,gofmtcleanSources
OpenTofu behavior verified against source and docs: credentials helpers, config file lookup, TF_CLI_CONFIG_FILE.