From 80fb516ec2203bfc676d8de7300cb14ddeb557bc Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Wed, 6 Sep 2023 11:26:39 -0400 Subject: [PATCH] all: Update Go Module to Go 1.20 (#1246) Reference: https://pkg.go.dev/math/rand#Seed Reference: https://github.com/hashicorp/terraform-plugin-sdk/issues/1245 Previously from `golangci-lint` after Go 1.20 upgrade: ``` helper/acctest/random.go:24:2: SA1019: rand.Seed has been deprecated since Go 1.20 and an alternative has been available since Go 1.0: As of Go 1.20 there is no reason to call Seed with a random value. Programs that call Seed with a known value to get a specific sequence of results should use New(NewSource(seed)) to obtain a local random generator. (staticcheck) rand.Seed(time.Now().UTC().UnixNano()) ^ ``` --- .../unreleased/NOTES-20230906-055849.yaml | 8 +++++++ .github/workflows/ci-go.yml | 2 +- README.md | 2 +- go.mod | 2 +- helper/acctest/random.go | 4 ---- tools/go.mod | 2 +- .../sdkv2/testing/acceptance-tests/index.mdx | 24 ++++++++++--------- 7 files changed, 25 insertions(+), 19 deletions(-) create mode 100644 .changes/unreleased/NOTES-20230906-055849.yaml diff --git a/.changes/unreleased/NOTES-20230906-055849.yaml b/.changes/unreleased/NOTES-20230906-055849.yaml new file mode 100644 index 0000000000..68b5461db9 --- /dev/null +++ b/.changes/unreleased/NOTES-20230906-055849.yaml @@ -0,0 +1,8 @@ +kind: NOTES +body: 'all: This Go module has been updated to Go 1.20 per the [Go support + policy](https://go.dev/doc/devel/release#policy). It is recommended to review + the [Go 1.20 release notes](https://go.dev/doc/go1.20) before upgrading. Any + consumers building on earlier Go versions may experience errors.' +time: 2023-09-06T05:58:49.879435-04:00 +custom: + Issue: "1245" diff --git a/.github/workflows/ci-go.yml b/.github/workflows/ci-go.yml index c855113fe8..05ae733219 100644 --- a/.github/workflows/ci-go.yml +++ b/.github/workflows/ci-go.yml @@ -48,7 +48,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go-version: [ '1.20', '1.19' ] + go-version: [ '1.21', '1.20' ] steps: - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3.5.3 - uses: actions/setup-go@93397bea11091df50f3d7e59dc26a7711a8bcfbe # v4.1.0 diff --git a/README.md b/README.md index 5125ae372b..118c29211d 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ When running provider tests, Terraform 0.12.26 or later is needed for version 2. This project follows the [support policy](https://golang.org/doc/devel/release.html#policy) of Go as its support policy. The two latest major releases of Go are supported by the project. -Currently, that means Go **1.19** or later must be used when including this project as a dependency. +Currently, that means Go **1.20** or later must be used when including this project as a dependency. ## Getting Started diff --git a/go.mod b/go.mod index 280accfe8e..4316566571 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/hashicorp/terraform-plugin-sdk/v2 -go 1.19 +go 1.20 require ( github.com/google/go-cmp v0.5.9 diff --git a/helper/acctest/random.go b/helper/acctest/random.go index abb778aa04..c26303eb60 100644 --- a/helper/acctest/random.go +++ b/helper/acctest/random.go @@ -20,10 +20,6 @@ import ( "golang.org/x/crypto/ssh" ) -func init() { - rand.Seed(time.Now().UTC().UnixNano()) -} - // Helpers for generating random tidbits for use in identifiers to prevent // collisions in acceptance tests. diff --git a/tools/go.mod b/tools/go.mod index fcd3f72703..c1aaab58ca 100644 --- a/tools/go.mod +++ b/tools/go.mod @@ -1,6 +1,6 @@ module tools -go 1.19 +go 1.20 require github.com/hashicorp/copywrite v0.16.4 diff --git a/website/docs/plugin/sdkv2/testing/acceptance-tests/index.mdx b/website/docs/plugin/sdkv2/testing/acceptance-tests/index.mdx index 34c7710c6d..f0d2cecb22 100644 --- a/website/docs/plugin/sdkv2/testing/acceptance-tests/index.mdx +++ b/website/docs/plugin/sdkv2/testing/acceptance-tests/index.mdx @@ -142,7 +142,7 @@ Create a [GitHub Actions workflow](https://docs.github.com/en/actions/using-work Use the [`matrix`](https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#jobsjob_idstrategymatrix) strategy for more advanced configuration, such as running acceptance testing against multiple Terraform CLI versions. -The following example workflow runs acceptance testing for the provider using the latest patch versions of Go 1.19 and Terraform CLI 1.3: +The following example workflow runs acceptance testing for the provider using the latest patch versions of Go defined in the `go.mod` file and Terraform CLI 1.5: ```yaml name: Terraform Provider Tests @@ -163,12 +163,12 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: actions/setup-go@v3 + - uses: actions/setup-go@v4 with: - go-version: '1.19' + go-version-file: 'go.mod' - uses: hashicorp/setup-terraform@v2 with: - terraform_version: '1.3.*' + terraform_version: '1.5.*' terraform_wrapper: false - run: go test -v -cover ./... env: @@ -178,14 +178,14 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: actions/setup-go@v3 + - uses: actions/setup-go@v4 with: - go-version: '1.19' + go-version-file: 'go.mod' - run: go test -v -cover ./... ``` -The following example workflow runs acceptance testing for the provider using the latest patch versions of Go 1.19 and Terraform CLI 0.12 through 1.3: +The following example workflow runs acceptance testing for the provider using the latest patch versions of Go defined in the `go.mod` file and Terraform CLI 0.12 through 1.5: ```yaml name: Terraform Provider Tests @@ -216,11 +216,13 @@ jobs: - '1.1.*' - '1.2.*' - '1.3.*' + - '1.4.*' + - '1.5.*' steps: - uses: actions/checkout@v3 - - uses: actions/setup-go@v3 + - uses: actions/setup-go@v4 with: - go-version: '1.19' + go-version-file: 'go.mod' - uses: hashicorp/setup-terraform@v2 with: terraform_version: ${{ matrix.terraform-version }} @@ -233,9 +235,9 @@ jobs: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 - - uses: actions/setup-go@v3 + - uses: actions/setup-go@v4 with: - go-version: '1.19' + go-version-file: 'go.mod' - run: go test -v -cover ./... ```