From 7c4737b3ddbc85ae78c00d5d0cd8784a948e87e8 Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Tue, 12 Apr 2022 07:36:37 -0400 Subject: [PATCH] Bump Expected Minimum Go Version to 1.17 (#934) Reference: https://github.com/hashicorp/terraform-plugin-sdk/issues/933 Previously from `tenv` linter: ``` helper/schema/schema_test.go:29:2: os.Setenv() can be replaced by `t.Setenv()` in TestEnvDefaultFunc (tenv) if err := os.Setenv(key, "foo"); err != nil { ^ helper/schema/schema_test.go:67:2: os.Setenv() can be replaced by `t.Setenv()` in TestMultiEnvDefaultFunc (tenv) if err := os.Setenv(keys[0], "foo"); err != nil { ^ helper/schema/schema_test.go:85:2: os.Setenv() can be replaced by `t.Setenv()` in TestMultiEnvDefaultFunc (tenv) if err := os.Setenv(keys[1], "foo"); err != nil { ^ helper/schema/schema_test.go:8479:2: os.Setenv() can be replaced by `t.Setenv()` in TestPanicOnErrorDefaultsFalse (tenv) os.Setenv("TF_ACC", "") ^ helper/schema/schema_test.go:8484:2: os.Setenv() can be replaced by `t.Setenv()` in TestPanicOnErrorDefaultsFalse (tenv) os.Setenv("TF_ACC", oldEnv) ^ helper/schema/schema_test.go:8490:2: os.Setenv() can be replaced by `t.Setenv()` in TestPanicOnErrorTF_ACCSet (tenv) os.Setenv("TF_ACC", "1") ^ helper/schema/schema_test.go:8495:2: os.Setenv() can be replaced by `t.Setenv()` in TestPanicOnErrorTF_ACCSet (tenv) os.Setenv("TF_ACC", oldEnv) ^ ``` --- .changelog/934.txt | 3 +++ .github/workflows/ci-go.yml | 2 +- .go-version | 2 +- .golangci.yml | 2 +- README.md | 4 ++-- go.mod | 35 +++++++++++++++++++++++++++++------ helper/schema/schema_test.go | 22 +++++----------------- 7 files changed, 42 insertions(+), 28 deletions(-) create mode 100644 .changelog/934.txt diff --git a/.changelog/934.txt b/.changelog/934.txt new file mode 100644 index 0000000000..40960a9035 --- /dev/null +++ b/.changelog/934.txt @@ -0,0 +1,3 @@ +```release-note:note +This Go module has been updated to Go 1.17 per the [Go support policy](https://golang.org/doc/devel/release.html#policy). Any consumers building on earlier Go versions may experience errors. +``` diff --git a/.github/workflows/ci-go.yml b/.github/workflows/ci-go.yml index 3016841832..1252fc6ad4 100644 --- a/.github/workflows/ci-go.yml +++ b/.github/workflows/ci-go.yml @@ -56,7 +56,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - go-version: [ '1.17', '1.16' ] + go-version: [ '1.18', '1.17' ] steps: - uses: actions/checkout@v3 - uses: actions/setup-go@v3 diff --git a/.go-version b/.go-version index 293bfa8f06..a23a1564cd 100644 --- a/.go-version +++ b/.go-version @@ -1 +1 @@ -1.16.7 +1.17.8 diff --git a/.golangci.yml b/.golangci.yml index a9ce7085c1..f6081de33c 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -21,7 +21,7 @@ linters: # - paralleltest # Reference: https://github.com/kunwardeep/paralleltest/issues/14 - predeclared - staticcheck - # - tenv # TODO: Enable when upgrading Go 1.16 to 1.17 + - tenv - unconvert - unparam - varcheck diff --git a/README.md b/README.md index d193a7ae5d..07a58aeb71 100644 --- a/README.md +++ b/README.md @@ -14,9 +14,9 @@ When running provider tests, Terraform 0.12.26 or later is needed for version 2. ## Go Compatibility -The Terraform Plugin SDK is built in Go, and uses 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 SDK. +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.16** or later must be used when building a provider with the SDK. +Currently, that means Go **1.17** or later must be used when including this project as a dependency. ## Getting Started diff --git a/go.mod b/go.mod index f386fa59d8..dd9ba50363 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,8 @@ module github.com/hashicorp/terraform-plugin-sdk/v2 -go 1.16 +go 1.17 require ( - github.com/agext/levenshtein v1.2.2 // indirect github.com/apparentlymart/go-cidr v1.1.0 github.com/apparentlymart/go-dump v0.0.0-20190214190832-042adf3cf4a0 github.com/davecgh/go-spew v1.1.1 @@ -21,17 +20,41 @@ require ( github.com/hashicorp/terraform-json v0.13.0 github.com/hashicorp/terraform-plugin-go v0.8.0 github.com/hashicorp/terraform-plugin-log v0.3.0 - github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect - github.com/kylelemons/godebug v1.1.0 // indirect github.com/mitchellh/copystructure v1.2.0 github.com/mitchellh/go-testing-interface v1.14.1 - github.com/mitchellh/go-wordwrap v1.0.0 // indirect github.com/mitchellh/mapstructure v1.4.3 github.com/mitchellh/reflectwalk v1.0.2 - github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect github.com/zclconf/go-cty v1.10.0 golang.org/x/crypto v0.0.0-20210616213533-5ff15b29337e golang.org/x/tools v0.0.0-20200713011307-fd294ab11aed +) + +require ( + github.com/agext/levenshtein v1.2.2 // indirect + github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect + github.com/fatih/color v1.7.0 // indirect + github.com/golang/protobuf v1.5.2 // indirect + github.com/hashicorp/errwrap v1.0.0 // indirect + github.com/hashicorp/go-checkpoint v0.5.0 // indirect + github.com/hashicorp/go-cleanhttp v0.5.2 // indirect + github.com/hashicorp/terraform-registry-address v0.0.0-20210412075316-9b2996cce896 // indirect + github.com/hashicorp/terraform-svchost v0.0.0-20200729002733-f050f53b9734 // indirect + github.com/hashicorp/yamux v0.0.0-20181012175058-2f1d1f20f75d // indirect + github.com/kylelemons/godebug v1.1.0 // indirect + github.com/mattn/go-colorable v0.1.4 // indirect + github.com/mattn/go-isatty v0.0.10 // indirect + github.com/mitchellh/go-wordwrap v1.0.0 // indirect + github.com/oklog/run v1.0.0 // indirect + github.com/vmihailenco/msgpack v4.0.4+incompatible // indirect + github.com/vmihailenco/msgpack/v4 v4.3.12 // indirect + github.com/vmihailenco/tagparser v0.1.1 // indirect + golang.org/x/mod v0.3.0 // indirect + golang.org/x/net v0.0.0-20210326060303-6b1517762897 // indirect + golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1 // indirect + golang.org/x/text v0.3.5 // indirect + golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect google.golang.org/appengine v1.6.6 // indirect google.golang.org/genproto v0.0.0-20200711021454-869866162049 // indirect + google.golang.org/grpc v1.45.0 // indirect + google.golang.org/protobuf v1.27.1 // indirect ) diff --git a/helper/schema/schema_test.go b/helper/schema/schema_test.go index d1e29fff81..a39250fe14 100644 --- a/helper/schema/schema_test.go +++ b/helper/schema/schema_test.go @@ -26,9 +26,7 @@ func TestEnvDefaultFunc(t *testing.T) { defer os.Unsetenv(key) f := EnvDefaultFunc(key, "42") - if err := os.Setenv(key, "foo"); err != nil { - t.Fatalf("err: %s", err) - } + t.Setenv(key, "foo") actual, err := f() if err != nil { @@ -64,9 +62,7 @@ func TestMultiEnvDefaultFunc(t *testing.T) { // Test that the first key is returned first f := MultiEnvDefaultFunc(keys, "42") - if err := os.Setenv(keys[0], "foo"); err != nil { - t.Fatalf("err: %s", err) - } + t.Setenv(keys[0], "foo") actual, err := f() if err != nil { @@ -82,9 +78,7 @@ func TestMultiEnvDefaultFunc(t *testing.T) { // Test that the second key is returned if the first one is empty f = MultiEnvDefaultFunc(keys, "42") - if err := os.Setenv(keys[1], "foo"); err != nil { - t.Fatalf("err: %s", err) - } + t.Setenv(keys[1], "foo") actual, err = f() if err != nil { @@ -8474,25 +8468,19 @@ func TestValidateAtLeastOneOfAttributes(t *testing.T) { } func TestPanicOnErrorDefaultsFalse(t *testing.T) { - oldEnv := os.Getenv("TF_ACC") + t.Setenv("TF_ACC", "") - os.Setenv("TF_ACC", "") if schemaMap(nil).panicOnError() { t.Fatalf("panicOnError should be false when TF_ACC is empty") } - - os.Setenv("TF_ACC", oldEnv) } func TestPanicOnErrorTF_ACCSet(t *testing.T) { - oldEnv := os.Getenv("TF_ACC") + t.Setenv("TF_ACC", "1") - os.Setenv("TF_ACC", "1") if !schemaMap(nil).panicOnError() { t.Fatalf("panicOnError should be true when TF_ACC is not empty") } - - os.Setenv("TF_ACC", oldEnv) } func TestValidateRequiredWithAttributes(t *testing.T) {