Skip to content

Commit 81c977d

Browse files
authored
feat(parser): handle terragrunt as parser binary (#87)
terragrunt needs the --terragrunt-log-disable flag to produce clean JSON output only
1 parent c0cac23 commit 81c977d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

parser/binary-parser.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,19 @@ type BinaryParser struct {
1515

1616
func (j BinaryParser) Parse() (tfjson.Plan, error) {
1717
tfbinary := "terraform"
18+
cmdArgs := []string{"show", "-json", j.fileName}
1819
if tfoverride, ok := os.LookupEnv("TF_BINARY"); ok {
20+
if tfoverride == "terragrunt" {
21+
cmdArgs = append(cmdArgs, "--terragrunt-log-disable")
22+
}
1923
tfbinary = tfoverride
2024
}
21-
cmd := exec.Command(tfbinary, "show", "-json", j.fileName)
25+
cmd := exec.Command(tfbinary, cmdArgs...)
2226
output, err := cmd.CombinedOutput()
2327
if err != nil {
2428
return tfjson.Plan{}, fmt.Errorf(
25-
"error when running 'terraform show -json %s': \n%s\n\n%s",
26-
j.fileName, output, "Make sure you are running in terraform directory and terraform init is done")
29+
"error when running '%s show -json %s': \n%s\n\nMake sure you are running in %s directory and %s init is done",
30+
tfbinary, j.fileName, output, tfbinary, tfbinary)
2731
}
2832
plan := tfjson.Plan{}
2933
err = json.Unmarshal(output, &plan)

0 commit comments

Comments
 (0)