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, }, ) })