diff --git a/terraform/node_module_variable.go b/terraform/node_module_variable.go index 20d6d6df71..a320cb3735 100644 --- a/terraform/node_module_variable.go +++ b/terraform/node_module_variable.go @@ -25,14 +25,13 @@ var ( _ GraphNodeReferenceOutside = (*NodePlannableModuleVariable)(nil) _ GraphNodeReferenceable = (*NodePlannableModuleVariable)(nil) _ GraphNodeReferencer = (*NodePlannableModuleVariable)(nil) - _ GraphNodeModuleInstance = (*NodePlannableModuleVariable)(nil) _ RemovableIfNotTargeted = (*NodePlannableModuleVariable)(nil) ) func (n *NodePlannableModuleVariable) DynamicExpand(ctx EvalContext) (*Graph, error) { var g Graph expander := ctx.InstanceExpander() - for _, module := range expander.ExpandModule(ctx.Path().Module()) { + for _, module := range expander.ExpandModule(n.Module) { o := &NodeApplyableModuleVariable{ Addr: n.Addr.Absolute(module), Config: n.Config, @@ -47,13 +46,6 @@ func (n *NodePlannableModuleVariable) Name() string { return fmt.Sprintf("%s.%s", n.Module, n.Addr.String()) } -// GraphNodeModuleInstance -func (n *NodePlannableModuleVariable) Path() addrs.ModuleInstance { - // Return an UnkeyedInstanceShim as our placeholder, - // given that modules will be unexpanded at this point in the walk - return n.Module.UnkeyedInstanceShim() -} - // GraphNodeModulePath func (n *NodePlannableModuleVariable) ModulePath() addrs.Module { return n.Module diff --git a/terraform/node_output.go b/terraform/node_output.go index e391b1ead9..6aa91da87d 100644 --- a/terraform/node_output.go +++ b/terraform/node_output.go @@ -2,6 +2,7 @@ package terraform import ( "fmt" + "log" "github.com/hashicorp/terraform/addrs" "github.com/hashicorp/terraform/configs" @@ -18,10 +19,8 @@ type NodePlannableOutput struct { } var ( - _ GraphNodeModuleInstance = (*NodePlannableOutput)(nil) - _ RemovableIfNotTargeted = (*NodePlannableOutput)(nil) - _ GraphNodeReferenceable = (*NodePlannableOutput)(nil) - //_ GraphNodeEvalable = (*NodePlannableOutput)(nil) + _ RemovableIfNotTargeted = (*NodePlannableOutput)(nil) + _ GraphNodeReferenceable = (*NodePlannableOutput)(nil) _ GraphNodeReferencer = (*NodePlannableOutput)(nil) _ GraphNodeDynamicExpandable = (*NodePlannableOutput)(nil) ) @@ -29,26 +28,24 @@ var ( func (n *NodePlannableOutput) DynamicExpand(ctx EvalContext) (*Graph, error) { var g Graph expander := ctx.InstanceExpander() - for _, module := range expander.ExpandModule(ctx.Path().Module()) { + for _, module := range expander.ExpandModule(n.Module) { o := &NodeApplyableOutput{ Addr: n.Addr.Absolute(module), Config: n.Config, } - // log.Printf("[TRACE] Expanding output: adding %s as %T", o.Addr.String(), o) + log.Printf("[TRACE] Expanding output: adding %s as %T", o.Addr.String(), o) g.Add(o) } return &g, nil } func (n *NodePlannableOutput) Name() string { - return n.Addr.Absolute(n.Module.UnkeyedInstanceShim()).String() -} - -// GraphNodeModuleInstance -func (n *NodePlannableOutput) Path() addrs.ModuleInstance { - // Return an UnkeyedInstanceShim as our placeholder, - // given that modules will be unexpanded at this point in the walk - return n.Module.UnkeyedInstanceShim() + path := n.Module.String() + addr := n.Addr.String() + if path != "" { + return path + "." + addr + } + return addr } // GraphNodeModulePath @@ -66,9 +63,6 @@ func (n *NodePlannableOutput) ReferenceableAddrs() []addrs.Referenceable { // the output is referenced through the module call, and via the // module itself. _, call := n.Module.Call() - - // FIXME: make something like ModuleCallOutput for this type of reference - // that doesn't need an instance shim callOutput := addrs.ModuleCallOutput{ Call: call.Instance(addrs.NoKey), Name: n.Addr.Name, @@ -247,7 +241,6 @@ type NodeDestroyableOutput struct { } var ( - _ GraphNodeModuleInstance = (*NodeDestroyableOutput)(nil) _ RemovableIfNotTargeted = (*NodeDestroyableOutput)(nil) _ GraphNodeTargetDownstream = (*NodeDestroyableOutput)(nil) _ GraphNodeReferencer = (*NodeDestroyableOutput)(nil) @@ -259,11 +252,6 @@ func (n *NodeDestroyableOutput) Name() string { return fmt.Sprintf("%s (destroy)", n.Addr.String()) } -// GraphNodeModuleInstance -func (n *NodeDestroyableOutput) Path() addrs.ModuleInstance { - return n.Module.UnkeyedInstanceShim() -} - // GraphNodeModulePath func (n *NodeDestroyableOutput) ModulePath() addrs.Module { return n.Module diff --git a/terraform/transform_module_variable.go b/terraform/transform_module_variable.go index 2cbb5cd117..c651358882 100644 --- a/terraform/transform_module_variable.go +++ b/terraform/transform_module_variable.go @@ -58,15 +58,7 @@ func (t *ModuleVariableTransformer) transform(g *Graph, parent, c *configs.Confi } func (t *ModuleVariableTransformer) transformSingle(g *Graph, parent, c *configs.Config) error { - - // Our addressing system distinguishes between modules and module instances, - // but we're not yet ready to make that distinction here (since we don't - // support "count"/"for_each" on modules) and so we just do a naive - // transform of the module path into a module instance path, assuming that - // no keys are in use. This should be removed when "count" and "for_each" - // are implemented for modules. - path := c.Path.UnkeyedInstanceShim() - _, call := path.Call() + _, call := c.Path.Call() // Find the call in the parent module configuration, so we can get the // expressions given for each input variable at the call site. @@ -74,7 +66,7 @@ func (t *ModuleVariableTransformer) transformSingle(g *Graph, parent, c *configs if !exists { // This should never happen, since it indicates an improperly-constructed // configuration tree. - panic(fmt.Errorf("no module call block found for %s", path)) + panic(fmt.Errorf("no module call block found for %s", c.Path)) } // We need to construct a schema for the expected call arguments based on diff --git a/terraform/transform_output.go b/terraform/transform_output.go index 8e19000af9..7eb8e4884e 100644 --- a/terraform/transform_output.go +++ b/terraform/transform_output.go @@ -72,6 +72,11 @@ func (t *DestroyOutputTransformer) Transform(g *Graph) error { continue } + // We only destroy root outputs + if !output.Module.Equal(addrs.RootModule) { + continue + } + // create the destroy node for this output node := &NodeDestroyableOutput{ Addr: output.Addr,