drivers/azure/azureutil/cleanup.go
func (a AzureClient) cleanupResourceIfExists(r cleanupResource) error {
	f := r.LogFields()
	log.Info(fmt.Sprintf("Attempting to clean up %s resource...", r.ResourceType()), f)
	err := r.Get(a)
	if exists, err := checkResourceExistsFromError(err); err != nil {
		return err
	} else if !exists {
		log.Debug(fmt.Sprintf("%s resource does not exist. Skipping.", r.ResourceType()), f)
		return nil
	}

	if !r.HasAttachedResources() {
		log.Debug(fmt.Sprintf("%s does not have any attached dependent resource.", r.ResourceType()), f)
		log.Info(fmt.Sprintf("Removing %s resource...", r.ResourceType()), f)
		return r.Delete(a)
	}
	log.Info(fmt.Sprintf("%s is still in use by other resources, skipping removal.", r.ResourceType()), f)
	return nil
}
func (a AzureClient) cleanupResourceIfExists(r cleanupResource) error {
	f := r.LogFields()
	log.Info(fmt.Sprintf("Attempting to clean up %s resource...", r.ResourceType()), f)
	err := r.Get(a)
	if exists, err := checkResourceExistsFromError(err); err != nil {
		return err
	} else if !exists {
		log.Debug(fmt.Sprintf("%s resource does not exist. Skipping.", r.ResourceType()), f)
		return nil
	}

	if !r.HasAttachedResources() {
		log.Debug(fmt.Sprintf("%s does not have any attached dependent resource.", r.ResourceType()), f)
		log.Info(fmt.Sprintf("Removing %s resource...", r.ResourceType()), f)
		return r.Delete(a)
	}
	log.Info(fmt.Sprintf("%s is still in use by other resources, skipping removal.", r.ResourceType()), f)
	return nil
}
func ( a AzureClient ) cleanupResourceIfExists ( r cleanupResource ) error { f := r . LogFields ( ) log . Info ( fmt . Sprintf ( " " , r . ResourceType ( ) ) , f ) err := r . Get ( a ) if exists , err := checkResourceExistsFromError ( err ) ; err != nil { return err } else if ! exists { log . Debug ( fmt . Sprintf ( " " , r . ResourceType ( ) ) , f ) return nil } if ! r . HasAttachedResources ( ) { log . Debug ( fmt . Sprintf ( " " , r . ResourceType ( ) ) , f ) log . Info ( fmt . Sprintf ( " " , r . ResourceType ( ) ) , f ) return r . Delete ( a ) } log . Info ( fmt . Sprintf ( " " , r . ResourceType ( ) ) , f ) return nil }
// cleanupResourceIfExists checks if the resource exists, if it does and it
// does not have any attached resources, then deletes the resource. If the
// resource does not exist or is not eligible for cleanup, returns nil. If an
// error is encountered, returns the error.
cleanupResourceIfExists checks if the resource exists if it does and it does not have any attached resources then deletes the resource . If the resource does not exist or is not eligible for cleanup returns nil . If an error is encountered returns the error .