Skip to content

Commit 46a9706

Browse files
committed
Fix: terragunt should call 'providers schema -json'
1 parent 4369f90 commit 46a9706

File tree

1 file changed

+5
-45
lines changed

1 file changed

+5
-45
lines changed

internal/tfschema/tfschema.go

+5-45
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,8 @@ import (
55
"encoding/json"
66
"errors"
77
"fmt"
8-
"io/fs"
98
"log"
10-
"os"
119
"os/exec"
12-
"path/filepath"
1310
"strings"
1411
"sync"
1512

@@ -90,36 +87,6 @@ type TfSchemaAttribute struct {
9087
Type string
9188
}
9289

93-
func getFolderPathHelper(dir string, suffix string) string {
94-
ret := dir
95-
found := false
96-
97-
filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
98-
if found || err != nil {
99-
return filepath.SkipDir
100-
}
101-
102-
if strings.HasSuffix(path, suffix) {
103-
ret = strings.TrimSuffix(path, suffix)
104-
found = true
105-
}
106-
107-
return nil
108-
})
109-
110-
return ret
111-
}
112-
113-
func getTerragruntCacheFolderPath(dir string) string {
114-
return getFolderPathHelper(dir, "/.terragrunt-cache")
115-
}
116-
117-
func getTerragruntPluginPath(dir string) string {
118-
dir += "/.terragrunt-cache"
119-
120-
return getFolderPathHelper(dir, "/.terraform")
121-
}
122-
12390
func extractProviderNameFromResourceType(resourceType string) (string, error) {
12491
s := strings.SplitN(resourceType, "_", 2)
12592
if len(s) < 2 {
@@ -145,17 +112,6 @@ func detectProviderName(resource hclwrite.Block) (string, error) {
145112
}
146113

147114
func getResourceSchema(resourceType string, resource hclwrite.Block, dir string, iacType common.IACType, defaultToTerraform bool) (*ResourceSchema, error) {
148-
if iacType == common.Terragrunt {
149-
// try to locate a .terragrunt-cache cache folder.
150-
dir = getTerragruntCacheFolderPath(dir)
151-
152-
// which mode of terragrunt it is (with or without cache folder).
153-
if _, err := os.Stat(dir + "/.terragrunt-cache"); err == nil {
154-
// try to locate a .terrafrom cache folder within the .terragrunt-cache cache folder.
155-
dir = getTerragruntPluginPath(dir)
156-
}
157-
}
158-
159115
providerSchemasMapLock.Lock()
160116
defer providerSchemasMapLock.Unlock()
161117

@@ -164,8 +120,12 @@ func getResourceSchema(resourceType string, resource hclwrite.Block, dir string,
164120
providerSchemas = &ProviderSchemas{}
165121

166122
// Use tofu by default (if it exists).
123+
167124
name := "terraform"
168-
if _, err := exec.LookPath("tofu"); !defaultToTerraform && err == nil {
125+
// For terragrunt - use terragrunt.
126+
if iacType == common.Terragrunt {
127+
name = "terragrunt"
128+
} else if _, err := exec.LookPath("tofu"); !defaultToTerraform && err == nil {
169129
name = "tofu"
170130
}
171131

0 commit comments

Comments
 (0)