@@ -5,11 +5,8 @@ import (
5
5
"encoding/json"
6
6
"errors"
7
7
"fmt"
8
- "io/fs"
9
8
"log"
10
- "os"
11
9
"os/exec"
12
- "path/filepath"
13
10
"strings"
14
11
"sync"
15
12
@@ -90,36 +87,6 @@ type TfSchemaAttribute struct {
90
87
Type string
91
88
}
92
89
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
-
123
90
func extractProviderNameFromResourceType (resourceType string ) (string , error ) {
124
91
s := strings .SplitN (resourceType , "_" , 2 )
125
92
if len (s ) < 2 {
@@ -145,17 +112,6 @@ func detectProviderName(resource hclwrite.Block) (string, error) {
145
112
}
146
113
147
114
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
-
159
115
providerSchemasMapLock .Lock ()
160
116
defer providerSchemasMapLock .Unlock ()
161
117
@@ -164,8 +120,12 @@ func getResourceSchema(resourceType string, resource hclwrite.Block, dir string,
164
120
providerSchemas = & ProviderSchemas {}
165
121
166
122
// Use tofu by default (if it exists).
123
+
167
124
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 {
169
129
name = "tofu"
170
130
}
171
131
0 commit comments