forked from gruntwork-io/terragrunt
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
50 lines (41 loc) · 1.34 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package main
import (
"os"
"github.com/coveooss/multilogger"
"github.com/coveooss/terragrunt/v2/cli"
"github.com/coveooss/terragrunt/v2/options"
"github.com/coveooss/terragrunt/v2/shell"
"github.com/coveooss/terragrunt/v2/tgerrors"
)
// VERSION is set at build time using -ldflags parameters. For more info, see http://stackoverflow.com/a/11355611/483528
var VERSION = "2.7.13-local"
// The main entrypoint for Terragrunt
func main() {
defer tgerrors.Recover(checkForErrorsAndExit)
app := cli.CreateTerragruntCli(VERSION, os.Stdout, os.Stderr)
err := app.Run(os.Args)
checkForErrorsAndExit(err)
}
// If there is an error, display it in the console and exit with a non-zero exit code. Otherwise, exit 0.
func checkForErrorsAndExit(err error) {
if err == nil {
os.Exit(0)
} else {
logger := multilogger.New("terragrunt")
if _, ok := tgerrors.Unwrap(err).(tgerrors.PlanWithChanges); !ok {
// Plan status are not considered as an error
if os.Getenv(options.EnvDebug) != "" {
logger.Error(tgerrors.PrintErrorWithStackTrace(err))
} else {
logger.Error(err)
}
}
// exit with the underlying error code
exitCode, exitCodeErr := shell.GetExitCode(err)
if exitCodeErr != nil {
exitCode = 1
logger.Error("Unable to determine underlying exit code, so Terragrunt will exit with error code 1")
}
os.Exit(exitCode)
}
}