mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
These three types represent the three different address representations we need to represent different stages of analysis for "moved" blocks in the configuration. The goal here is to encapsulate all of the static address wrangling inside these types so that users of these types elsewhere would have to work pretty hard to use them incorrectly. In particular, the MovableEndpoint type intentionally fully encapsulates the weird relative addresses we use in configuration so that code elsewhere in Terraform can never end up holding an address of a type that suggests absolute when it's actually relative. That situation only occurs in the internals of MoveableEndpoint where we use not-really-absolute AbsMoveable address types to represent the not-yet-resolved relative addresses. This only takes care of the static address wrangling. There's lots of other rules for what makes a "moved" block valid which will need to be checked elsewhere because they require more context than just the content of the address itself.
45 lines
1.6 KiB
Go
45 lines
1.6 KiB
Go
package addrs
|
|
|
|
// AbsMoveable is an interface implemented by address types that can be either
|
|
// the source or destination of a "moved" statement in configuration, along
|
|
// with any other similar cross-module state refactoring statements we might
|
|
// allow.
|
|
//
|
|
// Note that AbsMovable represents an absolute address relative to the root
|
|
// of the configuration, which is different than the direct representation
|
|
// of these in configuration where the author gives an address relative to
|
|
// the current module where the address is defined. The type MoveEndpoint
|
|
|
|
type AbsMoveable interface {
|
|
absMoveableSigil()
|
|
|
|
String() string
|
|
}
|
|
|
|
// The following are all of the possible AbsMovable address types:
|
|
var (
|
|
_ AbsMoveable = AbsResource{}
|
|
_ AbsMoveable = AbsResourceInstance{}
|
|
_ AbsMoveable = ModuleInstance(nil)
|
|
_ AbsMoveable = AbsModuleCall{}
|
|
)
|
|
|
|
// ConfigMoveable is similar to AbsMoveable but represents a static object in
|
|
// the configuration, rather than an instance of that object created by
|
|
// module expansion.
|
|
//
|
|
// Note that ConfigMovable represents an absolute address relative to the root
|
|
// of the configuration, which is different than the direct representation
|
|
// of these in configuration where the author gives an address relative to
|
|
// the current module where the address is defined. The type MoveEndpoint
|
|
// represents the relative form given directly in configuration.
|
|
type ConfigMoveable interface {
|
|
configMoveableSigil()
|
|
}
|
|
|
|
// The following are all of the possible ConfigMovable address types:
|
|
var (
|
|
_ ConfigMoveable = ConfigResource{}
|
|
_ ConfigMoveable = Module(nil)
|
|
)
|