diff --git a/internal/terraform/ast/ast.go b/internal/terraform/ast/ast.go deleted file mode 100644 index c8b123b58..000000000 --- a/internal/terraform/ast/ast.go +++ /dev/null @@ -1,13 +0,0 @@ -package ast - -import ( - "strings" -) - -// isIgnoredFile returns true if the given filename (which must not have a -// directory path ahead of it) should be ignored as e.g. an editor swap file. -func isIgnoredFile(name string) bool { - return strings.HasPrefix(name, ".") || // Unix-like hidden files - strings.HasSuffix(name, "~") || // vim - strings.HasPrefix(name, "#") && strings.HasSuffix(name, "#") // emacs -} diff --git a/internal/terraform/ast/module.go b/internal/terraform/ast/module.go index 0600d7497..4d6da63bd 100644 --- a/internal/terraform/ast/module.go +++ b/internal/terraform/ast/module.go @@ -17,9 +17,21 @@ func (mf ModFilename) IsJSON() bool { } func IsModuleFilename(name string) bool { - return (strings.HasSuffix(name, ".tf") || - strings.HasSuffix(name, ".tf.json")) && - !isIgnoredFile(name) + if isIgnoredFile(name) { + // See https://github.com/hashicorp/terraform/blob/d35bc05/internal/configs/parser_config_dir.go#L107 + return false + } + + return strings.HasSuffix(name, ".tf") || + strings.HasSuffix(name, ".tf.json") +} + +// isIgnoredFile returns true if the given filename (which must not have a +// directory path ahead of it) should be ignored as e.g. an editor swap file. +func isIgnoredFile(name string) bool { + return strings.HasPrefix(name, ".") || // Unix-like hidden files + strings.HasSuffix(name, "~") || // vim + strings.HasPrefix(name, "#") && strings.HasSuffix(name, "#") // emacs } type ModFiles map[ModFilename]*hcl.File diff --git a/internal/terraform/ast/variables.go b/internal/terraform/ast/variables.go index 29b595c5b..af0197903 100644 --- a/internal/terraform/ast/variables.go +++ b/internal/terraform/ast/variables.go @@ -16,9 +16,11 @@ func NewVarsFilename(name string) (VarsFilename, bool) { } func IsVarsFilename(name string) bool { - return (strings.HasSuffix(name, ".tfvars") || - strings.HasSuffix(name, ".tfvars.json")) && - !isIgnoredFile(name) + // even files which are normally ignored/hidden, + // such as .foo.tfvars (with leading .) are accepted here + // see https://github.com/hashicorp/terraform/blob/77e6b62/internal/command/meta.go#L734-L738 + return strings.HasSuffix(name, ".tfvars") || + strings.HasSuffix(name, ".tfvars.json") } func (vf VarsFilename) String() string {