From fae5f9958d2e18877d61c207cea9f2875ebbebef Mon Sep 17 00:00:00 2001 From: James Bardin Date: Mon, 9 Mar 2020 15:43:56 -0400 Subject: [PATCH 1/4] remove GraphNodeModuleInstance from Resource types Remove the requirement for most *Resource types to be a GraphNodeModuleInstance, ensuring that they never call ctx.Path while being evaluated. This gets rid of most of the direct need for the Path method currently implemented by NodeResourceAbstract, leaving the provider and schema related calls for a subsequent PR. --- terraform/eval_state.go | 12 ++++++------ terraform/node_data_refresh.go | 24 ++++++++++++++---------- terraform/node_resource_abstract.go | 10 ++++++++-- terraform/node_resource_apply.go | 15 ++++++--------- terraform/node_resource_destroy.go | 6 +----- terraform/node_resource_plan.go | 13 +++++-------- terraform/node_resource_refresh.go | 8 +++----- terraform/node_resource_validate.go | 1 - 8 files changed, 43 insertions(+), 46 deletions(-) diff --git a/terraform/eval_state.go b/terraform/eval_state.go index ab55835e2..ccf63d1e4 100644 --- a/terraform/eval_state.go +++ b/terraform/eval_state.go @@ -453,6 +453,7 @@ func (n *EvalMaybeRestoreDeposedObject) Eval(ctx EvalContext) (interface{}, erro // list rather than as not set at all. type EvalWriteResourceState struct { Addr addrs.Resource + Module addrs.Module Config *configs.Resource ProviderAddr addrs.AbsProviderConfig } @@ -460,7 +461,6 @@ type EvalWriteResourceState struct { // TODO: test func (n *EvalWriteResourceState) Eval(ctx EvalContext) (interface{}, error) { var diags tfdiags.Diagnostics - absAddr := n.Addr.Absolute(ctx.Path()) state := ctx.State() count, countDiags := evaluateResourceCountExpression(n.Config.Count, ctx) @@ -484,16 +484,16 @@ func (n *EvalWriteResourceState) Eval(ctx EvalContext) (interface{}, error) { eachMode = states.EachMap } - // This method takes care of all of the business logic of updating this - // while ensuring that any existing instances are preserved, etc. - state.SetResourceMeta(absAddr, eachMode, n.ProviderAddr) - // We'll record our expansion decision in the shared "expander" object // so that later operations (i.e. DynamicExpand and expression evaluation) // can refer to it. Since this node represents the abstract module, we need // to expand the module here to create all resources. expander := ctx.InstanceExpander() - for _, module := range expander.ExpandModule(ctx.Path().Module()) { + for _, module := range expander.ExpandModule(n.Module) { + // This method takes care of all of the business logic of updating this + // while ensuring that any existing instances are preserved, etc. + state.SetResourceMeta(n.Addr.Absolute(module), eachMode, n.ProviderAddr) + switch eachMode { case states.EachList: expander.SetResourceCount(module, n.Addr, count) diff --git a/terraform/node_data_refresh.go b/terraform/node_data_refresh.go index dd0b43352..4e2460745 100644 --- a/terraform/node_data_refresh.go +++ b/terraform/node_data_refresh.go @@ -1,6 +1,7 @@ package terraform import ( + "github.com/hashicorp/terraform/addrs" "github.com/hashicorp/terraform/dag" "github.com/hashicorp/terraform/plans" "github.com/hashicorp/terraform/providers" @@ -15,7 +16,6 @@ type NodeRefreshableDataResource struct { } var ( - _ GraphNodeModuleInstance = (*NodeRefreshableDataResource)(nil) _ GraphNodeDynamicExpandable = (*NodeRefreshableDataResource)(nil) _ GraphNodeReferenceable = (*NodeRefreshableDataResource)(nil) _ GraphNodeReferencer = (*NodeRefreshableDataResource)(nil) @@ -54,18 +54,22 @@ func (n *NodeRefreshableDataResource) DynamicExpand(ctx EvalContext) (*Graph, er // if we're transitioning whether "count" is set at all. fixResourceCountSetTransition(ctx, n.ResourceAddr(), count != -1) + var instanceAddrs []addrs.AbsResourceInstance + // Inform our instance expander about our expansion results above, // and then use it to calculate the instance addresses we'll expand for. expander := ctx.InstanceExpander() - switch { - case count >= 0: - expander.SetResourceCount(ctx.Path(), n.ResourceAddr().Resource, count) - case forEachMap != nil: - expander.SetResourceForEach(ctx.Path(), n.ResourceAddr().Resource, forEachMap) - default: - expander.SetResourceSingle(ctx.Path(), n.ResourceAddr().Resource) + for _, path := range expander.ExpandModule(n.Module) { + switch { + case count >= 0: + expander.SetResourceCount(path, n.ResourceAddr().Resource, count) + case forEachMap != nil: + expander.SetResourceForEach(path, n.ResourceAddr().Resource, forEachMap) + default: + expander.SetResourceSingle(path, n.ResourceAddr().Resource) + } + instanceAddrs = append(instanceAddrs, expander.ExpandResource(path.Module(), n.ResourceAddr().Resource)...) } - instanceAddrs := expander.ExpandResource(ctx.Path().Module(), n.ResourceAddr().Resource) // Our graph transformers require access to the full state, so we'll // temporarily lock it while we work on this. @@ -135,7 +139,7 @@ func (n *NodeRefreshableDataResource) DynamicExpand(ctx EvalContext) (*Graph, er Name: "NodeRefreshableDataResource", } - graph, diags := b.Build(ctx.Path()) + graph, diags := b.Build(nil) return graph, diags.ErrWithWarnings() } diff --git a/terraform/node_resource_abstract.go b/terraform/node_resource_abstract.go index d67bd5953..687fa0f1a 100644 --- a/terraform/node_resource_abstract.go +++ b/terraform/node_resource_abstract.go @@ -99,7 +99,8 @@ func NewNodeAbstractResource(addr addrs.AbsResource) *NodeAbstractResource { // the "count" or "for_each" arguments. type NodeAbstractResourceInstance struct { NodeAbstractResource - InstanceKey addrs.InstanceKey + ModuleInstance addrs.ModuleInstance + InstanceKey addrs.InstanceKey // The fields below will be automatically set using the Attach // interfaces if you're running those transforms, but also be explicitly @@ -138,7 +139,8 @@ func NewNodeAbstractResourceInstance(addr addrs.AbsResourceInstance) *NodeAbstra Addr: addr.Resource.Resource, Module: addr.Module.Module(), }, - InstanceKey: addr.Resource.Key, + ModuleInstance: addr.Module, + InstanceKey: addr.Resource.Key, } } @@ -155,6 +157,10 @@ func (n *NodeAbstractResource) Path() addrs.ModuleInstance { return n.Module.UnkeyedInstanceShim() } +func (n *NodeAbstractResourceInstance) Path() addrs.ModuleInstance { + return n.ModuleInstance +} + // GraphNodeModulePath func (n *NodeAbstractResource) ModulePath() addrs.Module { return n.Module diff --git a/terraform/node_resource_apply.go b/terraform/node_resource_apply.go index 3e2fff3a0..11aeb338a 100644 --- a/terraform/node_resource_apply.go +++ b/terraform/node_resource_apply.go @@ -53,19 +53,16 @@ func (n *NodeApplyableResource) References() []*addrs.Reference { // GraphNodeEvalable func (n *NodeApplyableResource) EvalTree() EvalNode { - addr := n.ResourceAddr() - config := n.Config - providerAddr := n.ResolvedProvider - - if config == nil { + if n.Config == nil { // Nothing to do, then. - log.Printf("[TRACE] NodeApplyableResource: no configuration present for %s", addr) + log.Printf("[TRACE] NodeApplyableResource: no configuration present for %s", n.Name()) return &EvalNoop{} } return &EvalWriteResourceState{ - Addr: addr.Resource, - Config: config, - ProviderAddr: providerAddr, + Addr: n.Addr, + Module: n.Module, + Config: n.Config, + ProviderAddr: n.ResolvedProvider, } } diff --git a/terraform/node_resource_destroy.go b/terraform/node_resource_destroy.go index ed2bafa69..54fba1dec 100644 --- a/terraform/node_resource_destroy.go +++ b/terraform/node_resource_destroy.go @@ -288,6 +288,7 @@ func (n *NodeDestroyResourceInstance) EvalTree() EvalNode { // all been destroyed. type NodeDestroyResource struct { *NodeAbstractResource + Addr addrs.AbsResource } var ( @@ -342,11 +343,6 @@ func (n *NodeDestroyResource) ResourceAddr() addrs.AbsResource { return n.NodeAbstractResource.ResourceAddr() } -// GraphNodeSubpath -func (n *NodeDestroyResource) Path() addrs.ModuleInstance { - return n.NodeAbstractResource.Path() -} - // GraphNodeNoProvider // FIXME: this should be removed once the node can be separated from the // Internal NodeAbstractResource behavior. diff --git a/terraform/node_resource_plan.go b/terraform/node_resource_plan.go index bd567e052..0455296c8 100644 --- a/terraform/node_resource_plan.go +++ b/terraform/node_resource_plan.go @@ -19,7 +19,6 @@ type NodePlannableResource struct { } var ( - _ GraphNodeModuleInstance = (*NodePlannableResource)(nil) _ GraphNodeDestroyerCBD = (*NodePlannableResource)(nil) _ GraphNodeDynamicExpandable = (*NodePlannableResource)(nil) _ GraphNodeReferenceable = (*NodePlannableResource)(nil) @@ -30,19 +29,17 @@ var ( // GraphNodeEvalable func (n *NodePlannableResource) EvalTree() EvalNode { - addr := n.ResourceAddr() - config := n.Config - - if config == nil { + if n.Config == nil { // Nothing to do, then. - log.Printf("[TRACE] NodeApplyableResource: no configuration present for %s", addr) + log.Printf("[TRACE] NodeApplyableResource: no configuration present for %s", n.Name()) return &EvalNoop{} } // this ensures we can reference the resource even if the count is 0 return &EvalWriteResourceState{ - Addr: addr.Resource, - Config: config, + Addr: n.Addr, + Module: n.Module, + Config: n.Config, ProviderAddr: n.ResolvedProvider, } } diff --git a/terraform/node_resource_refresh.go b/terraform/node_resource_refresh.go index 53fdf2cba..7871918e5 100644 --- a/terraform/node_resource_refresh.go +++ b/terraform/node_resource_refresh.go @@ -25,7 +25,6 @@ type NodeRefreshableManagedResource struct { } var ( - _ GraphNodeModuleInstance = (*NodeRefreshableManagedResource)(nil) _ GraphNodeDynamicExpandable = (*NodeRefreshableManagedResource)(nil) _ GraphNodeReferenceable = (*NodeRefreshableManagedResource)(nil) _ GraphNodeReferencer = (*NodeRefreshableManagedResource)(nil) @@ -61,8 +60,7 @@ func (n *NodeRefreshableManagedResource) DynamicExpand(ctx EvalContext) (*Graph, // Inform our instance expander about our expansion results above, // and then use it to calculate the instance addresses we'll expand for. expander := ctx.InstanceExpander() - - for _, module := range expander.ExpandModule(ctx.Path().Module()) { + for _, module := range expander.ExpandModule(n.Module) { switch { case count >= 0: expander.SetResourceCount(module, n.ResourceAddr().Resource, count) @@ -72,7 +70,7 @@ func (n *NodeRefreshableManagedResource) DynamicExpand(ctx EvalContext) (*Graph, expander.SetResourceSingle(module, n.ResourceAddr().Resource) } } - instanceAddrs := expander.ExpandResource(ctx.Path().Module(), n.ResourceAddr().Resource) + instanceAddrs := expander.ExpandResource(n.Module, n.ResourceAddr().Resource) // Our graph transformers require access to the full state, so we'll // temporarily lock it while we work on this. @@ -131,7 +129,7 @@ func (n *NodeRefreshableManagedResource) DynamicExpand(ctx EvalContext) (*Graph, Name: "NodeRefreshableManagedResource", } - graph, diags := b.Build(ctx.Path()) + graph, diags := b.Build(nil) return graph, diags.ErrWithWarnings() } diff --git a/terraform/node_resource_validate.go b/terraform/node_resource_validate.go index 3703d81ba..f8374f3fb 100644 --- a/terraform/node_resource_validate.go +++ b/terraform/node_resource_validate.go @@ -15,7 +15,6 @@ type NodeValidatableResource struct { } var ( - _ GraphNodeModuleInstance = (*NodeValidatableResource)(nil) _ GraphNodeEvalable = (*NodeValidatableResource)(nil) _ GraphNodeReferenceable = (*NodeValidatableResource)(nil) _ GraphNodeReferencer = (*NodeValidatableResource)(nil) From 8497adcb6e9386f3b494e7d263699bb1ca778558 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Mon, 9 Mar 2020 17:11:57 -0400 Subject: [PATCH 2/4] AbsProviderConfig to use addrs.Module Change ModuleInstance to Module in AbsProviderConfig, because providers need to be handled before module expansion, and should not be used defined inside an expanded module at all. Renaming of the addrs type can happen later, when there's less work in-flight around provider configuration. --- addrs/provider_config.go | 64 ++++++++++++++------- addrs/provider_config_test.go | 83 ++++++---------------------- configs/config.go | 6 +- configs/config_test.go | 12 ++-- states/statefile/version3_upgrade.go | 4 +- 5 files changed, 74 insertions(+), 95 deletions(-) diff --git a/addrs/provider_config.go b/addrs/provider_config.go index aba6afceb..f83ce8d48 100644 --- a/addrs/provider_config.go +++ b/addrs/provider_config.go @@ -2,6 +2,7 @@ package addrs import ( "fmt" + "strings" "github.com/hashicorp/terraform/tfdiags" "github.com/zclconf/go-cty/cty" @@ -86,7 +87,7 @@ func (pc LocalProviderConfig) StringCompact() string { // AbsProviderConfig is the absolute address of a provider configuration // within a particular module instance. type AbsProviderConfig struct { - Module ModuleInstance + Module Module Provider Provider Alias string } @@ -101,7 +102,6 @@ var _ ProviderConfig = AbsProviderConfig{} // provider["registry.terraform.io/hashicorp/aws"].foo // module.bar.provider["registry.terraform.io/hashicorp/aws"] // module.bar.module.baz.provider["registry.terraform.io/hashicorp/aws"].foo -// module.foo[1].provider["registry.terraform.io/hashicorp/aws"].foo // // This type of address is used, for example, to record the relationships // between resources and provider configurations in the state structure. @@ -109,9 +109,23 @@ var _ ProviderConfig = AbsProviderConfig{} // messages that refer to provider configurations. func ParseAbsProviderConfig(traversal hcl.Traversal) (AbsProviderConfig, tfdiags.Diagnostics) { modInst, remain, diags := parseModuleInstancePrefix(traversal) - ret := AbsProviderConfig{ - Module: modInst, + var ret AbsProviderConfig + + // Providers cannot resolve within module instances, so verify that there + // are no instance keys in the module path before converting to a Module. + for _, step := range modInst { + if step.InstanceKey != NoKey { + diags = diags.Append(&hcl.Diagnostic{ + Severity: hcl.DiagError, + Summary: "Invalid provider configuration address", + Detail: "Provider address cannot contain module indexes", + Subject: remain.SourceRange().Ptr(), + }) + return ret, diags + } } + ret.Module = modInst.Module() + if len(remain) < 2 || remain.RootName() != "provider" { diags = diags.Append(&hcl.Diagnostic{ Severity: hcl.DiagError, @@ -223,16 +237,28 @@ func ParseLegacyAbsProviderConfigStr(str string) (AbsProviderConfig, tfdiags.Dia // provider.aws.foo // module.bar.provider.aws // module.bar.module.baz.provider.aws.foo -// module.foo[1].provider.aws.foo // // This type of address is used in legacy state and may appear in state v4 if // the provider config addresses have not been normalized to include provider // FQN. func ParseLegacyAbsProviderConfig(traversal hcl.Traversal) (AbsProviderConfig, tfdiags.Diagnostics) { modInst, remain, diags := parseModuleInstancePrefix(traversal) - ret := AbsProviderConfig{ - Module: modInst, + var ret AbsProviderConfig + + // Providers cannot resolve within module instances, so verify that there + // are no instance keys in the module path before converting to a Module. + for _, step := range modInst { + if step.InstanceKey != NoKey { + diags = diags.Append(&hcl.Diagnostic{ + Severity: hcl.DiagError, + Summary: "Invalid provider configuration address", + Detail: "Provider address cannot contain module indexes", + Subject: remain.SourceRange().Ptr(), + }) + return ret, diags + } } + ret.Module = modInst.Module() if len(remain) < 2 || remain.RootName() != "provider" { diags = diags.Append(&hcl.Diagnostic{ @@ -287,7 +313,7 @@ func ParseLegacyAbsProviderConfig(traversal hcl.Traversal) (AbsProviderConfig, t // the given type inside the recieving module instance. func (m ModuleInstance) ProviderConfigDefault(provider Provider) AbsProviderConfig { return AbsProviderConfig{ - Module: m, + Module: m.Module(), Provider: provider, } } @@ -296,7 +322,7 @@ func (m ModuleInstance) ProviderConfigDefault(provider Provider) AbsProviderConf // the given type and alias inside the recieving module instance. func (m ModuleInstance) ProviderConfigAliased(provider Provider, alias string) AbsProviderConfig { return AbsProviderConfig{ - Module: m, + Module: m.Module(), Provider: provider, Alias: alias, } @@ -359,16 +385,16 @@ func (pc AbsProviderConfig) LegacyString() string { // module.module-name.provider["example.com/namespace/name"] // module.module-name.provider["example.com/namespace/name"].alias func (pc AbsProviderConfig) String() string { - if pc.Alias != "" { - if len(pc.Module) == 0 { - return fmt.Sprintf("%s[%q].%s", "provider", pc.Provider.String(), pc.Alias) - } else { - return fmt.Sprintf("%s.%s[%q].%s", pc.Module.String(), "provider", pc.Provider.String(), pc.Alias) - } - } - if len(pc.Module) == 0 { - return fmt.Sprintf("%s[%q]", "provider", pc.Provider.String()) + var parts []string + if len(pc.Module) > 0 { + parts = append(parts, pc.Module.String()) } - return fmt.Sprintf("%s.%s[%q]", pc.Module.String(), "provider", pc.Provider.String()) + parts = append(parts, fmt.Sprintf("provider[%q]", pc.Provider)) + + if pc.Alias != "" { + parts = append(parts, pc.Alias) + } + + return strings.Join(parts, ".") } diff --git a/addrs/provider_config_test.go b/addrs/provider_config_test.go index a48129e57..deba9e713 100644 --- a/addrs/provider_config_test.go +++ b/addrs/provider_config_test.go @@ -18,7 +18,7 @@ func TestParseAbsProviderConfig(t *testing.T) { { `provider["registry.terraform.io/hashicorp/aws"]`, AbsProviderConfig{ - Module: RootModuleInstance, + Module: RootModule, Provider: Provider{ Type: "aws", Namespace: "hashicorp", @@ -30,7 +30,7 @@ func TestParseAbsProviderConfig(t *testing.T) { { `provider["registry.terraform.io/hashicorp/aws"].foo`, AbsProviderConfig{ - Module: RootModuleInstance, + Module: RootModule, Provider: Provider{ Type: "aws", Namespace: "hashicorp", @@ -43,11 +43,7 @@ func TestParseAbsProviderConfig(t *testing.T) { { `module.baz.provider["registry.terraform.io/hashicorp/aws"]`, AbsProviderConfig{ - Module: ModuleInstance{ - { - Name: "baz", - }, - }, + Module: Module{"baz"}, Provider: Provider{ Type: "aws", Namespace: "hashicorp", @@ -59,11 +55,7 @@ func TestParseAbsProviderConfig(t *testing.T) { { `module.baz.provider["registry.terraform.io/hashicorp/aws"].foo`, AbsProviderConfig{ - Module: ModuleInstance{ - { - Name: "baz", - }, - }, + Module: Module{"baz"}, Provider: Provider{ Type: "aws", Namespace: "hashicorp", @@ -75,57 +67,18 @@ func TestParseAbsProviderConfig(t *testing.T) { }, { `module.baz["foo"].provider["registry.terraform.io/hashicorp/aws"]`, - AbsProviderConfig{ - Module: ModuleInstance{ - { - Name: "baz", - InstanceKey: StringKey("foo"), - }, - }, - Provider: Provider{ - Type: "aws", - Namespace: "hashicorp", - Hostname: "registry.terraform.io", - }, - }, - ``, + AbsProviderConfig{}, + `Provider address cannot contain module indexes`, }, { `module.baz[1].provider["registry.terraform.io/hashicorp/aws"]`, - AbsProviderConfig{ - Module: ModuleInstance{ - { - Name: "baz", - InstanceKey: IntKey(1), - }, - }, - Provider: Provider{ - Type: "aws", - Namespace: "hashicorp", - Hostname: "registry.terraform.io", - }, - }, - ``, + AbsProviderConfig{}, + `Provider address cannot contain module indexes`, }, { `module.baz[1].module.bar.provider["registry.terraform.io/hashicorp/aws"]`, - AbsProviderConfig{ - Module: ModuleInstance{ - { - Name: "baz", - InstanceKey: IntKey(1), - }, - { - Name: "bar", - }, - }, - Provider: Provider{ - Type: "aws", - Namespace: "hashicorp", - Hostname: "registry.terraform.io", - }, - }, - ``, + AbsProviderConfig{}, + `Provider address cannot contain module indexes`, }, { `aws`, @@ -206,21 +159,21 @@ func TestAbsProviderConfigString(t *testing.T) { }{ { AbsProviderConfig{ - Module: RootModuleInstance, + Module: RootModule, Provider: NewLegacyProvider("foo"), }, `provider["registry.terraform.io/-/foo"]`, }, { AbsProviderConfig{ - Module: RootModuleInstance.Child("child_module", NoKey), + Module: RootModule.Child("child_module"), Provider: NewLegacyProvider("foo"), }, `module.child_module.provider["registry.terraform.io/-/foo"]`, }, { AbsProviderConfig{ - Module: RootModuleInstance, + Module: RootModule, Alias: "bar", Provider: NewLegacyProvider("foo"), }, @@ -228,7 +181,7 @@ func TestAbsProviderConfigString(t *testing.T) { }, { AbsProviderConfig{ - Module: RootModuleInstance.Child("child_module", NoKey), + Module: RootModule.Child("child_module"), Alias: "bar", Provider: NewLegacyProvider("foo"), }, @@ -251,21 +204,21 @@ func TestAbsProviderConfigLegacyString(t *testing.T) { }{ { AbsProviderConfig{ - Module: RootModuleInstance, + Module: RootModule, Provider: NewLegacyProvider("foo"), }, `provider.foo`, }, { AbsProviderConfig{ - Module: RootModuleInstance.Child("child_module", NoKey), + Module: RootModule.Child("child_module"), Provider: NewLegacyProvider("foo"), }, `module.child_module.provider.foo`, }, { AbsProviderConfig{ - Module: RootModuleInstance, + Module: RootModule, Alias: "bar", Provider: NewLegacyProvider("foo"), }, @@ -273,7 +226,7 @@ func TestAbsProviderConfigLegacyString(t *testing.T) { }, { AbsProviderConfig{ - Module: RootModuleInstance.Child("child_module", NoKey), + Module: RootModule.Child("child_module"), Alias: "bar", Provider: NewLegacyProvider("foo"), }, diff --git a/configs/config.go b/configs/config.go index b3b367a76..bc021c4d1 100644 --- a/configs/config.go +++ b/configs/config.go @@ -222,7 +222,7 @@ func (c *Config) gatherProviderTypes(m map[addrs.Provider]struct{}) { // The module address to resolve local addresses in must be given in the second // argument, and must refer to a module that exists under the receiver or // else this method will panic. -func (c *Config) ResolveAbsProviderAddr(addr addrs.ProviderConfig, inModule addrs.ModuleInstance) addrs.AbsProviderConfig { +func (c *Config) ResolveAbsProviderAddr(addr addrs.ProviderConfig, inModule addrs.Module) addrs.AbsProviderConfig { switch addr := addr.(type) { case addrs.AbsProviderConfig: @@ -231,7 +231,7 @@ func (c *Config) ResolveAbsProviderAddr(addr addrs.ProviderConfig, inModule addr case addrs.LocalProviderConfig: // Find the descendent Config that contains the module that this // local config belongs to. - mc := c.DescendentForInstance(inModule) + mc := c.Descendent(inModule) if mc == nil { panic(fmt.Sprintf("ResolveAbsProviderAddr with non-existent module %s", inModule.String())) } @@ -265,5 +265,5 @@ func (c *Config) ProviderForConfigAddr(addr addrs.LocalProviderConfig) addrs.Pro if provider, exists := c.Module.ProviderRequirements[addr.LocalName]; exists { return provider.Type } - return c.ResolveAbsProviderAddr(addr, addrs.RootModuleInstance).Provider + return c.ResolveAbsProviderAddr(addr, addrs.RootModule).Provider } diff --git a/configs/config_test.go b/configs/config_test.go index f91aa92d9..1bbf5666d 100644 --- a/configs/config_test.go +++ b/configs/config_test.go @@ -43,11 +43,11 @@ func TestConfigResolveAbsProviderAddr(t *testing.T) { t.Run("already absolute", func(t *testing.T) { addr := addrs.AbsProviderConfig{ - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, Provider: addrs.NewLegacyProvider("test"), Alias: "boop", } - got := cfg.ResolveAbsProviderAddr(addr, addrs.RootModuleInstance) + got := cfg.ResolveAbsProviderAddr(addr, addrs.RootModule) if got, want := got.String(), addr.String(); got != want { t.Errorf("wrong result\ngot: %s\nwant: %s", got, want) } @@ -57,9 +57,9 @@ func TestConfigResolveAbsProviderAddr(t *testing.T) { LocalName: "implied", Alias: "boop", } - got := cfg.ResolveAbsProviderAddr(addr, addrs.RootModuleInstance) + got := cfg.ResolveAbsProviderAddr(addr, addrs.RootModule) want := addrs.AbsProviderConfig{ - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, // FIXME: At the time of writing we still have LocalProviderConfig // nested inside AbsProviderConfig, but a future change will // stop tis embedding and just have an addrs.Provider and an alias @@ -78,9 +78,9 @@ func TestConfigResolveAbsProviderAddr(t *testing.T) { LocalName: "foo-test", // this is explicitly set in the config Alias: "boop", } - got := cfg.ResolveAbsProviderAddr(addr, addrs.RootModuleInstance) + got := cfg.ResolveAbsProviderAddr(addr, addrs.RootModule) want := addrs.AbsProviderConfig{ - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, Provider: addrs.NewProvider(addrs.DefaultRegistryHost, "foo", "test"), Alias: "boop", } diff --git a/states/statefile/version3_upgrade.go b/states/statefile/version3_upgrade.go index 36153faae..3eb6e855e 100644 --- a/states/statefile/version3_upgrade.go +++ b/states/statefile/version3_upgrade.go @@ -136,13 +136,13 @@ func upgradeStateV3ToV4(old *stateV3) (*stateV4, error) { return nil, fmt.Errorf("invalid legacy provider config reference %q for %s: %s", oldProviderAddr, instAddr, diags.Err()) } providerAddr = addrs.AbsProviderConfig{ - Module: moduleAddr, + Module: moduleAddr.Module(), Provider: addrs.NewLegacyProvider(localAddr.LocalName), Alias: localAddr.Alias, } } else { providerAddr = addrs.AbsProviderConfig{ - Module: moduleAddr, + Module: moduleAddr.Module(), Provider: resAddr.DefaultProvider(), } } From 98cfb51f27ccaea1d578c68d294a79d6d2d3eefa Mon Sep 17 00:00:00 2001 From: James Bardin Date: Tue, 10 Mar 2020 21:21:19 -0400 Subject: [PATCH 3/4] convert /terraform to use new provider config Change all ModuleInstances in provider types to plain Modules --- terraform/context_apply_test.go | 50 ++++++++-------- terraform/context_import_test.go | 6 +- terraform/context_input.go | 2 +- terraform/context_input_test.go | 2 +- terraform/context_plan_test.go | 2 +- terraform/context_refresh_test.go | 10 ++-- terraform/eval_context_builtin.go | 10 ++-- terraform/eval_context_builtin_test.go | 8 +-- terraform/eval_provider_test.go | 8 +-- terraform/graph_builder_apply_test.go | 4 +- terraform/node_data_refresh_test.go | 2 +- terraform/node_provider_abstract.go | 6 +- terraform/transform_attach_schema.go | 2 +- terraform/transform_diff_test.go | 2 +- terraform/transform_import_state.go | 9 ++- terraform/transform_orphan_resource_test.go | 16 +++--- terraform/transform_provider.go | 63 ++++++++------------- terraform/transform_provisioner_test.go | 4 +- 18 files changed, 98 insertions(+), 108 deletions(-) diff --git a/terraform/context_apply_test.go b/terraform/context_apply_test.go index 3fe1400d2..c33885e68 100644 --- a/terraform/context_apply_test.go +++ b/terraform/context_apply_test.go @@ -1333,7 +1333,7 @@ func TestContext2Apply_destroyDependsOnStateOnly(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) root.SetResourceInstanceCurrent( @@ -1358,7 +1358,7 @@ func TestContext2Apply_destroyDependsOnStateOnly(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) @@ -1431,7 +1431,7 @@ func TestContext2Apply_destroyDependsOnStateOnlyModule(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) child.SetResourceInstanceCurrent( @@ -1456,7 +1456,7 @@ func TestContext2Apply_destroyDependsOnStateOnlyModule(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) @@ -2828,7 +2828,7 @@ func TestContext2Apply_orphanResource(t *testing.T) { want := states.BuildState(func(s *states.SyncState) { providerAddr := addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, } zeroAddr := addrs.Resource{ Mode: addrs.ManagedResourceMode, @@ -7051,7 +7051,7 @@ func TestContext2Apply_errorDestroy(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }), @@ -7191,7 +7191,7 @@ func TestContext2Apply_errorUpdateNullNew(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }), @@ -8618,7 +8618,7 @@ func TestContext2Apply_createBefore_depends(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) @@ -8644,7 +8644,7 @@ func TestContext2Apply_createBefore_depends(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) @@ -8751,7 +8751,7 @@ func TestContext2Apply_singleDestroy(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) @@ -8777,7 +8777,7 @@ func TestContext2Apply_singleDestroy(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) @@ -9684,7 +9684,7 @@ func TestContext2Apply_destroyWithProviders(t *testing.T) { state.Modules["module.mod.module.removed"].Resources["aws_instance.child"].ProviderConfig = addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), Alias: "bar", - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, } if _, diags := ctx.Plan(); diags.HasErrors() { @@ -10108,7 +10108,7 @@ func TestContext2Apply_issue19908(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }), @@ -10236,7 +10236,7 @@ func TestContext2Apply_moduleReplaceCycle(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) @@ -10253,7 +10253,7 @@ func TestContext2Apply_moduleReplaceCycle(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) @@ -10296,7 +10296,7 @@ func TestContext2Apply_moduleReplaceCycle(t *testing.T) { }.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance.Child("a", addrs.NoKey)), ProviderAddr: addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ChangeSrc: plans.ChangeSrc{ Action: aAction, @@ -10312,7 +10312,7 @@ func TestContext2Apply_moduleReplaceCycle(t *testing.T) { }.Instance(addrs.IntKey(0)).Absolute(addrs.RootModuleInstance.Child("b", addrs.NoKey)), ProviderAddr: addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ChangeSrc: plans.ChangeSrc{ Action: plans.DeleteThenCreate, @@ -10363,7 +10363,7 @@ func TestContext2Apply_destroyDataCycle(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("null"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) root.SetResourceInstanceCurrent( @@ -10378,7 +10378,7 @@ func TestContext2Apply_destroyDataCycle(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("null"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) @@ -10453,7 +10453,7 @@ func TestContext2Apply_taintedDestroyFailure(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) root.SetResourceInstanceCurrent( @@ -10468,7 +10468,7 @@ func TestContext2Apply_taintedDestroyFailure(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) root.SetResourceInstanceCurrent( @@ -10483,7 +10483,7 @@ func TestContext2Apply_taintedDestroyFailure(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) @@ -10660,7 +10660,7 @@ func TestContext2Apply_cbdCycle(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) root.SetResourceInstanceCurrent( @@ -10685,7 +10685,7 @@ func TestContext2Apply_cbdCycle(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) root.SetResourceInstanceCurrent( @@ -10700,7 +10700,7 @@ func TestContext2Apply_cbdCycle(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) diff --git a/terraform/context_import_test.go b/terraform/context_import_test.go index d16a36371..1f9bc21d2 100644 --- a/terraform/context_import_test.go +++ b/terraform/context_import_test.go @@ -117,7 +117,7 @@ func TestContextImport_collision(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }), @@ -606,7 +606,7 @@ func TestContextImport_moduleDiff(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }), @@ -667,7 +667,7 @@ func TestContextImport_moduleExisting(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }), diff --git a/terraform/context_input.go b/terraform/context_input.go index b3a2b5f9d..305bae77f 100644 --- a/terraform/context_input.go +++ b/terraform/context_input.go @@ -160,7 +160,7 @@ func (c *Context) Input(mode InputMode) tfdiags.Diagnostics { absConfigAddr := addrs.AbsProviderConfig{ Provider: providerFqn, Alias: pa.Alias, - Module: c.Config().Path.UnkeyedInstanceShim(), + Module: c.Config().Path, } c.providerInputConfig[absConfigAddr.String()] = vals diff --git a/terraform/context_input_test.go b/terraform/context_input_test.go index 74a9f6e73..d7e48f151 100644 --- a/terraform/context_input_test.go +++ b/terraform/context_input_test.go @@ -480,7 +480,7 @@ func TestContext2Input_dataSourceRequiresRefresh(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("null"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) diff --git a/terraform/context_plan_test.go b/terraform/context_plan_test.go index 8288d5121..09c8e78d8 100644 --- a/terraform/context_plan_test.go +++ b/terraform/context_plan_test.go @@ -5052,7 +5052,7 @@ func TestContext2Plan_ignoreChangesInMap(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) diff --git a/terraform/context_refresh_test.go b/terraform/context_refresh_test.go index 7b84af45c..82765125c 100644 --- a/terraform/context_refresh_test.go +++ b/terraform/context_refresh_test.go @@ -105,7 +105,7 @@ func TestContext2Refresh_dynamicAttr(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -1742,7 +1742,7 @@ func TestContext2Refresh_schemaUpgradeFlatmap(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -1828,7 +1828,7 @@ func TestContext2Refresh_schemaUpgradeJSON(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -1999,7 +1999,7 @@ func TestRefresh_updateDependencies(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) root.SetResourceInstanceCurrent( @@ -2014,7 +2014,7 @@ func TestRefresh_updateDependencies(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) diff --git a/terraform/eval_context_builtin.go b/terraform/eval_context_builtin.go index 15f1f08ab..c5cae2194 100644 --- a/terraform/eval_context_builtin.go +++ b/terraform/eval_context_builtin.go @@ -108,7 +108,7 @@ func (ctx *BuiltinEvalContext) Input() UIInput { func (ctx *BuiltinEvalContext) InitProvider(addr addrs.AbsProviderConfig) (providers.Interface, error) { ctx.once.Do(ctx.init) absAddr := addr - if !absAddr.Module.Equal(ctx.Path()) { + if !absAddr.Module.Equal(ctx.Path().Module()) { // This indicates incorrect use of InitProvider: it should be used // only from the module that the provider configuration belongs to. panic(fmt.Sprintf("%s initialized by wrong module %s", absAddr, ctx.Path())) @@ -153,7 +153,7 @@ func (ctx *BuiltinEvalContext) ProviderSchema(addr addrs.AbsProviderConfig) *Pro func (ctx *BuiltinEvalContext) CloseProvider(addr addrs.AbsProviderConfig) error { ctx.once.Do(ctx.init) - if !addr.Module.Equal(ctx.Path()) { + if !addr.Module.Equal(ctx.Path().Module()) { // This indicates incorrect use of CloseProvider: it should be used // only from the module that the provider configuration belongs to. panic(fmt.Sprintf("%s closed by wrong module %s", addr, ctx.Path())) @@ -175,7 +175,7 @@ func (ctx *BuiltinEvalContext) CloseProvider(addr addrs.AbsProviderConfig) error func (ctx *BuiltinEvalContext) ConfigureProvider(addr addrs.AbsProviderConfig, cfg cty.Value) tfdiags.Diagnostics { var diags tfdiags.Diagnostics absAddr := addr - if !absAddr.Module.Equal(ctx.Path()) { + if !absAddr.Module.Equal(ctx.Path().Module()) { // This indicates incorrect use of ConfigureProvider: it should be used // only from the module that the provider configuration belongs to. panic(fmt.Sprintf("%s configured by wrong module %s", absAddr, ctx.Path())) @@ -206,7 +206,7 @@ func (ctx *BuiltinEvalContext) ProviderInput(pc addrs.AbsProviderConfig) map[str ctx.ProviderLock.Lock() defer ctx.ProviderLock.Unlock() - if !pc.Module.Equal(ctx.Path()) { + if !pc.Module.Equal(ctx.Path().Module()) { // This indicates incorrect use of InitProvider: it should be used // only from the module that the provider configuration belongs to. panic(fmt.Sprintf("%s initialized by wrong module %s", pc, ctx.Path())) @@ -222,7 +222,7 @@ func (ctx *BuiltinEvalContext) ProviderInput(pc addrs.AbsProviderConfig) map[str func (ctx *BuiltinEvalContext) SetProviderInput(pc addrs.AbsProviderConfig, c map[string]cty.Value) { absProvider := pc - if !absProvider.Module.Equal(ctx.Path()) { + if !absProvider.Module.Equal(ctx.Path().Module()) { // This indicates incorrect use of InitProvider: it should be used // only from the module that the provider configuration belongs to. panic(fmt.Sprintf("%s initialized by wrong module %s", absProvider, ctx.Path())) diff --git a/terraform/eval_context_builtin_test.go b/terraform/eval_context_builtin_test.go index 45343c0f3..bdcd09484 100644 --- a/terraform/eval_context_builtin_test.go +++ b/terraform/eval_context_builtin_test.go @@ -25,11 +25,11 @@ func TestBuiltinEvalContextProviderInput(t *testing.T) { ctx2.ProviderLock = &lock providerAddr1 := addrs.AbsProviderConfig{ - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, Provider: addrs.NewLegacyProvider("foo"), } providerAddr2 := addrs.AbsProviderConfig{ - Module: addrs.RootModuleInstance.Child("child", addrs.NoKey), + Module: addrs.RootModule.Child("child"), Provider: addrs.NewLegacyProvider("foo"), } @@ -65,11 +65,11 @@ func TestBuildingEvalContextInitProvider(t *testing.T) { } providerAddrDefault := addrs.AbsProviderConfig{ - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, Provider: addrs.NewLegacyProvider("test"), } providerAddrAlias := addrs.AbsProviderConfig{ - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, Provider: addrs.NewLegacyProvider("test"), Alias: "foo", } diff --git a/terraform/eval_provider_test.go b/terraform/eval_provider_test.go index 23b94c537..5b3e70c24 100644 --- a/terraform/eval_provider_test.go +++ b/terraform/eval_provider_test.go @@ -17,7 +17,7 @@ func TestBuildProviderConfig(t *testing.T) { "set_in_config": cty.StringVal("config"), }) providerAddr := addrs.AbsProviderConfig{ - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, Provider: addrs.NewLegacyProvider("foo"), } @@ -69,7 +69,7 @@ func TestEvalConfigProvider(t *testing.T) { provider := mockProviderWithConfigSchema(simpleTestSchema()) rp := providers.Interface(provider) providerAddr := addrs.AbsProviderConfig{ - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, Provider: addrs.NewLegacyProvider("foo"), } n := &EvalConfigProvider{ @@ -103,7 +103,7 @@ func TestEvalInitProvider_impl(t *testing.T) { func TestEvalInitProvider(t *testing.T) { providerAddr := addrs.AbsProviderConfig{ - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, Provider: addrs.NewLegacyProvider("foo"), } n := &EvalInitProvider{ @@ -125,7 +125,7 @@ func TestEvalInitProvider(t *testing.T) { func TestEvalCloseProvider(t *testing.T) { providerAddr := addrs.AbsProviderConfig{ - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, Provider: addrs.NewLegacyProvider("foo"), } n := &EvalCloseProvider{ diff --git a/terraform/graph_builder_apply_test.go b/terraform/graph_builder_apply_test.go index 293af99db..5654c49c3 100644 --- a/terraform/graph_builder_apply_test.go +++ b/terraform/graph_builder_apply_test.go @@ -554,7 +554,7 @@ func TestApplyGraphBuilder_updateFromOrphan(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) root.SetResourceInstanceCurrent( @@ -579,7 +579,7 @@ func TestApplyGraphBuilder_updateFromOrphan(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) diff --git a/terraform/node_data_refresh_test.go b/terraform/node_data_refresh_test.go index eaa233b4c..1f88d1bee 100644 --- a/terraform/node_data_refresh_test.go +++ b/terraform/node_data_refresh_test.go @@ -134,7 +134,7 @@ func TestNodeRefreshableDataResourceDynamicExpand_scaleIn(t *testing.T) { Config: m.Module.DataResources["data.aws_instance.foo"], ResolvedProvider: addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, }, } diff --git a/terraform/node_provider_abstract.go b/terraform/node_provider_abstract.go index 5c0d953f3..871caefc5 100644 --- a/terraform/node_provider_abstract.go +++ b/terraform/node_provider_abstract.go @@ -26,7 +26,7 @@ type NodeAbstractProvider struct { } var ( - _ GraphNodeModuleInstance = (*NodeAbstractProvider)(nil) + _ GraphNodeModulePath = (*NodeAbstractProvider)(nil) _ RemovableIfNotTargeted = (*NodeAbstractProvider)(nil) _ GraphNodeReferencer = (*NodeAbstractProvider)(nil) _ GraphNodeProvider = (*NodeAbstractProvider)(nil) @@ -41,12 +41,12 @@ func (n *NodeAbstractProvider) Name() string { // GraphNodeModuleInstance func (n *NodeAbstractProvider) Path() addrs.ModuleInstance { - return n.Addr.Module + return n.Addr.Module.UnkeyedInstanceShim() } // GraphNodeModulePath func (n *NodeAbstractProvider) ModulePath() addrs.Module { - return n.Addr.Module.Module() + return n.Addr.Module } // RemovableIfNotTargeted diff --git a/terraform/transform_attach_schema.go b/terraform/transform_attach_schema.go index 1315da609..3165b0df1 100644 --- a/terraform/transform_attach_schema.go +++ b/terraform/transform_attach_schema.go @@ -69,7 +69,7 @@ func (t *AttachSchemaTransformer) Transform(g *Graph) error { if t.Config == nil { providerFqn = addrs.NewLegacyProvider(p.LocalName) } else { - modConfig := t.Config.DescendentForInstance(tv.Path()) + modConfig := t.Config.Descendent(tv.ModulePath()) if modConfig == nil { providerFqn = addrs.NewLegacyProvider(p.LocalName) } else { diff --git a/terraform/transform_diff_test.go b/terraform/transform_diff_test.go index 58ae5e8fb..a75bd29ea 100644 --- a/terraform/transform_diff_test.go +++ b/terraform/transform_diff_test.go @@ -45,7 +45,7 @@ func TestDiffTransformer(t *testing.T) { }.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance), ProviderAddr: addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ChangeSrc: plans.ChangeSrc{ Action: plans.Update, diff --git a/terraform/transform_import_state.go b/terraform/transform_import_state.go index 22c56be4d..19bca4132 100644 --- a/terraform/transform_import_state.go +++ b/terraform/transform_import_state.go @@ -24,7 +24,7 @@ func (t *ImportStateTransformer) Transform(g *Graph) error { defaultFQN := target.Addr.Resource.Resource.DefaultProvider() providerAddr = addrs.AbsProviderConfig{ Provider: defaultFQN, - Module: target.Addr.Module, + Module: target.Addr.Module.Module(), } } @@ -48,7 +48,7 @@ type graphNodeImportState struct { } var ( - _ GraphNodeModuleInstance = (*graphNodeImportState)(nil) + _ GraphNodeModulePath = (*graphNodeImportState)(nil) _ GraphNodeEvalable = (*graphNodeImportState)(nil) _ GraphNodeProviderConsumer = (*graphNodeImportState)(nil) _ GraphNodeDynamicExpandable = (*graphNodeImportState)(nil) @@ -88,6 +88,11 @@ func (n *graphNodeImportState) Path() addrs.ModuleInstance { return n.Addr.Module } +// GraphNodeModulePath +func (n *graphNodeImportState) ModulePath() addrs.Module { + return n.Addr.Module.Module() +} + // GraphNodeEvalable impl. func (n *graphNodeImportState) EvalTree() EvalNode { var provider providers.Interface diff --git a/terraform/transform_orphan_resource_test.go b/terraform/transform_orphan_resource_test.go index 182d14bca..acb80564c 100644 --- a/terraform/transform_orphan_resource_test.go +++ b/terraform/transform_orphan_resource_test.go @@ -28,7 +28,7 @@ func TestOrphanResourceInstanceTransformer(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) @@ -47,7 +47,7 @@ func TestOrphanResourceInstanceTransformer(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -96,7 +96,7 @@ func TestOrphanResourceInstanceTransformer_countGood(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) s.SetResourceInstanceCurrent( @@ -113,7 +113,7 @@ func TestOrphanResourceInstanceTransformer_countGood(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -161,7 +161,7 @@ func TestOrphanResourceInstanceTransformer_countBad(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) s.SetResourceInstanceCurrent( @@ -178,7 +178,7 @@ func TestOrphanResourceInstanceTransformer_countBad(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -226,7 +226,7 @@ func TestOrphanResourceInstanceTransformer_modules(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) s.SetResourceInstanceCurrent( @@ -243,7 +243,7 @@ func TestOrphanResourceInstanceTransformer_modules(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) diff --git a/terraform/transform_provider.go b/terraform/transform_provider.go index 910e8aac1..a4494b054 100644 --- a/terraform/transform_provider.go +++ b/terraform/transform_provider.go @@ -44,7 +44,7 @@ func TransformProviders(providers []string, concrete ConcreteProviderNodeFunc, c // // Name returns the full name of the provider in the config. type GraphNodeProvider interface { - GraphNodeModuleInstance + GraphNodeModulePath ProviderAddr() addrs.AbsProviderConfig Name() string } @@ -53,7 +53,7 @@ type GraphNodeProvider interface { // provider must implement. The CloseProviderName returned is the name of // the provider they satisfy. type GraphNodeCloseProvider interface { - GraphNodeModuleInstance + GraphNodeModulePath CloseProviderAddr() addrs.AbsProviderConfig } @@ -63,7 +63,7 @@ type GraphNodeCloseProvider interface { // or in an ancestor module, with the resulting absolute address passed to // SetProvider. type GraphNodeProviderConsumer interface { - GraphNodeModuleInstance + GraphNodeModulePath // ProvidedBy returns the address of the provider configuration the node // refers to, if available. The following value types may be returned: // @@ -139,7 +139,7 @@ func (t *ProviderTransformer) Transform(g *Graph) error { case addrs.LocalProviderConfig: // ProvidedBy() return a LocalProviderConfig when the resource // contains a `provider` attribute - modPath := pv.Path() + modPath := pv.ModulePath() if t.Config == nil { absPc.Provider = addrs.NewLegacyProvider(p.LocalName) absPc.Module = modPath @@ -147,7 +147,7 @@ func (t *ProviderTransformer) Transform(g *Graph) error { break } - modConfig := t.Config.DescendentForInstance(modPath) + modConfig := t.Config.Descendent(modPath) if modConfig == nil { absPc.Provider = addrs.NewLegacyProvider(p.LocalName) } else { @@ -159,7 +159,7 @@ func (t *ProviderTransformer) Transform(g *Graph) error { case nil: // No provider found in config or state; fall back to implied default provider. absPc.Provider = pv.ImpliedProvider() - absPc.Module = pv.Path() + absPc.Module = pv.ModulePath() log.Printf("[TRACE] ProviderTransformer: %s is provided by %s or inherited equivalent", dag.VertexName(v), absPc) default: @@ -216,7 +216,7 @@ func (t *ProviderTransformer) Transform(g *Graph) error { // start up the provider and fetch its schema. if _, exists := needConfigured[key]; target == nil && !exists { stubAddr := addrs.AbsProviderConfig{ - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, Provider: p.Provider, } stub := &NodeEvalableProvider{ @@ -364,7 +364,7 @@ func (t *MissingProviderTransformer) Transform(g *Graph) error { log.Println("[TRACE] MissingProviderTransformer: skipping implication of aliased config", p) continue } - modConfig := t.Config.DescendentForInstance(pv.Path()) + modConfig := t.Config.Descendent(pv.ModulePath()) if modConfig == nil { providerFqn = addrs.NewLegacyProvider(p.LocalName) } else { @@ -427,7 +427,7 @@ func (t *ParentProviderTransformer) Transform(g *Graph) error { // Also require non-empty path, since otherwise we're in the root // module and so cannot have a parent. - if len(pn.Path()) <= 1 { + if len(pn.ModulePath()) <= 1 { continue } @@ -513,6 +513,11 @@ func (n *graphNodeCloseProvider) Name() string { // GraphNodeModuleInstance impl. func (n *graphNodeCloseProvider) Path() addrs.ModuleInstance { + return n.Addr.Module.UnkeyedInstanceShim() +} + +// GraphNodeModulePath +func (n *graphNodeCloseProvider) ModulePath() addrs.Module { return n.Addr.Module } @@ -562,7 +567,8 @@ type graphNodeProxyProvider struct { } var ( - _ GraphNodeProvider = (*graphNodeProxyProvider)(nil) + _ GraphNodeModulePath = (*graphNodeProxyProvider)(nil) + _ GraphNodeProvider = (*graphNodeProxyProvider)(nil) ) func (n *graphNodeProxyProvider) ProviderAddr() addrs.AbsProviderConfig { @@ -570,6 +576,10 @@ func (n *graphNodeProxyProvider) ProviderAddr() addrs.AbsProviderConfig { } func (n *graphNodeProxyProvider) Path() addrs.ModuleInstance { + return n.addr.Module.UnkeyedInstanceShim() +} + +func (n *graphNodeProxyProvider) ModulePath() addrs.Module { return n.addr.Module } @@ -644,19 +654,7 @@ func (t *ProviderConfigTransformer) transform(g *Graph, c *configs.Config) error func (t *ProviderConfigTransformer) transformSingle(g *Graph, c *configs.Config) error { // Get the module associated with this configuration tree node mod := c.Module - staticPath := c.Path - - // We actually need a dynamic module path here, but we've not yet updated - // our graph builders enough to support expansion of module calls with - // "count" and "for_each" set, so for now we'll shim this by converting to - // a dynamic path with no keys. At the time of writing this is the only - // possible kind of dynamic path anyway. - path := make(addrs.ModuleInstance, len(staticPath)) - for i, name := range staticPath { - path[i] = addrs.ModuleInstanceStep{ - Name: name, - } - } + path := c.Path // add all providers from the configuration for _, p := range mod.ProviderConfigs { @@ -720,19 +718,6 @@ func (t *ProviderConfigTransformer) addProxyProviders(g *Graph, c *configs.Confi } } - // We currently don't support count/for_each for modules and so we must - // shim our path and parentPath into module instances here so that the - // rest of Terraform can behave as if we do. This shimming should be - // removed later as part of implementing count/for_each for modules. - instPath := make(addrs.ModuleInstance, len(path)) - for i, name := range path { - instPath[i] = addrs.ModuleInstanceStep{Name: name} - } - parentInstPath := make(addrs.ModuleInstance, len(parentPath)) - for i, name := range parentPath { - parentInstPath[i] = addrs.ModuleInstanceStep{Name: name} - } - if parentCfg == nil { // this can't really happen during normal execution. return fmt.Errorf("parent module config not found for %s", c.Path.String()) @@ -744,13 +729,13 @@ func (t *ProviderConfigTransformer) addProxyProviders(g *Graph, c *configs.Confi fqn := c.Module.ProviderForLocalConfig(pair.InChild.Addr()) fullAddr := addrs.AbsProviderConfig{ Provider: fqn, - Module: instPath, + Module: path, Alias: pair.InChild.Addr().Alias, } fullParentAddr := addrs.AbsProviderConfig{ Provider: fqn, - Module: parentInstPath, + Module: parentPath, Alias: pair.InParent.Addr().Alias, } @@ -802,7 +787,7 @@ func (t *ProviderConfigTransformer) attachProviderConfigs(g *Graph) error { addr := apn.ProviderAddr() // Get the configuration. - mc := t.Config.DescendentForInstance(addr.Module) + mc := t.Config.Descendent(addr.Module) if mc == nil { log.Printf("[TRACE] ProviderConfigTransformer: no configuration available for %s", addr.String()) continue diff --git a/terraform/transform_provisioner_test.go b/terraform/transform_provisioner_test.go index 0b25b1d25..89e67cc82 100644 --- a/terraform/transform_provisioner_test.go +++ b/terraform/transform_provisioner_test.go @@ -72,7 +72,7 @@ func TestMissingProvisionerTransformer_module(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) s.SetResourceInstanceCurrent( @@ -89,7 +89,7 @@ func TestMissingProvisionerTransformer_module(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("aws"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) From e13eecbc5bd1c54a36013c27e969b02eeee935cc Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 11 Mar 2020 14:19:52 -0400 Subject: [PATCH 4/4] finish provider ModuleInstance replacement --- backend/local/backend_plan_test.go | 10 +++--- backend/testing.go | 2 +- command/apply_destroy_test.go | 8 ++--- command/apply_test.go | 8 ++--- command/command_test.go | 2 +- command/format/diff_test.go | 2 +- command/format/state_test.go | 14 ++++---- command/graph_test.go | 2 +- command/jsonplan/values_test.go | 2 +- command/jsonstate/state_test.go | 22 ++++++------- command/plan_test.go | 4 +-- command/show_test.go | 2 +- command/state_mv_test.go | 52 +++++++++++++++--------------- command/state_rm_test.go | 24 +++++++------- command/state_show.go | 2 +- command/state_show_test.go | 8 ++--- command/taint_test.go | 12 +++---- command/untaint_test.go | 12 +++---- command/workspace_command_test.go | 2 +- helper/resource/state_shim_test.go | 16 ++++----- helper/resource/testing.go | 2 +- plans/plan_test.go | 10 +++--- plans/planfile/tfplan_test.go | 6 ++-- providers/addressed_types_test.go | 10 +++--- repl/session_test.go | 4 +-- states/state_test.go | 8 ++--- states/statemgr/testing.go | 2 +- 27 files changed, 124 insertions(+), 124 deletions(-) diff --git a/backend/local/backend_plan_test.go b/backend/local/backend_plan_test.go index 9aa028653..d6ba5ce08 100644 --- a/backend/local/backend_plan_test.go +++ b/backend/local/backend_plan_test.go @@ -217,7 +217,7 @@ func TestLocal_planDeposedOnly(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) })) @@ -661,7 +661,7 @@ func testPlanState() *states.State { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) return state @@ -688,7 +688,7 @@ func testPlanState_withDataSource() *states.State { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) rootModule.SetResourceInstanceCurrent( @@ -705,7 +705,7 @@ func testPlanState_withDataSource() *states.State { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) return state @@ -732,7 +732,7 @@ func testPlanState_tainted() *states.State { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) return state diff --git a/backend/testing.go b/backend/testing.go index 4521fd753..e6f591e0e 100644 --- a/backend/testing.go +++ b/backend/testing.go @@ -152,7 +152,7 @@ func TestBackendStates(t *testing.T, b Backend) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) diff --git a/command/apply_destroy_test.go b/command/apply_destroy_test.go index bdcfa1a07..784c3029b 100644 --- a/command/apply_destroy_test.go +++ b/command/apply_destroy_test.go @@ -31,7 +31,7 @@ func TestApply_destroy(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -127,7 +127,7 @@ func TestApply_destroyLockedState(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -202,7 +202,7 @@ func TestApply_destroyTargeted(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) s.SetResourceInstanceCurrent( @@ -218,7 +218,7 @@ func TestApply_destroyTargeted(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) diff --git a/command/apply_test.go b/command/apply_test.go index f411d138d..743f60815 100644 --- a/command/apply_test.go +++ b/command/apply_test.go @@ -835,7 +835,7 @@ func TestApply_refresh(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -992,7 +992,7 @@ func TestApply_state(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -1359,7 +1359,7 @@ func TestApply_backup(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -1663,7 +1663,7 @@ func applyFixturePlanFile(t *testing.T) string { }.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance), ProviderAddr: addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ChangeSrc: plans.ChangeSrc{ Action: plans.Create, diff --git a/command/command_test.go b/command/command_test.go index 1bb715b97..11632df93 100644 --- a/command/command_test.go +++ b/command/command_test.go @@ -273,7 +273,7 @@ func testState() *states.State { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) // DeepCopy is used here to ensure our synthetic state matches exactly diff --git a/command/format/diff_test.go b/command/format/diff_test.go index ef731d5b2..3c6e6460b 100644 --- a/command/format/diff_test.go +++ b/command/format/diff_test.go @@ -3159,7 +3159,7 @@ func runTestCases(t *testing.T, testCases map[string]testCase) { }.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance), ProviderAddr: addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ChangeSrc: plans.ChangeSrc{ Action: tc.Action, diff --git a/command/format/state_test.go b/command/format/state_test.go index 40c97b124..ba7354188 100644 --- a/command/format/state_test.go +++ b/command/format/state_test.go @@ -245,7 +245,7 @@ func basicState(t *testing.T) *states.State { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) rootModule.SetResourceInstanceCurrent( @@ -261,7 +261,7 @@ func basicState(t *testing.T) *states.State { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) return state @@ -297,7 +297,7 @@ func stateWithMoreOutputs(t *testing.T) *states.State { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) return state @@ -324,7 +324,7 @@ func nestedState(t *testing.T) *states.State { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) return state @@ -347,7 +347,7 @@ func deposedState(t *testing.T) *states.State { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) return state @@ -376,7 +376,7 @@ func onlyDeposedState(t *testing.T) *states.State { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) rootModule.SetResourceInstanceDeposed( @@ -393,7 +393,7 @@ func onlyDeposedState(t *testing.T) *states.State { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) return state diff --git a/command/graph_test.go b/command/graph_test.go index a3b4e6a14..bea2d3925 100644 --- a/command/graph_test.go +++ b/command/graph_test.go @@ -127,7 +127,7 @@ func TestGraph_plan(t *testing.T) { }, ProviderAddr: addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, }) emptyConfig, err := plans.NewDynamicValue(cty.EmptyObjectVal, cty.EmptyObject) diff --git a/command/jsonplan/values_test.go b/command/jsonplan/values_test.go index 9fe9043cb..15084e2d9 100644 --- a/command/jsonplan/values_test.go +++ b/command/jsonplan/values_test.go @@ -260,7 +260,7 @@ func TestMarshalPlanResources(t *testing.T) { }.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance), ProviderAddr: addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ChangeSrc: plans.ChangeSrc{ Action: test.Action, diff --git a/command/jsonstate/state_test.go b/command/jsonstate/state_test.go index ef8cb869c..c1b16c8c2 100644 --- a/command/jsonstate/state_test.go +++ b/command/jsonstate/state_test.go @@ -203,7 +203,7 @@ func TestMarshalResources(t *testing.T) { }, ProviderConfig: addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, }, }, @@ -245,7 +245,7 @@ func TestMarshalResources(t *testing.T) { }, ProviderConfig: addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, }, }, @@ -287,7 +287,7 @@ func TestMarshalResources(t *testing.T) { }, ProviderConfig: addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, }, }, @@ -331,7 +331,7 @@ func TestMarshalResources(t *testing.T) { }, ProviderConfig: addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, }, }, @@ -380,7 +380,7 @@ func TestMarshalResources(t *testing.T) { }, ProviderConfig: addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, }, }, @@ -452,7 +452,7 @@ func TestMarshalModules_basic(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) s.SetResourceInstanceCurrent( @@ -467,7 +467,7 @@ func TestMarshalModules_basic(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: childModule, + Module: childModule.Module(), }, ) s.SetResourceInstanceCurrent( @@ -482,7 +482,7 @@ func TestMarshalModules_basic(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: subModule, + Module: subModule.Module(), }, ) }) @@ -521,7 +521,7 @@ func TestMarshalModules_nested(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) s.SetResourceInstanceCurrent( @@ -536,7 +536,7 @@ func TestMarshalModules_nested(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: childModule, + Module: childModule.Module(), }, ) s.SetResourceInstanceCurrent( @@ -551,7 +551,7 @@ func TestMarshalModules_nested(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: subModule, + Module: subModule.Module(), }, ) }) diff --git a/command/plan_test.go b/command/plan_test.go index 1891833e7..db0402702 100644 --- a/command/plan_test.go +++ b/command/plan_test.go @@ -126,7 +126,7 @@ func TestPlan_destroy(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -245,7 +245,7 @@ func TestPlan_outPathNoChange(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) diff --git a/command/show_test.go b/command/show_test.go index 3ad7b437d..50e1c32ca 100644 --- a/command/show_test.go +++ b/command/show_test.go @@ -487,7 +487,7 @@ func showFixturePlanFile(t *testing.T, action plans.Action) string { }.Instance(addrs.NoKey).Absolute(addrs.RootModuleInstance), ProviderAddr: addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ChangeSrc: plans.ChangeSrc{ Action: action, diff --git a/command/state_mv_test.go b/command/state_mv_test.go index d7968b5e6..95bc6984b 100644 --- a/command/state_mv_test.go +++ b/command/state_mv_test.go @@ -29,7 +29,7 @@ func TestStateMv(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) s.SetResourceInstanceCurrent( @@ -45,7 +45,7 @@ func TestStateMv(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -160,7 +160,7 @@ func TestStateMv_resourceToInstance(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) s.SetResourceInstanceCurrent( @@ -176,7 +176,7 @@ func TestStateMv_resourceToInstance(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) s.SetResourceMeta( @@ -188,7 +188,7 @@ func TestStateMv_resourceToInstance(t *testing.T) { states.EachList, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -250,7 +250,7 @@ func TestStateMv_instanceToResource(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) s.SetResourceInstanceCurrent( @@ -265,7 +265,7 @@ func TestStateMv_instanceToResource(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -338,7 +338,7 @@ func TestStateMv_instanceToNewResource(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -409,7 +409,7 @@ func TestStateMv_differentResourceTypes(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -462,7 +462,7 @@ func TestStateMv_explicitWithBackend(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) s.SetResourceInstanceCurrent( @@ -477,7 +477,7 @@ func TestStateMv_explicitWithBackend(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -537,7 +537,7 @@ func TestStateMv_backupExplicit(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) s.SetResourceInstanceCurrent( @@ -553,7 +553,7 @@ func TestStateMv_backupExplicit(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -602,7 +602,7 @@ func TestStateMv_stateOutNew(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -656,7 +656,7 @@ func TestStateMv_stateOutExisting(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -675,7 +675,7 @@ func TestStateMv_stateOutExisting(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -755,7 +755,7 @@ func TestStateMv_stateOutNew_count(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) s.SetResourceInstanceCurrent( @@ -770,7 +770,7 @@ func TestStateMv_stateOutNew_count(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) s.SetResourceInstanceCurrent( @@ -785,7 +785,7 @@ func TestStateMv_stateOutNew_count(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -843,7 +843,7 @@ func TestStateMv_stateOutNew_largeCount(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) } @@ -859,7 +859,7 @@ func TestStateMv_stateOutNew_largeCount(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -913,7 +913,7 @@ func TestStateMv_stateOutNew_nestedModule(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) s.SetResourceInstanceCurrent( @@ -928,7 +928,7 @@ func TestStateMv_stateOutNew_nestedModule(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -983,7 +983,7 @@ func TestStateMv_toNewModule(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -1056,7 +1056,7 @@ func TestStateMv_withinBackend(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) s.SetResourceInstanceCurrent( @@ -1072,7 +1072,7 @@ func TestStateMv_withinBackend(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) diff --git a/command/state_rm_test.go b/command/state_rm_test.go index 02fea0adf..ddb219787 100644 --- a/command/state_rm_test.go +++ b/command/state_rm_test.go @@ -27,7 +27,7 @@ func TestStateRm(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) s.SetResourceInstanceCurrent( @@ -42,7 +42,7 @@ func TestStateRm(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -92,7 +92,7 @@ func TestStateRmNotChildModule(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) // This second instance has the same local address as the first but @@ -110,7 +110,7 @@ func TestStateRmNotChildModule(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -181,7 +181,7 @@ func TestStateRmNoArgs(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) s.SetResourceInstanceCurrent( @@ -196,7 +196,7 @@ func TestStateRmNoArgs(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -240,7 +240,7 @@ func TestStateRmNonExist(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) s.SetResourceInstanceCurrent( @@ -255,7 +255,7 @@ func TestStateRmNonExist(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -300,7 +300,7 @@ func TestStateRm_backupExplicit(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) s.SetResourceInstanceCurrent( @@ -315,7 +315,7 @@ func TestStateRm_backupExplicit(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -416,7 +416,7 @@ func TestStateRm_backendState(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) s.SetResourceInstanceCurrent( @@ -431,7 +431,7 @@ func TestStateRm_backendState(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) diff --git a/command/state_show.go b/command/state_show.go index f91f051b6..93544781d 100644 --- a/command/state_show.go +++ b/command/state_show.go @@ -120,7 +120,7 @@ func (c *StateShowCommand) Run(args []string) int { absPc := addrs.AbsProviderConfig{ Provider: rs.ProviderConfig.Provider, Alias: rs.ProviderConfig.Alias, - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, } singleInstance := states.NewState() singleInstance.EnsureModule(addr.Module).SetResourceInstanceCurrent( diff --git a/command/state_show_test.go b/command/state_show_test.go index e382bdf90..b91cca0b8 100644 --- a/command/state_show_test.go +++ b/command/state_show_test.go @@ -27,7 +27,7 @@ func TestStateShow(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -85,7 +85,7 @@ func TestStateShow_multi(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) s.SetResourceInstanceCurrent( @@ -100,7 +100,7 @@ func TestStateShow_multi(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: submod, + Module: submod.Module(), }, ) }) @@ -206,7 +206,7 @@ func TestStateShow_configured_provider(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test-beta"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) diff --git a/command/taint_test.go b/command/taint_test.go index a34365d4b..80816b837 100644 --- a/command/taint_test.go +++ b/command/taint_test.go @@ -26,7 +26,7 @@ func TestTaint(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -64,7 +64,7 @@ func TestTaint_lockedState(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -253,7 +253,7 @@ func TestTaint_missing(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -289,7 +289,7 @@ func TestTaint_missingAllow(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -368,7 +368,7 @@ func TestTaint_module(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) s.SetResourceInstanceCurrent( @@ -383,7 +383,7 @@ func TestTaint_module(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) diff --git a/command/untaint_test.go b/command/untaint_test.go index 9584a7654..aa94eebf0 100644 --- a/command/untaint_test.go +++ b/command/untaint_test.go @@ -25,7 +25,7 @@ func TestUntaint(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -68,7 +68,7 @@ func TestUntaint_lockedState(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -279,7 +279,7 @@ func TestUntaint_missing(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -315,7 +315,7 @@ func TestUntaint_missingAllow(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) @@ -403,7 +403,7 @@ func TestUntaint_module(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) s.SetResourceInstanceCurrent( @@ -418,7 +418,7 @@ func TestUntaint_module(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) diff --git a/command/workspace_command_test.go b/command/workspace_command_test.go index 4d37da610..aefa0e159 100644 --- a/command/workspace_command_test.go +++ b/command/workspace_command_test.go @@ -243,7 +243,7 @@ func TestWorkspace_createWithState(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) diff --git a/helper/resource/state_shim_test.go b/helper/resource/state_shim_test.go index 3894c7392..7363f066e 100644 --- a/helper/resource/state_shim_test.go +++ b/helper/resource/state_shim_test.go @@ -43,7 +43,7 @@ func TestStateShim(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) rootModule.SetResourceInstanceCurrent( @@ -59,7 +59,7 @@ func TestStateShim(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) @@ -78,7 +78,7 @@ func TestStateShim(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: childInstance, + Module: childInstance.Module(), }, ) childModule.SetResourceInstanceCurrent( @@ -102,7 +102,7 @@ func TestStateShim(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: childInstance, + Module: childInstance.Module(), }, ) @@ -128,7 +128,7 @@ func TestStateShim(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: childInstance, + Module: childInstance.Module(), }, ) @@ -145,7 +145,7 @@ func TestStateShim(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: childInstance, + Module: childInstance.Module(), }, ) childModule.SetResourceInstanceCurrent( @@ -161,7 +161,7 @@ func TestStateShim(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: childInstance, + Module: childInstance.Module(), }, ) @@ -178,7 +178,7 @@ func TestStateShim(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: childInstance, + Module: childInstance.Module(), }, ) diff --git a/helper/resource/testing.go b/helper/resource/testing.go index 853241a9e..495e26d15 100644 --- a/helper/resource/testing.go +++ b/helper/resource/testing.go @@ -729,7 +729,7 @@ func testIDOnlyRefresh(c TestCase, opts terraform.ContextOpts, step TestStep, r }, addrs.AbsProviderConfig{ Provider: addrs.NewDefaultProvider("placeholder"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) diff --git a/plans/plan_test.go b/plans/plan_test.go index 03501b619..90cf2ffa5 100644 --- a/plans/plan_test.go +++ b/plans/plan_test.go @@ -21,7 +21,7 @@ func TestProviderAddrs(t *testing.T) { Name: "woot", }.Instance(addrs.IntKey(0)).Absolute(addrs.RootModuleInstance), ProviderAddr: addrs.AbsProviderConfig{ - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, Provider: addrs.NewLegacyProvider("test"), }, }, @@ -33,7 +33,7 @@ func TestProviderAddrs(t *testing.T) { }.Instance(addrs.IntKey(0)).Absolute(addrs.RootModuleInstance), DeposedKey: "foodface", ProviderAddr: addrs.AbsProviderConfig{ - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, Provider: addrs.NewLegacyProvider("test"), }, }, @@ -44,7 +44,7 @@ func TestProviderAddrs(t *testing.T) { Name: "what", }.Instance(addrs.IntKey(0)).Absolute(addrs.RootModuleInstance), ProviderAddr: addrs.AbsProviderConfig{ - Module: addrs.RootModuleInstance.Child("foo", addrs.NoKey), + Module: addrs.RootModule.Child("foo"), Provider: addrs.NewLegacyProvider("test"), }, }, @@ -55,11 +55,11 @@ func TestProviderAddrs(t *testing.T) { got := plan.ProviderAddrs() want := []addrs.AbsProviderConfig{ addrs.AbsProviderConfig{ - Module: addrs.RootModuleInstance.Child("foo", addrs.NoKey), + Module: addrs.RootModule.Child("foo"), Provider: addrs.NewLegacyProvider("test"), }, addrs.AbsProviderConfig{ - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, Provider: addrs.NewLegacyProvider("test"), }, } diff --git a/plans/planfile/tfplan_test.go b/plans/planfile/tfplan_test.go index 3da15289c..ffd6d1c49 100644 --- a/plans/planfile/tfplan_test.go +++ b/plans/planfile/tfplan_test.go @@ -58,7 +58,7 @@ func TestTFPlanRoundTrip(t *testing.T) { }.Instance(addrs.IntKey(0)).Absolute(addrs.RootModuleInstance), ProviderAddr: addrs.AbsProviderConfig{ Provider: addrs.NewDefaultProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ChangeSrc: plans.ChangeSrc{ Action: plans.DeleteThenCreate, @@ -79,7 +79,7 @@ func TestTFPlanRoundTrip(t *testing.T) { DeposedKey: "foodface", ProviderAddr: addrs.AbsProviderConfig{ Provider: addrs.NewDefaultProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ChangeSrc: plans.ChangeSrc{ Action: plans.Delete, @@ -198,7 +198,7 @@ func TestTFPlanRoundTripDestroy(t *testing.T) { }.Instance(addrs.IntKey(0)).Absolute(addrs.RootModuleInstance), ProviderAddr: addrs.AbsProviderConfig{ Provider: addrs.NewDefaultProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ChangeSrc: plans.ChangeSrc{ Action: plans.Delete, diff --git a/providers/addressed_types_test.go b/providers/addressed_types_test.go index 0bf555bba..5b0e90a43 100644 --- a/providers/addressed_types_test.go +++ b/providers/addressed_types_test.go @@ -11,24 +11,24 @@ import ( func TestAddressedTypesAbs(t *testing.T) { providerAddrs := []addrs.AbsProviderConfig{ addrs.AbsProviderConfig{ - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, Provider: addrs.NewLegacyProvider("aws"), }, addrs.AbsProviderConfig{ - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, Provider: addrs.NewLegacyProvider("aws"), Alias: "foo", }, addrs.AbsProviderConfig{ - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, Provider: addrs.NewLegacyProvider("azure"), }, addrs.AbsProviderConfig{ - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, Provider: addrs.NewLegacyProvider("null"), }, addrs.AbsProviderConfig{ - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, Provider: addrs.NewLegacyProvider("null"), }, } diff --git a/repl/session_test.go b/repl/session_test.go index 4ef4c8b78..3e4b0fda4 100644 --- a/repl/session_test.go +++ b/repl/session_test.go @@ -47,7 +47,7 @@ func TestSession_basicState(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) s.SetResourceInstanceCurrent( @@ -62,7 +62,7 @@ func TestSession_basicState(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewLegacyProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) }) diff --git a/states/state_test.go b/states/state_test.go index ef481a6e6..7feb252a4 100644 --- a/states/state_test.go +++ b/states/state_test.go @@ -37,7 +37,7 @@ func TestState(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewDefaultProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) @@ -81,7 +81,7 @@ func TestState(t *testing.T) { }, ProviderConfig: addrs.AbsProviderConfig{ Provider: addrs.NewDefaultProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, }, }, @@ -144,7 +144,7 @@ func TestStateDeepCopy(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewDefaultProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) rootModule.SetResourceInstanceCurrent( @@ -171,7 +171,7 @@ func TestStateDeepCopy(t *testing.T) { }, addrs.AbsProviderConfig{ Provider: addrs.NewDefaultProvider("test"), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, }, ) diff --git a/states/statemgr/testing.go b/states/statemgr/testing.go index 2ded9ac7a..aab2c393a 100644 --- a/states/statemgr/testing.go +++ b/states/statemgr/testing.go @@ -152,7 +152,7 @@ func TestFullInitialState() *states.State { } providerAddr := addrs.AbsProviderConfig{ Provider: rAddr.DefaultProvider(), - Module: addrs.RootModuleInstance, + Module: addrs.RootModule, } childMod.SetResourceMeta(rAddr, states.EachList, providerAddr) return state