-
Notifications
You must be signed in to change notification settings - Fork 17
/
terraformignore.go
43 lines (35 loc) · 1.24 KB
/
terraformignore.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package slug
import (
"fmt"
"os"
"path/filepath"
"github.com/hashicorp/go-slug/internal/ignorefiles"
)
func parseIgnoreFile(rootPath string) *ignorefiles.Ruleset {
// Look for .terraformignore at our root path/src
file, err := os.Open(filepath.Join(rootPath, ".terraformignore"))
defer file.Close()
// If there's any kind of file error, punt and use the default ignore patterns
if err != nil {
// Only show the error debug if an error *other* than IsNotExist
if !os.IsNotExist(err) {
fmt.Fprintf(os.Stderr, "Error reading .terraformignore, default exclusions will apply: %v \n", err)
}
return ignorefiles.DefaultRuleset
}
ret, err := ignorefiles.ParseIgnoreFileContent(file)
if err != nil {
fmt.Fprintf(os.Stderr, "Error reading .terraformignore, default exclusions will apply: %v \n", err)
return ignorefiles.DefaultRuleset
}
return ret
}
func matchIgnoreRules(path string, ruleset *ignorefiles.Ruleset) ignorefiles.ExcludesResult {
// Ruleset.Excludes explicitly allows ignoring its error, in which
// case we are ignoring any individual invalid rules in the set
// but still taking all of the others into account.
ret, _ := ruleset.Excludes(path)
return ret
}