diff --git a/internal/configs/config.go b/internal/configs/config.go index f9cef3eb68..7dff76a095 100644 --- a/internal/configs/config.go +++ b/internal/configs/config.go @@ -234,23 +234,6 @@ func (c *Config) TargetExists(target addrs.Targetable) bool { } } -// EntersNewPackage returns true if this call is to an external module, either -// directly via a remote source address or indirectly via a registry source -// address. -// -// Other behaviors in Terraform may treat package crossings as a special -// situation, because that indicates that the caller and callee can change -// independently of one another and thus we should disallow using any features -// where the caller assumes anything about the callee other than its input -// variables, required provider configurations, and output values. -// -// It's not meaningful to ask if the Config representing the root module enters -// a new package because the root module is always outside of all module -// packages, and so this function will arbitrarily return false in that case. -func (c *Config) EntersNewPackage() bool { - return moduleSourceAddrEntersNewPackage(c.SourceAddr) -} - // VerifyDependencySelections checks whether the given locked dependencies // are acceptable for all of the version constraints reported in the // configuration tree represented by the reciever. diff --git a/internal/configs/module_call.go b/internal/configs/module_call.go index ecc3be1821..ff7c7417f8 100644 --- a/internal/configs/module_call.go +++ b/internal/configs/module_call.go @@ -227,19 +227,6 @@ func decodeModuleBlock(block *hcl.Block, override bool) (*ModuleCall, hcl.Diagno return mc, diags } -// EntersNewPackage returns true if this call is to an external module, either -// directly via a remote source address or indirectly via a registry source -// address. -// -// Other behaviors in Terraform may treat package crossings as a special -// situation, because that indicates that the caller and callee can change -// independently of one another and thus we should disallow using any features -// where the caller assumes anything about the callee other than its input -// variables, required provider configurations, and output values. -func (mc *ModuleCall) EntersNewPackage() bool { - return moduleSourceAddrEntersNewPackage(mc.SourceAddr) -} - // PassedProviderConfig represents a provider config explicitly passed down to // a child module, possibly giving it a new local address in the process. type PassedProviderConfig struct { @@ -318,27 +305,3 @@ var moduleBlockSchema = &hcl.BodySchema{ {Type: "provider", LabelNames: []string{"type"}}, }, } - -func moduleSourceAddrEntersNewPackage(addr addrs.ModuleSource) bool { - switch addr.(type) { - case nil: - // There are only two situations where we should get here: - // - We've been asked about the source address of the root module, - // which is always nil. - // - We've been asked about a ModuleCall that is part of the partial - // result of a failed decode. - // The root module exists outside of all module packages, so we'll - // just return false for that case. For the error case it doesn't - // really matter what we return as long as we don't panic, because - // we only make a best-effort to allow careful inspection of objects - // representing invalid configuration. - return false - case addrs.ModuleSourceLocal: - // Local source addresses are the only address type that remains within - // the same package. - return false - default: - // All other address types enter a new package. - return true - } -} diff --git a/internal/configs/module_call_test.go b/internal/configs/module_call_test.go index 5f64f65506..058024f856 100644 --- a/internal/configs/module_call_test.go +++ b/internal/configs/module_call_test.go @@ -4,18 +4,17 @@ package configs import ( - "io/ioutil" + "os" "testing" "github.com/go-test/deep" "github.com/hashicorp/hcl/v2" "github.com/hashicorp/terraform/internal/addrs" - "github.com/hashicorp/terraform/internal/getmodules/moduleaddrs" ) func TestLoadModuleCall(t *testing.T) { - src, err := ioutil.ReadFile("testdata/invalid-files/module-calls.tf") + src, err := os.ReadFile("testdata/invalid-files/module-calls.tf") if err != nil { t.Fatal(err) } @@ -149,49 +148,3 @@ func TestLoadModuleCall(t *testing.T) { t.Error(problem) } } - -func TestModuleSourceAddrEntersNewPackage(t *testing.T) { - tests := []struct { - Addr string - Want bool - }{ - { - "./", - false, - }, - { - "../bork", - false, - }, - { - "/absolute/path", - true, - }, - { - "github.com/example/foo", - true, - }, - { - "hashicorp/subnets/cidr", // registry module - true, - }, - { - "registry.terraform.io/hashicorp/subnets/cidr", // registry module - true, - }, - } - - for _, test := range tests { - t.Run(test.Addr, func(t *testing.T) { - addr, err := moduleaddrs.ParseModuleSource(test.Addr) - if err != nil { - t.Fatalf("parsing failed for %q: %s", test.Addr, err) - } - - got := moduleSourceAddrEntersNewPackage(addr) - if got != test.Want { - t.Errorf("wrong result for %q\ngot: %#v\nwant: %#v", addr, got, test.Want) - } - }) - } -}