mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-30 10:47:14 -06:00
22eee529e3
We previously built out addrs.UnifyMoveEndpoints with a different implementation strategy in mind, but that design turns out to not be viable because it forces us to move to AbsMoveable addresses too soon, before we've done the analysis required to identify chained and nested moves. Instead, UnifyMoveEndpoints will return a new type MoveEndpointInModule which conceptually represents a matching pattern which either matches or doesn't match a particular AbsMoveable. It does this by just binding the unified relative address from the MoveEndpoint to the module where it was declared, and thus allows us to distinguish between the part of the module path which applies to any instances of the given modules vs. the user-specified part which must identify particular module instances.
34 lines
1019 B
Go
34 lines
1019 B
Go
package addrs
|
|
|
|
import "fmt"
|
|
|
|
// MoveEndpointKind represents the different kinds of object that a movable
|
|
// address can refer to.
|
|
type MoveEndpointKind rune
|
|
|
|
//go:generate go run golang.org/x/tools/cmd/stringer -type MoveEndpointKind
|
|
|
|
const (
|
|
// MoveEndpointModule indicates that a move endpoint either refers to
|
|
// an individual module instance or to all instances of a particular
|
|
// module call.
|
|
MoveEndpointModule MoveEndpointKind = 'M'
|
|
|
|
// MoveEndpointResource indicates that a move endpoint either refers to
|
|
// an individual resource instance or to all instances of a particular
|
|
// resource.
|
|
MoveEndpointResource MoveEndpointKind = 'R'
|
|
)
|
|
|
|
func absMoveableEndpointKind(addr AbsMoveable) MoveEndpointKind {
|
|
switch addr := addr.(type) {
|
|
case ModuleInstance, AbsModuleCall:
|
|
return MoveEndpointModule
|
|
case AbsResourceInstance, AbsResource:
|
|
return MoveEndpointResource
|
|
default:
|
|
// The above should be exhaustive for all AbsMoveable types.
|
|
panic(fmt.Sprintf("unsupported address type %T", addr))
|
|
}
|
|
}
|