Make TF_IGNORE case insensitive
Current Terraform Version
Terraform v0.13.5
Use-cases
I was trying to debug a .terraformignore file by setting an ENV variable TF_IGNORE=TRACE, but it turned out only a lower case "trace" was accepted. No indication of using an unaccepted debug level was provided.
Attempted Solutions
Using a lower case "trace" (as stated in the documentation) works.
Proposal
Can we have Terraform accept any case for the TF_IGNORE variable and potentially also inform the user if an invalid debug level has been used ?
This will be consistent with the TF_LOG experience, namely:
[WARN] Invalid log level: "nothing". Defaulting to level: TRACE. Valid levels are: [TRACE DEBUG INFO WARN ERROR]
References
The "offending" code resides here in the go-slug package: https://github.com/hashicorp/go-slug/blob/dbc66eb36565a91ad0e3dd9ddec5e9446da6754c/terraformignore.go#L212-L213
func debug(printAll bool, path string, message ...interface{}) {
logLevel := os.Getenv("TF_IGNORE") == "trace"
It should be trivial to add code like the one from TF_LOG: https://github.com/hashicorp/terraform/blob/44aeaa59e70f416d582ed3ceccad7f7945f03688/helper/logging/logging.go#L81-L84
if isValidLogLevel(envLevel) {
// allow following for better ux: info, Info or INFO
logLevel = strings.ToUpper(envLevel)
}
What is stopping me from creating the PRs is that currently TF seems to use go-slug v0.4.1 and the current version is v0.4.3. There has been some changes around symlink handling and it would be a pity if I break Terraform while trying to fix a trivial thing like the case sensitivity of TF_IGNORE :)
https://github.com/hashicorp/terraform/blob/111825da4522bef503e05deb55a9e142c1aa9a5a/go.sum#L326
As a stopgap I will raise a PR to the documentation to explicitly state that, currently, only lowercase "trace" is supported and hopefully that might save someone some time.
Thanks for raising this @qwerty1979bg! I don't like the inconsistency now that you point it out.
This debug mode was undocumented publicly until recently, and now that that's the case, it should be more consistent, so I'll work on both making it accept all cases and to warn when an invalid level has been supplied.
[edit: I've removed my assignment on this issue since I won't get to it for a while if I do, and added the tag for the remote backend -- although the update is small (if you don't change out the fmt logging for a proper logger 🙈 ), upgrading to the latest go-tfe library breaks tests in Terraform, so this needs more attention than I thought]
I'm using terraform 1.7.2 and I'm finding TF_IGNORE has no effect at all. Is this feature broken? I had to debug by trial and error just adding/removing things from .terraformignore and it's suddenly faster when I got the syntax correct. I still get no output from this setting at all.