From 3e8264a506b2d2c044851c12bd46a708f3c1e0fa Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Wed, 22 Mar 2023 10:50:22 -0400 Subject: [PATCH] helper/resource: Deprecate module-based TestCheckFunc Reference: https://github.com/hashicorp/terraform-plugin-testing/issues/98 --- .../unreleased/NOTES-20230322-104531.yaml | 9 ++++ helper/resource/testing.go | 48 +++++++++++++++++++ 2 files changed, 57 insertions(+) create mode 100644 .changes/unreleased/NOTES-20230322-104531.yaml diff --git a/.changes/unreleased/NOTES-20230322-104531.yaml b/.changes/unreleased/NOTES-20230322-104531.yaml new file mode 100644 index 000000000..570022b2c --- /dev/null +++ b/.changes/unreleased/NOTES-20230322-104531.yaml @@ -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: "98" diff --git a/helper/resource/testing.go b/helper/resource/testing.go index 0d479d8d6..9d5def3c3 100644 --- a/helper/resource/testing.go +++ b/helper/resource/testing.go @@ -914,6 +914,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 { @@ -1005,6 +1013,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 { @@ -1169,6 +1185,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 { @@ -1265,6 +1289,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 { @@ -1304,6 +1336,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) @@ -1361,6 +1401,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()