diff --git a/pkg/compute/models/elasticcache_instances.go b/pkg/compute/models/elasticcache_instances.go index 227abffe47..60da874dcb 100644 --- a/pkg/compute/models/elasticcache_instances.go +++ b/pkg/compute/models/elasticcache_instances.go @@ -19,6 +19,7 @@ import ( "fmt" "regexp" "strings" + "time" "yunion.io/x/jsonutils" "yunion.io/x/log" @@ -697,6 +698,10 @@ func (self *SElasticcache) ValidateDeleteCondition(ctx context.Context) error { return httperrors.NewInvalidStatusError("Elastic cache is locked, cannot delete") } + if self.GetChargeType() == billing.BILLING_TYPE_PREPAID && self.ExpiredAt.Sub(time.Now()).Seconds() > 0 { + return httperrors.NewInvalidStatusError("Elastic cache is not expired, cannot delete") + } + return self.ValidatePurgeCondition(ctx) }