When using terraform provider, and migrating it to use both the sdk v2 and plugin framework, I am running into
flag redefined: sweep
flag redefined: sweep
goroutine 1 [running]:
flag.(*FlagSet).Var(0x140001b0150, {0x108844438, 0x140007faf10}, {0x106cb8bd7, 0x5}, {0x106daffff, 0x29})
sdk/go1.22.5/src/flag/flag.go:1028 +0x2cc
flag.(*FlagSet).StringVar(...)
sdk/go1.22.5/src/flag/flag.go:879
flag.(*FlagSet).String(0x140001b0150, {0x106cb8bd7, 0x5}, {0x0, 0x0}, {0x106daffff, 0x29})
sdk/go1.22.5/src/flag/flag.go:892 +0x98
flag.String(...)
sdk/go1.22.5/src/flag/flag.go:899
github.com/hashicorp/terraform-plugin-testing/helper/resource.init()
go/pkg/mod/github.com/hashicorp/terraform-plugin-testing@v1.3.0/helper/resource/testing.go:55 +0x44
I followed the guidelines on this,still I the error persists
Hey there @ramuklawjju , without seeing the source code I can’t offer any specific guidance on what to adjust, but there is a very similar bug report here:
opened 02:48AM - 09 Mar 23 UTC
closed 03:07PM - 22 Mar 23 UTC
bug
### terraform-plugin-testing version
```
$ go list -m github.com/hashicorp… /terraform-plugin-testing/...
github.com/hashicorp/terraform-plugin-testing v1.1.0
```
### Relevant provider source code
```go
// n/a
```
### Terraform Configuration Files
```tf
// n/a
```
### Expected Behavior
```
$ make test
go test -i $(go list ./...) || exit 1
? github.com/cloudflare/terraform-provider-cloudflare [no test files]
echo $(go list ./...) | \
xargs -t -n4 go test -timeout=30s -parallel=4
go test -timeout=30s -parallel=4 github.com/cloudflare/terraform-provider-cloudflare github.com/cloudflare/terraform-provider-cloudflare/internal/consts github.com/cloudflare/terraform-provider-cloudflare/internal/framework/modifiers/defaults github.com/cloudflare/terraform-provider-cloudflare/internal/framework/provider
? github.com/cloudflare/terraform-provider-cloudflare [no test files]
? github.com/cloudflare/terraform-provider-cloudflare/internal/consts [no test files]
? github.com/cloudflare/terraform-provider-cloudflare/internal/framework/modifiers/defaults [no test files]
ok github.com/cloudflare/terraform-provider-cloudflare/internal/framework/provider 1.282s [no tests to run]
go test -timeout=30s -parallel=4 github.com/cloudflare/terraform-provider-cloudflare/internal/framework/service/example github.com/cloudflare/terraform-provider-cloudflare/internal/sdkv2provider github.com/cloudflare/terraform-provider-cloudflare/internal/utils
ok github.com/cloudflare/terraform-provider-cloudflare/internal/framework/service/example 1.049s [no tests to run]
? github.com/cloudflare/terraform-provider-cloudflare/internal/utils [no test files]
ok github.com/cloudflare/terraform-provider-cloudflare/internal/sdkv2provider 0.942s
```
This is reproducible by checking out the `master` branch that has not migrated to the terraform-plugin-testing repository and still uses the SDKv2 references.
### Actual Behavior
```
$ make test
go test -i $(go list ./...) || exit 1
? github.com/cloudflare/terraform-provider-cloudflare [no test files]
echo $(go list ./...) | \
xargs -t -n4 go test -timeout=30s -parallel=4
go test -timeout=30s -parallel=4 github.com/cloudflare/terraform-provider-cloudflare github.com/cloudflare/terraform-provider-cloudflare/internal/consts github.com/cloudflare/terraform-provider-cloudflare/internal/framework/modifiers/defaults github.com/cloudflare/terraform-provider-cloudflare/internal/framework/provider
? github.com/cloudflare/terraform-provider-cloudflare [no test files]
? github.com/cloudflare/terraform-provider-cloudflare/internal/consts [no test files]
? github.com/cloudflare/terraform-provider-cloudflare/internal/framework/modifiers/defaults [no test files]
ok github.com/cloudflare/terraform-provider-cloudflare/internal/framework/provider (cached) [no tests to run]
go test -timeout=30s -parallel=4 github.com/cloudflare/terraform-provider-cloudflare/internal/framework/service/example github.com/cloudflare/terraform-provider-cloudflare/internal/sdkv2provider github.com/cloudflare/terraform-provider-cloudflare/internal/utils
ok github.com/cloudflare/terraform-provider-cloudflare/internal/framework/service/example (cached) [no tests to run]
? github.com/cloudflare/terraform-provider-cloudflare/internal/utils [no test files]
/var/folders/36/zlscnhfn27n1yxx52cr1kdmr0000gp/T/go-build1935981002/b191/sdkv2provider.test flag redefined: sweep
panic: /var/folders/36/zlscnhfn27n1yxx52cr1kdmr0000gp/T/go-build1935981002/b191/sdkv2provider.test flag redefined: sweep
goroutine 1 [running]:
flag.(*FlagSet).Var(0xc0000a2180, {0x1f4c920, 0xc0001d3960}, {0x1d60fcd, 0x5}, {0x1d99c6b, 0x29})
/Users/jacob/.asdf/installs/golang/1.20.1/go/src/flag/flag.go:982 +0x2f9
flag.(*FlagSet).StringVar(...)
/Users/jacob/.asdf/installs/golang/1.20.1/go/src/flag/flag.go:847
flag.(*FlagSet).String(0x18938b1?, {0x1d60fcd, 0x5}, {0x0, 0x0}, {0x1d99c6b, 0x29})
/Users/jacob/.asdf/installs/golang/1.20.1/go/src/flag/flag.go:860 +0xac
flag.String(...)
/Users/jacob/.asdf/installs/golang/1.20.1/go/src/flag/flag.go:867
github.com/hashicorp/terraform-plugin-testing/helper/resource.init()
/Users/jacob/.asdf/installs/golang/1.20.1/packages/pkg/mod/github.com/hashicorp/terraform-plugin-testing@v1.1.0/helper/resource/testing.go:53 +0x45
FAIL github.com/cloudflare/terraform-provider-cloudflare/internal/sdkv2provider 0.880s
FAIL
make: *** [test] Error 1
```
### Steps to Reproduce
1. Checkout https://github.com/cloudflare/terraform-provider-cloudflare/pull/2272
2. Run `make test`
### References
I'm not seeing any differences between sdkv2 (https://github.com/hashicorp/terraform-plugin-sdk/blob/main/helper/resource/testing.go#L48) and this repository (https://github.com/hashicorp/terraform-plugin-testing/blob/main/helper/resource/testing.go#L53) that would be causing this. I suspect it may be a bug in either my find and replace that was done as part of the migration or a bug in our existing test suite that we are now privvy to but would love some guidance on where to start with this one.
I've tried running this one through git bisect to see where it's falling apart but the cross repository interactions and merging is making it a little tough without more understanding of where I should focus my effort.
It’s possible that there are still some lingering github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource
references in your code base, as the error message suggests that there are two imports defining the sweep flag , specifically:
Old: github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource
New: github.com/hashicorp/terraform-plugin-testing/helper/resource
In the past, the migration guide only mentioned _test.go
files that needed to change, but now there are .go
files that need to change as well (mentioned in that migration steps section you linked), some of them don’t reference the resource
package anymore and have new package names like retry
and id
1 Like