Skip to content

Commit

Permalink
Avoid errors when running from the wrong directory
Browse files Browse the repository at this point in the history
  • Loading branch information
jb-abbadie committed Aug 11, 2021
1 parent 70f9d3e commit d395001
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ func main() {
os.Exit(1)
}

tfBinaryPath := installTFProvidedModule(dir, mirrorURL)
tfBinaryPath, err := installTFProvidedModule(dir, mirrorURL)

if err != nil {
fmt.Println("Error occured:", err)
}

exitCode := runTerraform(tfBinaryPath, args[1:]...)
os.Exit(exitCode)
Expand All @@ -39,10 +43,15 @@ func printInvalidTFVersion() {
}

// install when tf file is provided
func installTFProvidedModule(dir string, mirrorURL string) string {
func installTFProvidedModule(dir string, mirrorURL string) (string, error) {
module, _ := tfconfig.LoadModule(dir)

if len(module.RequiredCore) == 0 {
return "", fmt.Errorf("No required_versions found")
}

tfconstraint := module.RequiredCore[0] //we skip duplicated definitions and use only first one
return installFromConstraint(&tfconstraint, mirrorURL)
return installFromConstraint(&tfconstraint, mirrorURL), nil
}

// install using a version constraint
Expand Down

0 comments on commit d395001

Please sign in to comment.