Skip to content

Commit 2981576

Browse files
committed
Merge remote-tracking branch 'origin/main' into f/import-state-id-config
2 parents 1b47671 + 4260dfd commit 2981576

38 files changed

+1804
-81
lines changed

.changes/1.12.0.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
## 1.12.0 (March 18, 2025)
2+
3+
NOTES:
4+
5+
* all: This Go module has been updated to Go 1.23 per the [Go support policy](https://go.dev/doc/devel/release#policy). It is recommended to review the [Go 1.23 release notes](https://go.dev/doc/go1.23) before upgrading. Any consumers building on earlier Go versions may experience errors. ([#454](https://github.com/hashicorp/terraform-plugin-testing/issues/454))
6+
7+
FEATURES:
8+
9+
* knownvalue: added function checks for custom validation of resource attribute or output values. ([#412](https://github.com/hashicorp/terraform-plugin-testing/issues/412))
10+
11+
ENHANCEMENTS:
12+
13+
* knownvalue: Updated the `ObjectExact` error message to report extra/missing attributes from the actual object. ([#451](https://github.com/hashicorp/terraform-plugin-testing/issues/451))
14+
* plancheck: Improved the unknown value plan check error messages to include a known value if one exists. ([#450](https://github.com/hashicorp/terraform-plugin-testing/issues/450))
15+
16+
BUG FIXES:
17+
18+
* plancheck: Fixed bug with all unknown value plan checks where a valid path would return a "path not found" error. ([#450](https://github.com/hashicorp/terraform-plugin-testing/issues/450))
19+

.github/workflows/ci-go.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
runs-on: ubuntu-latest
2828
strategy:
2929
matrix:
30-
go-version: [ '1.23', '1.22' ]
30+
go-version: [ '1.24', '1.23' ]
3131
terraform: ${{ fromJSON(vars.TF_VERSIONS_PROTOCOL_V5) }}
3232
steps:
3333
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2

.goreleaser.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@ builds:
55
milestones:
66
- close: true
77
release:
8+
prerelease: auto
89
ids:
910
- 'none'

CHANGELOG.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,22 @@
1+
## 1.12.0 (March 18, 2025)
2+
3+
NOTES:
4+
5+
* all: This Go module has been updated to Go 1.23 per the [Go support policy](https://go.dev/doc/devel/release#policy). It is recommended to review the [Go 1.23 release notes](https://go.dev/doc/go1.23) before upgrading. Any consumers building on earlier Go versions may experience errors. ([#454](https://github.com/hashicorp/terraform-plugin-testing/issues/454))
6+
7+
FEATURES:
8+
9+
* knownvalue: added function checks for custom validation of resource attribute or output values. ([#412](https://github.com/hashicorp/terraform-plugin-testing/issues/412))
10+
11+
ENHANCEMENTS:
12+
13+
* knownvalue: Updated the `ObjectExact` error message to report extra/missing attributes from the actual object. ([#451](https://github.com/hashicorp/terraform-plugin-testing/issues/451))
14+
* plancheck: Improved the unknown value plan check error messages to include a known value if one exists. ([#450](https://github.com/hashicorp/terraform-plugin-testing/issues/450))
15+
16+
BUG FIXES:
17+
18+
* plancheck: Fixed bug with all unknown value plan checks where a valid path would return a "path not found" error. ([#450](https://github.com/hashicorp/terraform-plugin-testing/issues/450))
19+
120
## 1.11.0 (November 19, 2024)
221

322
NOTES:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ When run from the root of a Terraform Provider codebase, Terraform’s testing f
99

1010
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.
1111

12-
Currently, that means Go **1.22** or later must be used when including this project as a dependency.
12+
Currently, that means Go **1.23** or later must be used when including this project as a dependency.
1313

1414
## Contributing
1515

go.mod

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
module github.com/hashicorp/terraform-plugin-testing
22

3-
go 1.22.0
3+
go 1.23.0
44

5-
toolchain go1.22.7
5+
toolchain go1.23.7
66

77
require (
88
github.com/google/go-cmp v0.7.0
9-
github.com/hashicorp/go-cty v1.4.1
9+
github.com/hashicorp/go-cty v1.5.0
1010
github.com/hashicorp/go-hclog v1.6.3
1111
github.com/hashicorp/go-uuid v1.0.3
1212
github.com/hashicorp/go-version v1.7.0
@@ -20,7 +20,7 @@ require (
2020
github.com/hashicorp/terraform-plugin-sdk/v2 v2.36.1
2121
github.com/mitchellh/go-testing-interface v1.14.1
2222
github.com/zclconf/go-cty v1.16.2
23-
golang.org/x/crypto v0.33.0
23+
golang.org/x/crypto v0.36.0
2424
)
2525

2626
require (
@@ -50,10 +50,10 @@ require (
5050
github.com/vmihailenco/msgpack/v5 v5.4.1 // indirect
5151
github.com/vmihailenco/tagparser/v2 v2.0.0 // indirect
5252
golang.org/x/mod v0.22.0 // indirect
53-
golang.org/x/net v0.34.0 // indirect
54-
golang.org/x/sync v0.11.0 // indirect
55-
golang.org/x/sys v0.30.0 // indirect
56-
golang.org/x/text v0.22.0 // indirect
53+
golang.org/x/net v0.37.0 // indirect
54+
golang.org/x/sync v0.12.0 // indirect
55+
golang.org/x/sys v0.31.0 // indirect
56+
golang.org/x/text v0.23.0 // indirect
5757
golang.org/x/tools v0.21.1-0.20240508182429-e35e4ccd0d2d // indirect
5858
google.golang.org/appengine v1.6.8 // indirect
5959
google.golang.org/genproto/googleapis/rpc v0.0.0-20241015192408-796eee8c2d53 // indirect

go.sum

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ github.com/hashicorp/go-checkpoint v0.5.0/go.mod h1:7nfLNL10NsxqO4iWuW6tWW0HjZuD
5555
github.com/hashicorp/go-cleanhttp v0.5.0/go.mod h1:JpRdi6/HCYpAwUzNwuwqhbovhLtngrth3wmdIIUrZ80=
5656
github.com/hashicorp/go-cleanhttp v0.5.2 h1:035FKYIWjmULyFRBKPs8TBQoi0x6d9G4xc9neXJWAZQ=
5757
github.com/hashicorp/go-cleanhttp v0.5.2/go.mod h1:kO/YDlP8L1346E6Sodw+PrpBSV4/SoxCXGY6BqNFT48=
58-
github.com/hashicorp/go-cty v1.4.1 h1:T4i4kbEKuyMoe4Ujh52Ud07VXr05dnP/Si9JiVDpx3Y=
59-
github.com/hashicorp/go-cty v1.4.1/go.mod h1:EiZBMaudVLy8fmjf9Npq1dq9RalhveqZG5w/yz3mHWs=
58+
github.com/hashicorp/go-cty v1.5.0 h1:EkQ/v+dDNUqnuVpmS5fPqyY71NXVgT5gf32+57xY8g0=
59+
github.com/hashicorp/go-cty v1.5.0/go.mod h1:lFUCG5kd8exDobgSfyj4ONE/dc822kiYMguVKdHGMLM=
6060
github.com/hashicorp/go-hclog v1.6.3 h1:Qr2kF+eVWjTiYmU7Y31tYlP1h0q/X3Nl3tPGdaB11/k=
6161
github.com/hashicorp/go-hclog v1.6.3/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M=
6262
github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo=
@@ -162,22 +162,22 @@ go.opentelemetry.io/otel/trace v1.31.0 h1:ffjsj1aRouKewfr85U2aGagJ46+MvodynlQ1HY
162162
go.opentelemetry.io/otel/trace v1.31.0/go.mod h1:TXZkRk7SM2ZQLtR6eoAWQFIHPvzQ06FJAsO1tJg480A=
163163
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
164164
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
165-
golang.org/x/crypto v0.33.0 h1:IOBPskki6Lysi0lo9qQvbxiQ+FvsCC/YWOecCHAixus=
166-
golang.org/x/crypto v0.33.0/go.mod h1:bVdXmD7IV/4GdElGPozy6U7lWdRXA4qyRVGJV57uQ5M=
165+
golang.org/x/crypto v0.36.0 h1:AnAEvhDddvBdpY+uR+MyHmuZzzNqXSe/GvuDeob5L34=
166+
golang.org/x/crypto v0.36.0/go.mod h1:Y4J0ReaxCR1IMaabaSMugxJES1EpwhBHhv2bDHklZvc=
167167
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
168168
golang.org/x/mod v0.22.0 h1:D4nJWe9zXqHOmWqj4VMOJhvzj7bEZg4wEYa759z1pH4=
169169
golang.org/x/mod v0.22.0/go.mod h1:6SkKJ3Xj0I0BrPOZoBy3bdMptDDU9oJrpohJ3eWZ1fY=
170170
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
171171
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
172172
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
173173
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
174-
golang.org/x/net v0.34.0 h1:Mb7Mrk043xzHgnRM88suvJFwzVrRfHEHJEl5/71CKw0=
175-
golang.org/x/net v0.34.0/go.mod h1:di0qlW3YNM5oh6GqDGQr92MyTozJPmybPK4Ev/Gm31k=
174+
golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c=
175+
golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8=
176176
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
177177
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
178178
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
179-
golang.org/x/sync v0.11.0 h1:GGz8+XQP4FvTTrjZPzNKTMFtSXH80RAzG+5ghFPgK9w=
180-
golang.org/x/sync v0.11.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
179+
golang.org/x/sync v0.12.0 h1:MHc5BpPuC30uJk597Ri8TV3CNZcTLu6B6z4lJy+g6Jw=
180+
golang.org/x/sync v0.12.0/go.mod h1:1dzgHSNfp02xaA81J2MS99Qcpr2w7fw1gpm99rleRqA=
181181
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
182182
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
183183
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
@@ -190,19 +190,18 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc
190190
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
191191
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
192192
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
193-
golang.org/x/sys v0.30.0 h1:QjkSwP/36a20jFYWkSue1YwXzLmsV5Gfq7Eiy72C1uc=
194-
golang.org/x/sys v0.30.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
193+
golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik=
194+
golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
195195
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
196196
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
197-
golang.org/x/term v0.29.0 h1:L6pJp37ocefwRRtYPKSWOWzOtWSxVajvz2ldH/xi3iU=
198-
golang.org/x/term v0.29.0/go.mod h1:6bl4lRlvVuDgSf3179VpIxBF0o10JUpXWOnI7nErv7s=
197+
golang.org/x/term v0.30.0 h1:PQ39fJZ+mfadBm0y5WlL4vlM7Sx1Hgf13sMIY2+QS9Y=
198+
golang.org/x/term v0.30.0/go.mod h1:NYYFdzHoI5wRh/h5tDMdMqCqPJZEuNqVR5xJLd/n67g=
199199
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
200-
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
201200
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
202201
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
203202
golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ=
204-
golang.org/x/text v0.22.0 h1:bofq7m3/HAFvbF51jz3Q9wLg3jkvSPuiZu/pD1XwgtM=
205-
golang.org/x/text v0.22.0/go.mod h1:YRoo4H8PVmsu+E3Ou7cqLVH8oXWIHVoX0jqUWALQhfY=
203+
golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY=
204+
golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4=
206205
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
207206
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
208207
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=

knownvalue/bool_func.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package knownvalue
5+
6+
import "fmt"
7+
8+
var _ Check = boolFunc{}
9+
10+
type boolFunc struct {
11+
checkFunc func(v bool) error
12+
}
13+
14+
// CheckValue determines whether the passed value is of type bool, and
15+
// returns no error from the provided check function
16+
func (v boolFunc) CheckValue(other any) error {
17+
val, ok := other.(bool)
18+
19+
if !ok {
20+
return fmt.Errorf("expected bool value for BoolFunc check, got: %T", other)
21+
}
22+
23+
return v.checkFunc(val)
24+
}
25+
26+
// String returns the bool representation of the value.
27+
func (v boolFunc) String() string {
28+
// Validation is up the the implementer of the function, so there are no
29+
// bool literal or regex comparers to print here
30+
return "BoolFunc"
31+
}
32+
33+
// BoolFunc returns a Check for passing the bool value in state
34+
// to the provided check function
35+
func BoolFunc(fn func(v bool) error) boolFunc {
36+
return boolFunc{
37+
checkFunc: fn,
38+
}
39+
}

knownvalue/bool_func_test.go

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package knownvalue_test
5+
6+
import (
7+
"encoding/json"
8+
"fmt"
9+
"testing"
10+
11+
"github.com/google/go-cmp/cmp"
12+
13+
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
14+
)
15+
16+
func TestBoolFunc_CheckValue(t *testing.T) {
17+
t.Parallel()
18+
19+
testCases := map[string]struct {
20+
self knownvalue.Check
21+
other any
22+
expectedError error
23+
}{
24+
"nil": {
25+
self: knownvalue.BoolFunc(func(bool) error { return nil }),
26+
expectedError: fmt.Errorf("expected bool value for BoolFunc check, got: <nil>"),
27+
},
28+
"wrong-type": {
29+
self: knownvalue.BoolFunc(func(bool) error { return nil }),
30+
other: json.Number("1.234"),
31+
expectedError: fmt.Errorf("expected bool value for BoolFunc check, got: json.Number"),
32+
},
33+
"failure": {
34+
self: knownvalue.BoolFunc(func(b bool) error {
35+
if b != true {
36+
return fmt.Errorf("%t was not true", b)
37+
}
38+
return nil
39+
}),
40+
other: false,
41+
expectedError: fmt.Errorf("%t was not true", false),
42+
},
43+
"success": {
44+
self: knownvalue.BoolFunc(func(b bool) error {
45+
if b != true {
46+
return fmt.Errorf("%t was not foo", b)
47+
}
48+
return nil
49+
}),
50+
other: true,
51+
},
52+
}
53+
54+
for name, testCase := range testCases {
55+
t.Run(name, func(t *testing.T) {
56+
t.Parallel()
57+
58+
got := testCase.self.CheckValue(testCase.other)
59+
60+
if diff := cmp.Diff(got, testCase.expectedError, equateErrorMessage); diff != "" {
61+
t.Errorf("unexpected difference: %s", diff)
62+
}
63+
})
64+
}
65+
}
66+
67+
func TestBoolFunc_String(t *testing.T) {
68+
t.Parallel()
69+
70+
got := knownvalue.BoolFunc(func(bool) error { return nil }).String()
71+
72+
if diff := cmp.Diff(got, "BoolFunc"); diff != "" {
73+
t.Errorf("unexpected difference: %s", diff)
74+
}
75+
}

knownvalue/float32_func.go

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package knownvalue
5+
6+
import (
7+
"encoding/json"
8+
"fmt"
9+
"strconv"
10+
)
11+
12+
var _ Check = float32Func{}
13+
14+
type float32Func struct {
15+
checkFunc func(v float32) error
16+
}
17+
18+
// CheckValue determines whether the passed value is of type float32, and
19+
// returns no error from the provided check function
20+
func (v float32Func) CheckValue(other any) error {
21+
jsonNum, ok := other.(json.Number)
22+
23+
if !ok {
24+
return fmt.Errorf("expected json.Number value for Float32Func check, got: %T", other)
25+
}
26+
27+
otherVal, err := strconv.ParseFloat(string(jsonNum), 32)
28+
if err != nil {
29+
return fmt.Errorf("expected json.Number to be parseable as float32 value for Float32Func check: %s", err)
30+
}
31+
32+
return v.checkFunc(float32(otherVal))
33+
}
34+
35+
// String returns the float32 representation of the value.
36+
func (v float32Func) String() string {
37+
// Validation is up the the implementer of the function, so there are no
38+
// float32 literal or regex comparers to print here
39+
return "Float32Func"
40+
}
41+
42+
// Float32Func returns a Check for passing the float32 value in state
43+
// to the provided check function
44+
func Float32Func(fn func(v float32) error) float32Func {
45+
return float32Func{
46+
checkFunc: fn,
47+
}
48+
}

0 commit comments

Comments
 (0)