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

meta.SDKVersion reporting incorrect version #1257

Closed
jacobbednarz opened this issue Oct 11, 2023 · 6 comments · Fixed by #1260
Closed

meta.SDKVersion reporting incorrect version #1257

jacobbednarz opened this issue Oct 11, 2023 · 6 comments · Fixed by #1260
Labels
bug Something isn't working
Milestone

Comments

@jacobbednarz
Copy link

SDK version

v2.29.0

Relevant provider source code

var SDKVersion = "2.10.1"

Terraform Configuration Files

n/a

Example usage

cloudflare/terraform-provider-cloudflare uses this value to append to the UA string.

https://github.com/cloudflare/terraform-provider-cloudflare/blob/658bb74d9a8ee1e258e10936bbe3c6c206ca4fe7/internal/sdkv2provider/provider.go#L380C3-L381

Expected Behavior

meta.SDKVersion should report v2.29.0

Actual Behavior

meta.SDKVersion reports v2.10.1

Steps to Reproduce

References

@bflad
Copy link
Member

bflad commented Oct 11, 2023

Since this is previously existing functionality that is not working as intended we will target fixing this in an upcoming terraform-plugin-sdk release. It appears an automated update to the file contents was not ported over to the newer release process.

It is important to note however that Go module code such as provider code, can fetch this information automatically using Go standard library functionality. The runtime/debug.ReadBuildInfo() function returns the Deps field which contains module paths and version information. This is how Terraform core, for example, is able to log "interesting" dependencies: https://github.com/hashicorp/terraform/blob/07b814c030daae39dea764571bef9cecf26e49be/version/dependencies.go#L8-L46

Given that, we may opt to fix the issue while also deprecating the exported function to suggest using runtime/debug information instead. It may be better to switch to that guaranteed to work information rather than depending on this potentially flaky version information.

@bflad bflad added this to the v2.30.0 milestone Oct 11, 2023
bflad added a commit that referenced this issue Oct 11, 2023
Reference: #1257

The release process is also updated to automatically overwrite the version variable as it did in the previous release process. While this should ensure this version information is correct going forward, consumers should instead prefer the Go standard library `runtime/debug` package build information, which is guaranteed to always be correct.
bflad added a commit that referenced this issue Oct 11, 2023
…1260)

Reference: #1257

The release process is also updated to automatically overwrite the version variable as it did in the previous release process. While this should ensure this version information is correct going forward, consumers should instead prefer the Go standard library `runtime/debug` package build information, which is guaranteed to always be correct.
@jacobbednarz
Copy link
Author

thanks for the update @bflad 🙇 using runtime.Debug can work for my case however, I wasn't sure if it was "blessed" and would potentially disappear given the value hasn't been getting set during the release.

@austinvalle
Copy link
Member

I think using runtime.Debug is going to be the most accurate way for you to determine the version of any dependency, the only real requirement is building your binary with Go module support, which all terraform providers are doing 👍🏻 .

The information is pretty easy to grok using that Deps field, as well as you can see this info using the Go toolchain outside of the code.

Example using the main branch of the cloudflare provider:

 $ go build .

 $ go version -m ./terraform-provider-cloudflare 
./terraform-provider-cloudflare: go1.21.1
        path    github.com/cloudflare/terraform-provider-cloudflare
        mod     github.com/cloudflare/terraform-provider-cloudflare     (devel)
        dep     github.com/MakeNowJust/heredoc/v2       v2.0.1  h1:rlCHh70XXXv7toz95ajQWOWQnN4WNLt0TdpZYIR/J6A=
        dep     github.com/agext/levenshtein    v1.2.3  h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo=
        dep     github.com/apparentlymart/go-textseg/v15        v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY=
        dep     github.com/cloudflare/cloudflare-go     v0.79.0 h1:ErwCYDjFCYppDJlDJ/5WhsSmzegAUe2+K9qgFyQDg3M=
        dep     github.com/fatih/color  v1.13.0 h1:8LOYc1KYPPmyKMuN8QV2DNRWNbLo6LZ0iLs8+mlH53w=
        dep     github.com/goccy/go-json        v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU=
        dep     github.com/golang/protobuf      v1.5.3  h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
        dep     github.com/google/go-cmp        v0.6.0  h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
        dep     github.com/google/go-querystring        v1.1.0  h1:AnCroh3fv4ZBgVIf1Iwtovgjaw/GiKJo8M8yD/fhyJ8=
        dep     github.com/google/uuid  v1.3.1  h1:KjJaJ9iWZ3jOFZIf1Lqf4laDRCasjl0BCmnEGxkdLb4=
        dep     github.com/hashicorp/errwrap    v1.1.0  h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY2I=
        dep     github.com/hashicorp/go-cleanhttp       v0.5.2  h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
        dep     github.com/hashicorp/go-cty     v1.4.1-0.20200414143053-d3edf31b6320    h1:1/D3zfFHttUKaCaGKZ/dR2roBXv0vKbSCnssIldfQdI=
        dep     github.com/hashicorp/go-hclog   v1.5.0  h1:bI2ocEMgcVlz55Oj1xZNBsVi900c7II+fWDyV9o+13c=
        dep     github.com/hashicorp/go-multierror      v1.1.1  h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
        dep     github.com/hashicorp/go-plugin  v1.5.1  h1:oGm7cWBaYIp3lJpx1RUEfLWophprE2EV/KUeqBYo+6k=
        dep     github.com/hashicorp/go-retryablehttp   v0.7.4  h1:ZQgVdpTdAL7WpMIwLzCfbalOcSUdkDZnpUv3/+BxzFA=
        dep     github.com/hashicorp/go-uuid    v1.0.3  h1:2gKiV6YVmrJ1i2CKKa9obLvRieoRGviZFL26PcT/Co8=
        dep     github.com/hashicorp/go-version v1.6.0  h1:feTTfFNnjP967rlCxM/I9g701jU+RN74YKx2mOkIeek=
        dep     github.com/hashicorp/hcl/v2     v2.18.0 h1:wYnG7Lt31t2zYkcquwgKo6MWXzRUDIeIVU5naZwHLl8=
        dep     github.com/hashicorp/logutils   v1.0.0  h1:dLEQVugN8vlakKOUE3ihGLTZJRB4j+M2cdTm/ORI65Y=
        dep     github.com/hashicorp/terraform-plugin-framework v1.4.1  h1:ZC29MoB3Nbov6axHdgPbMz7799pT5H8kIrM8YAsaVrs=
        dep     github.com/hashicorp/terraform-plugin-framework-validators      v0.12.0 h1:HOjBuMbOEzl7snOdOoUfE2Jgeto6JOjLVQ39Ls2nksc=
        dep     github.com/hashicorp/terraform-plugin-go        v0.19.0 h1:BuZx/6Cp+lkmiG0cOBk6Zps0Cb2tmqQpDM3iAtnhDQU=
        dep     github.com/hashicorp/terraform-plugin-log       v0.9.0  h1:i7hOA+vdAItN1/7UrfBqBwvYPQ9TFvymaRGZED3FCV0=
        dep     github.com/hashicorp/terraform-plugin-mux       v0.12.0 h1:TJlmeslQ11WlQtIFAfth0vXx+gSNgvMEng2Rn9z3WZY=
        dep     github.com/hashicorp/terraform-plugin-sdk/v2    v2.29.0 h1:wcOKYwPI9IorAJEBLzgclh3xVolO7ZorYd6U1vnok14=
        dep     github.com/hashicorp/terraform-registry-address v0.2.2  h1:lPQBg403El8PPicg/qONZJDC6YlgCVbWDtNmmZKtBno=
        dep     github.com/hashicorp/terraform-svchost  v0.1.1  h1:EZZimZ1GxdqFRinZ1tpJwVxxt49xc/S52uzrw4x0jKQ=
        dep     github.com/hashicorp/yamux      v0.0.0-20210826001029-26ff87cf9493      h1:brI5vBRUlAlM34VFmnLPwjnCL/FxAJp9XvOdX6Zt+XE=
        dep     github.com/mattn/go-colorable   v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
        dep     github.com/mattn/go-isatty      v0.0.16 h1:bq3VjFmv/sOjHtdEhmkEV4x1AJtvUvOJ2PFAZ5+peKQ=
        dep     github.com/mitchellh/copystructure      v1.2.0  h1:vpKXTN4ewci03Vljg/q9QvCGUDttBOGBIa15WveJJGw=
        dep     github.com/mitchellh/go-testing-interface       v1.14.1 h1:jrgshOhYAUVNMAJiKbEu7EqAwgJJ2JqpQmpLJOu07cU=
        dep     github.com/mitchellh/go-wordwrap        v1.0.1  h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0=
        dep     github.com/mitchellh/mapstructure       v1.5.0  h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY=
        dep     github.com/mitchellh/reflectwalk        v1.0.2  h1:G2LzWKi524PWgd3mLHV8Y5k7s6XUvT0Gef6zxSIeXaQ=
        dep     github.com/oklog/run    v1.1.0  h1:GEenZ1cK0+q0+wsJew9qUg/DyD8k3JzYsZAi5gYi2mA=
        dep     github.com/pkg/errors   v0.9.1  h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
        dep     github.com/vmihailenco/msgpack  v4.0.4+incompatible     h1:dSLoQfGFAo3F6OoNhwUmLwVgaUXK79GlxNBwueZn0xI=
        dep     github.com/vmihailenco/msgpack/v5       v5.3.5  h1:5gO0H1iULLWGhs2H5tbAHIZTV8/cYafcFOr9znI5mJU=
        dep     github.com/vmihailenco/tagparser/v2     v2.0.0  h1:y09buUbR+b5aycVFQs/g70pqKVZNBmxwAhO7/IwNM9g=
        dep     github.com/zclconf/go-cty       v1.14.0 h1:/Xrd39K7DXbHzlisFP9c4pHao4yyf+/Ug9LEz+Y/yhc=
        dep     golang.org/x/net        v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
        dep     golang.org/x/sys        v0.13.0 h1:Af8nKPmuFypiUBjVoU9V20FiaFXOcuZI21p0ycVYYGE=
        dep     golang.org/x/text       v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
        dep     golang.org/x/time       v0.3.0  h1:rg5rLMjNzMS1RkNLzCG38eapWhnYLFYXDXj2gOlr8j4=
        dep     google.golang.org/genproto/googleapis/rpc       v0.0.0-20230525234030-28d5490b6b19      h1:0nDDozoAU19Qb2HwhXadU8OcsiO/09cnTqhUtq2MEOM=
        dep     google.golang.org/grpc  v1.57.0 h1:kfzNeI/klCGD2YPMUlaGNT3pxvYfga7smW3Vth8Zsiw=
        dep     google.golang.org/protobuf      v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
        build   -buildmode=exe
        build   -compiler=gc
        build   DefaultGODEBUG=panicnil=1
        build   CGO_ENABLED=1
        build   CGO_CFLAGS=
        build   CGO_CPPFLAGS=
        build   CGO_CXXFLAGS=
        build   CGO_LDFLAGS=
        build   GOARCH=arm64
        build   GOOS=darwin
        build   vcs=git
        build   vcs.revision=bf62e71b1097ec31c41945fb1ce4d8da69e39224
        build   vcs.time=2023-10-11T09:01:02Z
        build   vcs.modified=false

With that you could expect the runtime/debug.ReadBuildInfo() function to have a Dep with:

{
	Path: "github.com/hashicorp/terraform-plugin-framework",
	Version: "v1.4.1",
	Sum: "h1:ZC29MoB3Nbov6axHdgPbMz7799pT5H8kIrM8YAsaVrs=",
	Replace: nil
}

@austinvalle
Copy link
Member

austinvalle commented Oct 11, 2023

Also worth noting that using this approach, in the rare case, if you ever need to use a specific commit of terraform-plugin-framework, rather than a tagged release, you'll get a pseudo-version.

Example using cloudflare provider:

 $ go get -u github.com/hashicorp/terraform-plugin-framework@0fbaf4b17f282c2030858ae2c419b1d043325376

 $ go build .

 $ go version -m ./terraform-provider-cloudflare
./terraform-provider-cloudflare: go1.21.1
	path	github.com/cloudflare/terraform-provider-cloudflare
	mod	github.com/cloudflare/terraform-provider-cloudflare	(devel)
        # ... other dependencies
	dep	github.com/hashicorp/terraform-plugin-framework	v1.4.2-0.20231011150141-0fbaf4b17f28	h1:gwqWSq4edVnLt79kUcf4O7Kd8c4CE/5wmGrF06h3Nlo=

And the resulting Dep

{
	Path: "github.com/hashicorp/terraform-plugin-framework",
	Version: "v1.4.2-0.20231011150141-0fbaf4b17f28",
	Sum: "h1:gwqWSq4edVnLt79kUcf4O7Kd8c4CE/5wmGrF06h3Nlo=",
	Replace: nil
}

It's unlikely you'd need to ever need to do that, but wanted to highlight it. More documentation on that version field here: https://go.dev/ref/mod#versions

@jacobbednarz
Copy link
Author

much appreciate the additional context here @austinvalle. thank you both!

jacobbednarz added a commit to cloudflare/terraform-provider-cloudflare that referenced this issue Oct 12, 2023
Before this change, we relied on the plugin libraries to expose their version. Unfortunately, this was incorrectly set in SDKv2[1] and non-existent in the framework[2].

The recommended approach is to instead dig into the build information via`runtime/debug.ReadBuildInfo()`[3] which is what we introduce here in a slightly safer and consistent way.

[1]: hashicorp/terraform-plugin-sdk#1257
[2]: hashicorp/terraform-plugin-framework#855
[3]: https://pkg.go.dev/runtime/debug#ReadBuildInfo

Signed-off-by: Jacob Bednarz <jacob.bednarz@gmail.com>
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants