terraform icon indicating copy to clipboard operation
terraform copied to clipboard

Upgrade to Go 1.22

Open apparentlymart opened this issue 2 years ago • 0 comments

Our typical policy is that the first release in any new minor release series of Terraform is built using the latest stable version of Go available at the time it enters its prerelease period, and then we stay on the same minor release of Go for the remainder of each Terraform minor release series.

It seems that Go 1.22 will be released soon, and so the Terraform v1.8 series (currently in development on our main branch) should adopt it.

This issue therefore represents the work to get Terraform's Go dependency upgraded. This issue is "done" once the main branch is configured to build with a stable Go 1.22 release.

Possible Compatibility Concerns

Because some aspects of the Terraform language are implemented in terms of Go core library features, changes to the core library can potentially have impacts on Terraform's behavior that would cause Terraform to violate its compatibility promises if not compensated for.

The following is a list of potential areas of concern. None of these are definitely a problem, but we'll need to investigate each of them as part of upgrading.

  • The Go encoding/json package has changed marshaling behavior for the characters represented by the \b and \f escape sequences in the Go language. Previously the encoder used numeric unicode escapes (\u0008 and \u000c respectively) whereas now it uses the shorter JSON escape sequences \b and \f.

    Although this new encoding is equivalent from a JSON perspective, Terraform's jsonencode function is typically constrained to not change its encoding of anything previously accepted because authors use this function's results as part of provider arguments where the provider is unaware that the data is JSON, such as in the user_data argument of the aws_instance resource type in the hashicorp/aws provider. Because that argument is just a plain UTF-8 character sequence from the provider's perspective, it cannot automatically recognize when two different JSON encodings have equivalent meaning, and so will consider these as meaningful changes needing to be applied.

  • The pure-Go DNS resolver on Windows systems now supports querying the system's local hosts file before making a DNS query, whereas it did not before.

    This is only a potential concern for us if we're using the pure-Go resolver on Windows. I think (but have not yet confirmed) that we use the system resolver for our official Windows releases, in which case this change is immaterial for our purposes.

  • The Go HTTP client (which Terraform uses in a number of different contexts) now rejects an empty Content-Length header as an error, whereas before it just silently ignored it.

    This does not seem like an upgrade blocker but we should consider mentioning it in the upgrade guide in case someone has problems with e.g. an internal Terraform Provider Registry Protocol server, or similar, that produces such incorrect headers when responding to Terraform.

The list above was based on the Go 1.22 release notes on "tip" at the time of the 1.22-rc2 release. We should revisit it after the 1.22 final release in case of any updates that might change the areas of concern.

Other Notable Changes

  • Go 1.22 is the last release that will run on macOS 10.15 Catalina, and Go 1.23 will require macOS 11 Big Sur or later.

    We should pass on a similar comment about Terraform itself in the Terraform v1.8 upgrade guide, stating that Terraform v1.9 will require macOS 11 Big Sur or later. (It is technically not guaranteed that Go 1.23 will be ready in time for Terraform v1.9, but past experience suggests that being a safe assumption and it's better to have said it even if the change actually waits for Terraform v1.10.)

apparentlymart avatar Jan 26 '24 22:01 apparentlymart