mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
remove more UnkeyedInstanceShim
planning variables and outputs no longer needs module instances
This commit is contained in:
parent
87776913c6
commit
67e06f4fbe
@ -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
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user