Skip to content
Browse files
main: Report version information for "interesting" dependencies
We have a few dependencies that are such a significant part of Terraform's
behavior that they will often be the root cause of or the solution to a
bug reported against Terraform.

As a small quality-of-life improvement to help with diagnosing those,
we'll now report the selected versions for each of these so-called
"interesting" dependencies as part of our initial trace log output during
Terraform startup.

The goal here is that when someone opens a bug report, and includes the
trace log as our bug report template requests, we'll be able to see at a
glance which versions of these dependencies were involved, instead of
having to manually cross-reference in the go.mod file of the reported main
Terraform CLI version.

This does slightly grow the general overhead of the logs, but as long as
we keep this set of interesting dependencies relatively small it shouldn't
present any significant problem in typical usage.
  • Loading branch information
apparentlymart committed Nov 5, 2021
1 parent 19101df commit 5ac1074c541f6e2dff4e05459764cf9f943168d3
Showing 2 changed files with 47 additions and 0 deletions.
@@ -79,6 +79,9 @@ func realMain() int {
"[INFO] Terraform version: %s %s",
Version, VersionPrerelease)
for _, depMod := range version.InterestingDependencies() {
log.Printf("[DEBUG] using %s %s", depMod.Path, depMod.Version)
log.Printf("[INFO] Go runtime version: %s", runtime.Version())
log.Printf("[INFO] CLI args: %#v", os.Args)

@@ -0,0 +1,44 @@
package version

import "runtime/debug"

// See the docs for InterestingDependencyVersions to understand what
// "interesting" is intended to mean here. We should keep this set relatively
// small to avoid bloating the logs too much.
var interestingDependencies = map[string]struct{}{
"": {},
"": {},
"": {},
"": {},
"": {},

// InterestingDependencies returns the compiled-in module version info for
// a small number of dependencies that Terraform uses broadly and which we
// tend to upgrade relatively often as part of improvements to Terraform.
// The set of dependencies this reports might change over time if our
// opinions change about what's "interesting". This is here only to create
// a small number of extra annotations in a debug log to help us more easily
// cross-reference bug reports with dependency changelogs.
func InterestingDependencies() []*debug.Module {
info, ok := debug.ReadBuildInfo()
if !ok {
// Weird to not be built in module mode, but not a big deal.
return nil

ret := make([]*debug.Module, 0, len(interestingDependencies))

for _, mod := range info.Deps {
if _, ok := interestingDependencies[mod.Path]; !ok {
if mod.Replace != nil {
mod = mod.Replace
ret = append(ret, mod)

return ret

0 comments on commit 5ac1074

Please sign in to comment.