diff --git a/pkg/util/aws/eip.go b/pkg/util/aws/eip.go index ac81461d5d..7e41d8ee9f 100644 --- a/pkg/util/aws/eip.go +++ b/pkg/util/aws/eip.go @@ -1,6 +1,7 @@ package aws import ( + "fmt" "github.com/aws/aws-sdk-go/service/ec2" "yunion.io/x/jsonutils" "yunion.io/x/log" @@ -221,6 +222,10 @@ func (self *SRegion) DissociateEip(eipId string, instanceId string) error { return nil } + if eip.InstanceId != instanceId { + return fmt.Errorf("eip %s associate with another instance %s", eipId, eip.InstanceId) + } + params := &ec2.DisassociateAddressInput{} params.SetAssociationId(eip.AssociationId) _, err = self.ec2Client.DisassociateAddress(params)