driftctl/pkg/remote/resource_enumeration_error_...

38 lines
931 B
Go
Raw Normal View History

package remote
import (
"fmt"
2021-02-11 11:21:49 +00:00
"strings"
"github.com/sirupsen/logrus"
remoteerror "github.com/cloudskiff/driftctl/pkg/remote/error"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/cloudskiff/driftctl/pkg/alerter"
)
func HandleResourceEnumerationError(err error, alertr *alerter.Alerter) error {
listError, ok := err.(*remoteerror.ResourceEnumerationError)
if !ok {
return err
}
reqerr, ok := listError.RootCause().(awserr.RequestFailure)
if !ok {
return err
}
2021-02-11 11:21:49 +00:00
if reqerr.StatusCode() == 403 || (reqerr.StatusCode() == 400 && strings.Contains(reqerr.Code(), "AccessDenied")) {
message := fmt.Sprintf("Ignoring %s from drift calculation: Listing %s is forbidden.", listError.SupplierType(), listError.ListedTypeError())
logrus.Debugf(message)
alertr.SendAlert(listError.SupplierType(), alerter.Alert{
Message: message,
ShouldIgnoreResource: true,
})
return nil
}
return err
}