Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: avoid ignoring hidden tfvars files #968

Merged
merged 1 commit into from
Jun 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions internal/terraform/ast/ast.go

This file was deleted.

18 changes: 15 additions & 3 deletions internal/terraform/ast/module.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 5 additions & 3 deletions internal/terraform/ast/variables.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down