Skip to content

Commit

Permalink
enable request logging when debug is enabled
Browse files Browse the repository at this point in the history
Previously, enabling debug for the tf provider did not log out requests.
The cloud sdk already supported a debug mode. We now enable this via
configuration if one of the terraform debug env vars (TF_LOG_PROVIDER or
TF_LOG) are set to either "DEBUG" or "TRACE".
  • Loading branch information
fantapop committed Mar 3, 2024
1 parent 94f1502 commit d3bced2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

## Added

- Allow the logging of requests to the cloud SDK by setting either TF_LOG or
TF_LOG_PROVIDER envvars to either DEBUG or TRACE.

## [1.3.1] - 2023-12-01

### Fixed
Expand Down
10 changes: 10 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,16 @@ func (p *provider) Configure(
}
cfg.UserAgent = UserAgent

logLevel := os.Getenv("TF_LOG")
if logLevel == "DEBUG" || logLevel == "TRACE" {
cfg.Debug = true
} else {
logLevel = os.Getenv("TF_LOG_PROVIDER")
if logLevel == "DEBUG" || logLevel == "TRACE" {
cfg.Debug = true
}
}

// retryablehttp gives us automatic retries with exponential backoff.
httpClient := retryablehttp.NewClient()
// The TF framework will pick up the default global logger.
Expand Down

0 comments on commit d3bced2

Please sign in to comment.