hashicorp / terraform-plugin-sdk

Terraform Plugin SDK enables building plugins (providers) to manage any service providers or custom in-house solutions
https://developer.hashicorp.com/terraform/plugin
Mozilla Public License 2.0
436 stars 231 forks source link

`meta.SDKVersion` reporting incorrect version #1257

Closed jacobbednarz closed 12 months ago

jacobbednarz commented 12 months ago

SDK version

v2.29.0

Relevant provider source code

https://github.com/hashicorp/terraform-plugin-sdk/blob/ec118d67dca1878e6582e392b0dad368b7092d91/meta/meta.go#L17

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 commented 12 months ago

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.

jacobbednarz commented 12 months ago

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 commented 12 months ago

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 commented 12 months ago

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 commented 12 months ago

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

github-actions[bot] commented 11 months ago

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.