add AffectedAbsResource to interface

This commit is contained in:
Katy Moe 2021-11-16 18:19:11 +00:00
parent 11566b1d11
commit aeecc6a627
No known key found for this signature in database
GPG Key ID: 8C3780F6DCDDA885
3 changed files with 13 additions and 9 deletions

View File

@ -28,7 +28,7 @@ var (
// instance.
type AbsMoveableResource interface {
AbsMoveable
Type() string
AffectedAbsResource() AbsResource
}
// The following are all of the possible AbsMoveableResource types:

View File

@ -186,8 +186,9 @@ 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
// AffectedAbsResource returns the AbsResource.
func (r AbsResource) AffectedAbsResource() AbsResource {
return r
}
func (r AbsResource) Equal(o AbsResource) bool {
@ -271,8 +272,12 @@ 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
// AffectedAbsResource returns the AbsResource for the instance.
func (r AbsResourceInstance) AffectedAbsResource() AbsResource {
return AbsResource{
Module: r.Module,
Resource: r.Resource.Resource,
}
}
func (r AbsResourceInstance) Equal(o AbsResourceInstance) bool {

View File

@ -249,14 +249,13 @@ 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)
switch absFrom := absFrom.(type) {
case addrs.AbsMoveableResource:
// addrs.UnifyMoveEndpoints guarantees that both addresses are of the
// same kind, so at this point we can assume that absTo is also an
// addrs.AbsResourceInstance or addrs.AbsResource.
absTo := absTo.(addrs.AbsMoveableResource)
return absFrom.Type() != absTo.Type()
return absFrom.AffectedAbsResource().Resource.Type != absTo.AffectedAbsResource().Resource.Type
default:
return false
}