mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-23 15:40:07 -06:00
introduce AbsMoveableResource
AbsMoveableResource is an AbsMoveable that is either a resource or a resource instance. This interface represents a moveable that has a resource type.
This commit is contained in:
parent
7162e79fdf
commit
11566b1d11
@ -24,6 +24,19 @@ var (
|
||||
_ AbsMoveable = AbsModuleCall{}
|
||||
)
|
||||
|
||||
// AbsMoveableResource is an AbsMoveable that is either a resource or a resource
|
||||
// instance.
|
||||
type AbsMoveableResource interface {
|
||||
AbsMoveable
|
||||
Type() string
|
||||
}
|
||||
|
||||
// The following are all of the possible AbsMoveableResource types:
|
||||
var (
|
||||
_ AbsMoveableResource = AbsResource{}
|
||||
_ AbsMoveableResource = AbsResourceInstance{}
|
||||
)
|
||||
|
||||
// ConfigMoveable is similar to AbsMoveable but represents a static object in
|
||||
// the configuration, rather than an instance of that object created by
|
||||
// module expansion.
|
||||
|
@ -186,6 +186,10 @@ func (r AbsResource) String() string {
|
||||
return fmt.Sprintf("%s.%s", r.Module.String(), r.Resource.String())
|
||||
}
|
||||
|
||||
func (r AbsResource) Type() string {
|
||||
return r.Resource.Type
|
||||
}
|
||||
|
||||
func (r AbsResource) Equal(o AbsResource) bool {
|
||||
return r.Module.Equal(o.Module) && r.Resource.Equal(o.Resource)
|
||||
}
|
||||
@ -267,6 +271,10 @@ func (r AbsResourceInstance) String() string {
|
||||
return fmt.Sprintf("%s.%s", r.Module.String(), r.Resource.String())
|
||||
}
|
||||
|
||||
func (r AbsResourceInstance) Type() string {
|
||||
return r.Resource.Resource.Type
|
||||
}
|
||||
|
||||
func (r AbsResourceInstance) Equal(o AbsResourceInstance) bool {
|
||||
return r.Module.Equal(o.Module) && r.Resource.Equal(o.Resource)
|
||||
}
|
||||
|
@ -251,29 +251,17 @@ func moveableObjectExists(addr addrs.AbsMoveable, in instances.Set) bool {
|
||||
func resourceTypesDiffer(absFrom, absTo addrs.AbsMoveable) bool {
|
||||
switch absFrom.(type) {
|
||||
case addrs.AbsResourceInstance, addrs.AbsResource:
|
||||
absFrom := absFrom.(addrs.AbsMoveableResource)
|
||||
// addrs.UnifyMoveEndpoints guarantees that both addresses are of the
|
||||
// same kind, so at this point we can assume that absTo is an
|
||||
// same kind, so at this point we can assume that absTo is also an
|
||||
// addrs.AbsResourceInstance or addrs.AbsResource.
|
||||
return absMoveableResourceType(absFrom) != absMoveableResourceType(absTo)
|
||||
absTo := absTo.(addrs.AbsMoveableResource)
|
||||
return absFrom.Type() != absTo.Type()
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// absMoveableResourceType returns the type of the supplied
|
||||
// addrs.AbsResourceInstance or addrs.AbsResource, or "" for other AbsMoveable
|
||||
// types.
|
||||
func absMoveableResourceType(addr addrs.AbsMoveable) string {
|
||||
switch addr := addr.(type) {
|
||||
case addrs.AbsResourceInstance:
|
||||
return addr.Resource.Resource.Type
|
||||
case addrs.AbsResource:
|
||||
return addr.Resource.Type
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
func movableObjectDeclRange(addr addrs.AbsMoveable, cfg *configs.Config) (tfdiags.SourceRange, bool) {
|
||||
switch addr := addr.(type) {
|
||||
case addrs.ModuleInstance:
|
||||
|
Loading…
Reference in New Issue
Block a user