mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
5ac1074c54
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.
45 lines
1.5 KiB
Go
45 lines
1.5 KiB
Go
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{}{
|
|
"github.com/hashicorp/hcl/v2": {},
|
|
"github.com/zclconf/go-cty": {},
|
|
"github.com/hashicorp/go-tfe": {},
|
|
"github.com/hashicorp/terraform-config-inspect": {},
|
|
"github.com/hashicorp/terraform-svchost": {},
|
|
}
|
|
|
|
// 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 {
|
|
continue
|
|
}
|
|
if mod.Replace != nil {
|
|
mod = mod.Replace
|
|
}
|
|
ret = append(ret, mod)
|
|
}
|
|
|
|
return ret
|
|
}
|