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 Configurable TF_LOG environment variable >= Terraform CLI 0.15 #290

Closed
bflad opened this issue Apr 13, 2022 · 0 comments · Fixed by #291
Closed

Support Configurable TF_LOG environment variable >= Terraform CLI 0.15 #290

bflad opened this issue Apr 13, 2022 · 0 comments · Fixed by #291
Labels
enhancement New feature or request

Comments

@bflad
Copy link
Contributor

bflad commented Apr 13, 2022

Description

Post Terraform CLI 0.15, setting log levels outside TRACE is now considered reliable. Currently, terraform-exec hardcodes the equivalent of TF_LOG=TRACE when using (tfexec.Terraform).SetLogPath():

// always override logging
if tf.logPath == "" {
// so logging can't pollute our stderr output
env[logEnvVar] = ""
env[logPathEnvVar] = ""
} else {
env[logPathEnvVar] = tf.logPath
// Log levels other than TRACE are currently unreliable, the CLI recommends using TRACE only.
env[logEnvVar] = "TRACE"
}

Consumers, such as the terraform-plugin-sdk/v2 acceptance testing framework should be able to pass along a provider developer's desire for DEBUG or higher logs only from Terraform CLI.

Proposal

  • Add tfexec.Terraform type log string field.
  • Add (tfexec.Terraform).SetLog(string) error method, which sets the log field if Terraform CLI >= 0.15.
  • Update (tfexec.Terraform).SetLogPath(string) to set the log field to TRACE, unless it is already set (this will ensure SetLog() or SetLogPath() can be called in any order and preserve the previous behavior)
  • Update (tfexec.Terraform).buildEnv() logic to call env[logEnvVar] = tf.log instead of env[logEnvVar] = "TRACE"

References

@bflad bflad added the enhancement New feature or request label Apr 13, 2022
bflad added a commit that referenced this issue Apr 13, 2022
bflad added a commit that referenced this issue May 18, 2022
radeksimko pushed a commit that referenced this issue May 18, 2022
* tfexec: Add (Terraform).SetLog() method

Reference: #290

* tfexec: Add testing for SetLog

* tfexec: Add SetLogPath testing

* tfexec: Ensure SetLog version compatibility is 0.15 minimum, testing updates for darwin/arm64
rstandt pushed a commit to rstandt/terraform-exec that referenced this issue Jun 21, 2022
* tfexec: Add (Terraform).SetLog() method

Reference: hashicorp#290

* tfexec: Add testing for SetLog

* tfexec: Add SetLogPath testing

* tfexec: Ensure SetLog version compatibility is 0.15 minimum, testing updates for darwin/arm64
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

Successfully merging a pull request may close this issue.

1 participant