Skip to content

Commit

Permalink
Fix: Terragrunt Run-All fails to Tag Azure Resource Group (#189)
Browse files Browse the repository at this point in the history
* Fix: Terragrunt Run-All fails to Tag Azure Resource Group

* updated comments
  • Loading branch information
TomerHeber authored Feb 28, 2024
1 parent 36ff306 commit 9a321e8
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions internal/tfschema/tfschema.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ type TfSchemaAttribute struct {
Type string
}

func getTerragruntPluginPath(dir string) string {
dir += "/.terragrunt-cache"
func getFolderPathHelper(dir string, suffix string) string {
ret := dir
found := false

Expand All @@ -98,9 +97,8 @@ func getTerragruntPluginPath(dir string) string {
return filepath.SkipDir
}

// E.g. ./.terragrunt-cache/yHtqnMrVQOISIYxobafVvZbAAyU/ThyYwttwki6d6AS3aD5OwoyqIWA/.terraform
if strings.HasSuffix(path, "/.terraform") {
ret = strings.TrimSuffix(path, "/.terraform")
if strings.HasSuffix(path, suffix) {
ret = strings.TrimSuffix(path, suffix)
found = true
}

Expand All @@ -110,6 +108,15 @@ func getTerragruntPluginPath(dir string) string {
return ret
}

func getTerragruntCacheFolderPath(dir string) string {
return getFolderPathHelper(dir, "/.terragrunt-cache")
}

func getTerragruntPluginPath(dir string) string {
dir += "/.terragrunt-cache"
return getFolderPathHelper(dir, "/.terraform")
}

func extractProviderNameFromResourceType(resourceType string) (string, error) {
s := strings.SplitN(resourceType, "_", 2)
if len(s) < 2 {
Expand All @@ -134,8 +141,12 @@ func detectProviderName(resource hclwrite.Block) (string, error) {

func getResourceSchema(resourceType string, resource hclwrite.Block, dir string, iacType common.IACType, defaultToTerraform bool) (*ResourceSchema, error) {
if iacType == common.Terragrunt {
// try to locate a .terragrunt-cache cache folder.
dir = getTerragruntCacheFolderPath(dir)

// which mode of terragrunt it is (with or without cache folder).
if _, err := os.Stat(dir + "/.terragrunt-cache"); err == nil {
// try to locate a .terrafrom cache folder within the .terragrunt-cache cache folder.
dir = getTerragruntPluginPath(dir)
}
}
Expand Down

0 comments on commit 9a321e8

Please sign in to comment.