From 7b2db4ca87ed5b36dc3d8473183e7ddc6664bfa9 Mon Sep 17 00:00:00 2001 From: msfendourakis Date: Mon, 1 Feb 2021 12:24:44 +0200 Subject: [PATCH] skip warnings on commented out and empty lines --- pkg/filter/driftignore.go | 56 +++++++++++++++++++++------------------ 1 file changed, 30 insertions(+), 26 deletions(-) diff --git a/pkg/filter/driftignore.go b/pkg/filter/driftignore.go index 54bf14d7..9a94f484 100644 --- a/pkg/filter/driftignore.go +++ b/pkg/filter/driftignore.go @@ -39,36 +39,40 @@ func (r *DriftIgnore) readIgnoreFile() error { line := scanner.Text() typeVal := readDriftIgnoreLine(line) nbArgs := len(typeVal) - if nbArgs < 2 { - logrus.WithFields(logrus.Fields{ - "line": line, - }).Warnf("unable to parse line, invalid length, got %d expected >= 2", nbArgs) - continue - } - if nbArgs == 2 { // We want to ignore a resource (type.id) + if nbArgs == 0 || strings.HasPrefix(line, "#") { + continue // skip empty or commented out lines + } else { + if nbArgs < 2 { + logrus.WithFields(logrus.Fields{ + "line": line, + }).Warnf("unable to parse line, invalid length, got %d expected >= 2", nbArgs) + continue + } + if nbArgs == 2 { // We want to ignore a resource (type.id) + logrus.WithFields(logrus.Fields{ + "type": typeVal[0], + "id": typeVal[1], + }).Debug("Found ignore resource rule in .driftignore") + r.resExclusionList[strings.Join(typeVal, ".")] = struct{}{} + continue + } + // Here we want to ignore a drift (type.id.path.to.field) + res := strings.Join(typeVal[0:2], ".") + ignoreSublist, exists := r.driftExclusionList[res] + if !exists { + ignoreSublist = make([]string, 0, 1) + } + path := strings.Join(typeVal[2:], ".") + logrus.WithFields(logrus.Fields{ "type": typeVal[0], "id": typeVal[1], - }).Debug("Found ignore resource rule in .driftignore") - r.resExclusionList[strings.Join(typeVal, ".")] = struct{}{} - continue - } - // Here we want to ignore a drift (type.id.path.to.field) - res := strings.Join(typeVal[0:2], ".") - ignoreSublist, exists := r.driftExclusionList[res] - if !exists { - ignoreSublist = make([]string, 0, 1) - } - path := strings.Join(typeVal[2:], ".") + "path": path, + }).Debug("Found ignore resource field rule in .driftignore") - logrus.WithFields(logrus.Fields{ - "type": typeVal[0], - "id": typeVal[1], - "path": path, - }).Debug("Found ignore resource field rule in .driftignore") - - ignoreSublist = append(ignoreSublist, path) - r.driftExclusionList[res] = ignoreSublist + ignoreSublist = append(ignoreSublist, path) + r.driftExclusionList[res] = ignoreSublist + } } if err := scanner.Err(); err != nil {