-
Notifications
You must be signed in to change notification settings - Fork 9.7k
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
Build with Go 1.21.0 #33691
Build with Go 1.21.0 #33691
Conversation
While working on something else I recalled that sometimes during Go upgrades we need to consider changes to the Unicode version supported by the standard library, and indeed that seems to be the case here: Go 1.21 has upgraded to Unicode 15. This will therefore require some further changes as described in How Terraform Uses Unicode, so we can ensure that our support for Unicode is consistently based on Unicode 15 throughout Terraform. |
@apparentlymart I believe Unicode 15 doesn't make changes to the textseg algorithm relative to Unicode 13 and have opened apparentlymart/go-textseg#5 to bump go-textseg to v15. Once go-textseg/v15 and go-cty are released I'll propagate the change through HCL and Terraform. |
I've been through the Go 1.21.0 release notes and I don't see anything relevant for Terraform users except the updates to Unicode and minimum macOS and Windows versions, which I'll document in the changelog. The following points were interesting to note but require no further action. runtime:
|
if recovered == nil { |
We are not intentionally using panic(nil)
in any sort of magical way in Terraform (see golang/go#25448 for some examples), though it is possible that we may accidentally end up with a panic(nil)
at runtime by mistake, which PanicHandler()
was previously ignoring. We can lint for this in future.
toolchain: go
version directive in go.mod
now strict
To improve forwards compatibility, Go 1.21 now reads the go line in a go.work or go.mod file as a strict minimum requirement: go 1.21.0 means that the workspace or module cannot be used with Go 1.20 or with Go 1.21rc1.
To make these new stricter version requirements easier to manage, the go command can now invoke not just the toolchain bundled in its own release but also other Go toolchain versions found in the PATH or downloaded on demand.
The new toolchain directive sets a suggested minimum toolchain to use, which may be newer than the strict go minimum.
Automatic toolchain downloading sounds like it might be a bit of a surprise to those using go
in network-constrained environments, but that's not a problem specific to Terraform.
I've bumped the go
directive in go.mod
to 1.21 because unit tests no longer pass on Go 1.20 due to the mTLS error message change.
flag
: calling .Set()
on a flag twice will panic
flag
: A flag definition (via Bool, BoolVar, Int, IntVar, etc.) will panic if Set has already been called on a flag with the same name. This change is intended to detect cases where changes in initialization order cause flag operations to occur in a different order than expected. In many cases the fix to this problem is to introduce a explicit package dependence to correctly order the definition before any Set operations.
No change required because we are not calling Set()
twice on any flag. The panic will make it quite obvious to anyone who makes this mistake in future.
Go 1.21 introduced more detailed error conditions for mTLS connections. As of Go 1.21, if the server is configured to require client auth, but no client cert is provided, the alert is now "certificate required", rather than "bad certificate". See golang/go@62a9948.
As of Go 1.21.0, the go directive in go.mod declares a strict minimum version of Go necessary to use a module. The go command will download a copy of the newer toolchain if necessary.
The last released version of staticcheck does not yet support Go 1.21.0, so pin to the latest commit. When a version is released that supports Go 1.21.0, we should pin to that instead.
This update means that HCL, cty, and Terraform all use Unicode 15.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since we swapped ownership of this PR after opening it I can't approve it in the GitHub workflow sense of the word, but this set of changes looks good to me and I'd have approved it if I could.
Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch. |
I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions. |
We typically make each new minor release with whatever minor version of Go is current at its code freeze and leave the Go minor version frozen throughout a Terraform minor release series.
This is the instance of that for making Terraform v1.6 be built with Go 1.21, which is now released.
Changes made (@kmoe):
.go-version
andgo.mod
. Please see note below about changes to thego
directive ingo.mod
.Original PR description by @apparentlymart :
However, this is not quite ready yet:
The text of a TLS-related error message in the standard library seems to have changed, causing one of the
http
backend's tests to fail.We'll need to closely review the Go 1.21 release notes to see if any changes will effectively be passed on to Terraform users as Terraform CLI or language changes, so we can either mitigate them or document them in our own changelog.
Given that several Terraform language features are essentially just thin wrappers around Go standard library bits, it's typical for there to be at least a few small notes, but I've not yet studied the release notes in enough detail to say whether there's anything concerning in this particular release.
Mainly I'm just opening this PR right now as a placeholder to put in the release milestone to record the intention to upgrade before the development freeze. I hope to have more time to spend on this some time in the next few weeks, but I'm busy with other things this week and so won't be able to complete this immediately.