Skip to content

Commit

Permalink
Skip hidden directories such as .terraform or .git
Browse files Browse the repository at this point in the history
  • Loading branch information
minamijoyo committed Sep 19, 2019
1 parent 5010efb commit 8353deb
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 3 deletions.
7 changes: 4 additions & 3 deletions tfupdate/file.go
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"
"os"
"path/filepath"
"strings"

"github.com/hashicorp/hcl2/hclwrite"
"github.com/spf13/afero"
Expand Down Expand Up @@ -43,7 +44,7 @@ func UpdateFile(fs afero.Fs, filename string, o Option) error {

// UpdateDir updates version constraints for files in a given directory.
// If a recursive flag is true, it checks and updates recursively.
// It skips a .terraform directory because it may contain module code.
// skip hidden directories such as .terraform or .git.
// It also skips a file without .tf extension.
func UpdateDir(fs afero.Fs, dirname string, recursive bool, o Option) error {
dir, err := afero.ReadDir(fs, dirname)
Expand All @@ -60,8 +61,8 @@ func UpdateDir(fs afero.Fs, dirname string, recursive bool, o Option) error {
// skip directory if a recursive flag is false
continue
}
if entry.Name() == ".terraform" {
// skip a .terraform directory because it may contain module code.
if strings.HasPrefix(entry.Name(), ".") {
// skip hidden directories such as .terraform or .git
continue
}

Expand Down
32 changes: 32 additions & 0 deletions tfupdate/file_test.go
Expand Up @@ -268,6 +268,38 @@ terraform {
provider "aws" {
version = "2.11.0"
}
`,
},
{
rootdir: "a",
subdir: ".git",
filename1: "terraform.tf",
src1: `
terraform {
required_version = "0.12.6"
}
`,
filename2: "provider.tf",
src2: `
provider "aws" {
version = "2.11.0"
}
`,
checkdir: "a",
recursive: true,
o: Option{
updateType: "terraform",
target: "0.12.7",
},
want1: `
terraform {
required_version = "0.12.6"
}
`,
want2: `
provider "aws" {
version = "2.11.0"
}
`,
},
{
Expand Down

0 comments on commit 8353deb

Please sign in to comment.