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

Build with Go 1.21.0 #33691

Merged
merged 7 commits into from
Aug 30, 2023
Merged

Build with Go 1.21.0 #33691

merged 7 commits into from
Aug 30, 2023

Conversation

apparentlymart
Copy link
Contributor

@apparentlymart apparentlymart commented Aug 15, 2023

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):

  • tests: Update a unit test to reflect more fine-grained mTLS errors 37ac4e1
  • Update .go-version and go.mod. Please see note below about changes to the go directive in go.mod.
  • As noted in the v1.5.0 changelog, the minimum required versions of macOS and Windows have been bumped.
  • scripts: pin version of staticcheck package (a005a33) for Go 1.21 support. Pinning some version of this tool is a good idea anyway.
  • Ensure Unicode 15 is used consistently throughout Terraform by upgrading the following chain of dependencies:
    • go-textseg/v15
    • go-cty
    • HCL
    • Terraform

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.

@apparentlymart apparentlymart added this to the v1.6.0 milestone Aug 15, 2023
@apparentlymart apparentlymart self-assigned this Aug 15, 2023
@apparentlymart
Copy link
Contributor Author

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.

@kmoe
Copy link
Member

kmoe commented Aug 29, 2023

@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.

@kmoe
Copy link
Member

kmoe commented Aug 29, 2023

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: recover() no longer returns nil with panic(nil)

Go 1.21 now defines that if a goroutine is panicking and recover was called directly by a deferred function, the return value of recover is guaranteed not to be nil. To ensure this, calling panic with a nil interface value (or an untyped nil) causes a run-time panic of type *runtime.PanicNilError.

No change required here because we don't depend on the old behaviour: we already assume that if the return value of recover() is nil, the calling goroutine did not panic:

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.

apparentlymart and others added 7 commits August 30, 2023 18:03
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.
@kmoe kmoe marked this pull request as ready for review August 30, 2023 17:04
@kmoe kmoe requested a review from a team as a code owner August 30, 2023 17:04
Copy link
Contributor Author

@apparentlymart apparentlymart left a 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.

@kmoe kmoe merged commit 91c30fe into main Aug 30, 2023
@github-actions
Copy link
Contributor

Reminder for the merging maintainer: if this is a user-visible change, please update the changelog on the appropriate release branch.

Copy link
Contributor

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.
If you have found a problem that seems related to this change, 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 Dec 11, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants