mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-28 01:41:48 -06:00
a3403f2766
Due to how often the state and plan types are referenced throughout Terraform, there isn't a great way to switch them out gradually. As a consequence, this huge commit gets us from the old world to a _compilable_ new world, but still has a large number of known test failures due to key functionality being stubbed out. The stubs here are for anything that interacts with providers, since we now need to do the follow-up work to similarly replace the old terraform.ResourceProvider interface with its replacement in the new "providers" package. That work, along with work to fix the remaining failing tests, will follow in subsequent commits. The aim here was to replace all references to terraform.State and its downstream types with states.State, terraform.Plan with plans.Plan, state.State with statemgr.State, and switch to the new implementations of the state and plan file formats. However, due to the number of times those types are used, this also ended up affecting numerous other parts of core such as terraform.Hook, the backend.Backend interface, and most of the CLI commands. Just as with 5861dbf3fc49b19587a31816eb06f511ab861bb4 before, I apologize in advance to the person who inevitably just found this huge commit while spelunking through the commit history.
82 lines
2.4 KiB
Go
82 lines
2.4 KiB
Go
package terraform
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/hashicorp/terraform/addrs"
|
|
)
|
|
|
|
// NodeModuleRemoved represents a module that is no longer in the
|
|
// config.
|
|
type NodeModuleRemoved struct {
|
|
Addr addrs.ModuleInstance
|
|
}
|
|
|
|
var (
|
|
_ GraphNodeSubPath = (*NodeModuleRemoved)(nil)
|
|
_ GraphNodeEvalable = (*NodeModuleRemoved)(nil)
|
|
_ GraphNodeReferencer = (*NodeModuleRemoved)(nil)
|
|
_ GraphNodeReferenceOutside = (*NodeModuleRemoved)(nil)
|
|
)
|
|
|
|
func (n *NodeModuleRemoved) Name() string {
|
|
return fmt.Sprintf("%s (removed)", n.Addr.String())
|
|
}
|
|
|
|
// GraphNodeSubPath
|
|
func (n *NodeModuleRemoved) Path() addrs.ModuleInstance {
|
|
return n.Addr
|
|
}
|
|
|
|
// GraphNodeEvalable
|
|
func (n *NodeModuleRemoved) EvalTree() EvalNode {
|
|
return &EvalOpFilter{
|
|
Ops: []walkOperation{walkRefresh, walkApply, walkDestroy},
|
|
Node: &EvalCheckModuleRemoved{
|
|
Addr: n.Addr,
|
|
},
|
|
}
|
|
}
|
|
|
|
func (n *NodeModuleRemoved) ReferenceOutside() (selfPath, referencePath addrs.ModuleInstance) {
|
|
// Our "References" implementation indicates that this node depends on
|
|
// the call to the module it represents, which implicitly depends on
|
|
// everything inside the module. That reference must therefore be
|
|
// interpreted in terms of our parent module.
|
|
return n.Addr, n.Addr.Parent()
|
|
}
|
|
|
|
func (n *NodeModuleRemoved) References() []*addrs.Reference {
|
|
// We depend on the call to the module we represent, because that
|
|
// implicitly then depends on everything inside that module.
|
|
// Our ReferenceOutside implementation causes this to be interpreted
|
|
// within the parent module.
|
|
|
|
_, call := n.Addr.CallInstance()
|
|
return []*addrs.Reference{
|
|
{
|
|
Subject: call,
|
|
|
|
// No source range here, because there's nothing reasonable for
|
|
// us to return.
|
|
},
|
|
}
|
|
}
|
|
|
|
// EvalCheckModuleRemoved is an EvalNode implementation that verifies that
|
|
// a module has been removed from the state as expected.
|
|
type EvalCheckModuleRemoved struct {
|
|
Addr addrs.ModuleInstance
|
|
}
|
|
|
|
func (n *EvalCheckModuleRemoved) Eval(ctx EvalContext) (interface{}, error) {
|
|
mod := ctx.State().Module(n.Addr)
|
|
if mod != nil {
|
|
// If we get here then that indicates a bug either in the states
|
|
// module or in an earlier step of the graph walk, since we should've
|
|
// pruned out the module when the last resource was removed from it.
|
|
return nil, fmt.Errorf("leftover module %s in state that should have been removed; this is a bug in Terraform and should be reported", n.Addr)
|
|
}
|
|
return nil, nil
|
|
}
|