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 11, 2024
1 parent 7f94a9d commit e6af236
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 @@ -12,6 +12,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Renamed example files to the correct name so they are automatically included
in the docs.

## 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 e6af236

Please sign in to comment.