Skip to content

Commit

Permalink
helper/resource: Deprecate module-based TestCheckFunc (#109)
Browse files Browse the repository at this point in the history
Reference: #98
  • Loading branch information
bflad authored Mar 22, 2023
1 parent 31836a5 commit 3c3189e
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
9 changes: 9 additions & 0 deletions .changes/unreleased/NOTES-20230322-104531.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
kind: NOTES
body: 'helper/resource: Deprecated Terraform module-based `TestCheckFunc`, such
as `TestCheckModuleResourceAttr`. Provider testing should always be possible
within the root module of a Terraform configuration. Terraform module testing
should be performed with Terraform core functionality or using tooling
outside this Go module.'
time: 2023-03-22T10:45:31.410428-04:00
custom:
Issue: "109"
48 changes: 48 additions & 0 deletions helper/resource/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -951,6 +951,14 @@ func TestCheckResourceAttrSet(name, key string) TestCheckFunc {

// TestCheckModuleResourceAttrSet - as per TestCheckResourceAttrSet but with
// support for non-root modules
//
// Deprecated: This functionality is deprecated without replacement. The
// terraform-plugin-testing Go module is intended for provider testing, which
// should always be possible within the root module of a configuration. This
// functionality is a carryover of when this code was used within Terraform
// core to test both providers and modules. Modern testing implementations to
// verify interactions between modules should be tested in Terraform core or
// using tooling outside this Go module.
func TestCheckModuleResourceAttrSet(mp []string, name string, key string) TestCheckFunc {
mpt := addrs.Module(mp).UnkeyedInstanceShim()
return checkIfIndexesIntoTypeSet(key, func(s *terraform.State) error {
Expand Down Expand Up @@ -1042,6 +1050,14 @@ func TestCheckResourceAttr(name, key, value string) TestCheckFunc {

// TestCheckModuleResourceAttr - as per TestCheckResourceAttr but with
// support for non-root modules
//
// Deprecated: This functionality is deprecated without replacement. The
// terraform-plugin-testing Go module is intended for provider testing, which
// should always be possible within the root module of a configuration. This
// functionality is a carryover of when this code was used within Terraform
// core to test both providers and modules. Modern testing implementations to
// verify interactions between modules should be tested in Terraform core or
// using tooling outside this Go module.
func TestCheckModuleResourceAttr(mp []string, name string, key string, value string) TestCheckFunc {
mpt := addrs.Module(mp).UnkeyedInstanceShim()
return checkIfIndexesIntoTypeSet(key, func(s *terraform.State) error {
Expand Down Expand Up @@ -1206,6 +1222,14 @@ func TestCheckNoResourceAttr(name, key string) TestCheckFunc {

// TestCheckModuleNoResourceAttr - as per TestCheckNoResourceAttr but with
// support for non-root modules
//
// Deprecated: This functionality is deprecated without replacement. The
// terraform-plugin-testing Go module is intended for provider testing, which
// should always be possible within the root module of a configuration. This
// functionality is a carryover of when this code was used within Terraform
// core to test both providers and modules. Modern testing implementations to
// verify interactions between modules should be tested in Terraform core or
// using tooling outside this Go module.
func TestCheckModuleNoResourceAttr(mp []string, name string, key string) TestCheckFunc {
mpt := addrs.Module(mp).UnkeyedInstanceShim()
return checkIfIndexesIntoTypeSet(key, func(s *terraform.State) error {
Expand Down Expand Up @@ -1302,6 +1326,14 @@ func TestMatchResourceAttr(name, key string, r *regexp.Regexp) TestCheckFunc {

// TestModuleMatchResourceAttr - as per TestMatchResourceAttr but with
// support for non-root modules
//
// Deprecated: This functionality is deprecated without replacement. The
// terraform-plugin-testing Go module is intended for provider testing, which
// should always be possible within the root module of a configuration. This
// functionality is a carryover of when this code was used within Terraform
// core to test both providers and modules. Modern testing implementations to
// verify interactions between modules should be tested in Terraform core or
// using tooling outside this Go module.
func TestModuleMatchResourceAttr(mp []string, name string, key string, r *regexp.Regexp) TestCheckFunc {
mpt := addrs.Module(mp).UnkeyedInstanceShim()
return checkIfIndexesIntoTypeSet(key, func(s *terraform.State) error {
Expand Down Expand Up @@ -1341,6 +1373,14 @@ func TestCheckResourceAttrPtr(name string, key string, value *string) TestCheckF

// TestCheckModuleResourceAttrPtr - as per TestCheckResourceAttrPtr but with
// support for non-root modules
//
// Deprecated: This functionality is deprecated without replacement. The
// terraform-plugin-testing Go module is intended for provider testing, which
// should always be possible within the root module of a configuration. This
// functionality is a carryover of when this code was used within Terraform
// core to test both providers and modules. Modern testing implementations to
// verify interactions between modules should be tested in Terraform core or
// using tooling outside this Go module.
func TestCheckModuleResourceAttrPtr(mp []string, name string, key string, value *string) TestCheckFunc {
return func(s *terraform.State) error {
return TestCheckModuleResourceAttr(mp, name, key, *value)(s)
Expand Down Expand Up @@ -1398,6 +1438,14 @@ func TestCheckResourceAttrPair(nameFirst, keyFirst, nameSecond, keySecond string

// TestCheckModuleResourceAttrPair - as per TestCheckResourceAttrPair but with
// support for non-root modules
//
// Deprecated: This functionality is deprecated without replacement. The
// terraform-plugin-testing Go module is intended for provider testing, which
// should always be possible within the root module of a configuration. This
// functionality is a carryover of when this code was used within Terraform
// core to test both providers and modules. Modern testing implementations to
// verify interactions between modules should be tested in Terraform core or
// using tooling outside this Go module.
func TestCheckModuleResourceAttrPair(mpFirst []string, nameFirst string, keyFirst string, mpSecond []string, nameSecond string, keySecond string) TestCheckFunc {
mptFirst := addrs.Module(mpFirst).UnkeyedInstanceShim()
mptSecond := addrs.Module(mpSecond).UnkeyedInstanceShim()
Expand Down

0 comments on commit 3c3189e

Please sign in to comment.