diff --git a/cli/cli_app.go b/cli/cli_app.go index 049791cca..fb39c0c59 100644 --- a/cli/cli_app.go +++ b/cli/cli_app.go @@ -197,7 +197,7 @@ func runTerragrunt(terragruntOptions *options.TerragruntOptions) error { } } - return runTerraformCommand(terragruntOptions) + return shell.RunTerraformCommand(terragruntOptions, terragruntOptions.TerraformCliArgs...) } // Returns true if the command the user wants to execute is supposed to affect multiple Terraform modules, such as the @@ -229,7 +229,7 @@ func downloadModules(terragruntOptions *options.TerragruntOptions) error { return err } if shouldDownload { - return shell.RunShellCommand(terragruntOptions, terragruntOptions.TerraformPath, "get", "-update") + return shell.RunTerraformCommand(terragruntOptions, "get", "-update") } } @@ -314,16 +314,6 @@ func outputAll(terragruntOptions *options.TerragruntOptions) error { return stack.Output(terragruntOptions) } -// Run the given Terraform command -func runTerraformCommand(terragruntOptions *options.TerragruntOptions) error { - return shell.RunShellCommand(terragruntOptions, terragruntOptions.TerraformPath, terragruntOptions.TerraformCliArgs...) -} - -// Run the given Terraform command and return the stdout as a string -func runTerraformCommandAndCaptureOutput(terragruntOptions *options.TerragruntOptions) (string, error) { - return shell.RunShellCommandAndCaptureOutput(terragruntOptions, terragruntOptions.TerraformPath, terragruntOptions.TerraformCliArgs...) -} - // Custom error types var DontManuallyConfigureRemoteState = fmt.Errorf("Instead of manually using the 'remote config' command, define your remote state settings in %s and Terragrunt will automatically configure it for you (and all your team members) next time you run it.", config.DefaultTerragruntConfigPath) diff --git a/cli/download_source.go b/cli/download_source.go index 88274ac1b..d9ad2715b 100644 --- a/cli/download_source.go +++ b/cli/download_source.go @@ -14,6 +14,7 @@ import ( "os" "regexp" "strings" + "github.com/gruntwork-io/terragrunt/shell" ) // This struct represents information about Terraform source code that needs to be downloaded @@ -348,11 +349,6 @@ func getTerraformSourceUrl(terragruntOptions *options.TerragruntOptions, terragr func terraformInit(terraformSource *TerraformSource, terragruntOptions *options.TerragruntOptions) error { terragruntOptions.Logger.Printf("Downloading Terraform configurations from %s into %s", terraformSource.CanonicalSourceURL, terraformSource.DownloadDir) - terragruntInitOptions := terragruntOptions.Clone(terragruntOptions.TerragruntConfigPath) - // Backend and get configuration will be handled separately - terragruntInitOptions.TerraformCliArgs = []string{"init", "-backend=false", "-get=false"} - terragruntInitOptions.TerraformCliArgs = append(terragruntInitOptions.TerraformCliArgs, terraformSource.CanonicalSourceURL.String(), terraformSource.DownloadDir) - - return runTerraformCommand(terragruntInitOptions) + return shell.RunTerraformCommand(terragruntOptions, "init", "-backend=false", "-get=false", terraformSource.CanonicalSourceURL.String(), terraformSource.DownloadDir) } diff --git a/cli/version_check.go b/cli/version_check.go index bd8705afa..9ed32437c 100644 --- a/cli/version_check.go +++ b/cli/version_check.go @@ -6,6 +6,7 @@ import ( "github.com/gruntwork-io/terragrunt/options" "github.com/hashicorp/go-version" "regexp" + "github.com/gruntwork-io/terragrunt/shell" ) // The terraform --version output is of the format: Terraform v0.9.3 @@ -38,10 +39,7 @@ func checkTerraformVersionMeetsConstraint(currentVersion *version.Version, const // Get the currently installed version of Terraform func getTerraformVersion(terragruntOptions *options.TerragruntOptions) (*version.Version, error) { - terragruntOptionsCopy := terragruntOptions.Clone(terragruntOptions.TerragruntConfigPath) - terragruntOptionsCopy.TerraformCliArgs = []string{"--version"} - - output, err := runTerraformCommandAndCaptureOutput(terragruntOptionsCopy) + output, err := shell.RunTerraformCommandAndCaptureOutput(terragruntOptions, "--version") if err != nil { return nil, err } diff --git a/remote/remote_state.go b/remote/remote_state.go index b4b0ba75a..c71a8b35a 100644 --- a/remote/remote_state.go +++ b/remote/remote_state.go @@ -64,7 +64,7 @@ func (remoteState RemoteState) ConfigureRemoteState(terragruntOptions *options.T } terragruntOptions.Logger.Printf("Configuring remote state for the %s backend", remoteState.Backend) - return shell.RunShellCommand(terragruntOptions, terragruntOptions.TerraformPath, initCommand(remoteState)...) + return shell.RunTerraformCommand(terragruntOptions, initCommand(remoteState)...) } return nil diff --git a/shell/run_shell_cmd.go b/shell/run_shell_cmd.go index 6b537ac3e..e6d281bc0 100644 --- a/shell/run_shell_cmd.go +++ b/shell/run_shell_cmd.go @@ -14,6 +14,16 @@ import ( "github.com/gruntwork-io/terragrunt/options" ) +// Run the given Terraform command +func RunTerraformCommand(terragruntOptions *options.TerragruntOptions, args ...string) error { + return RunShellCommand(terragruntOptions, terragruntOptions.TerraformPath, args...) +} + +// Run the given Terraform command and return the stdout as a string +func RunTerraformCommandAndCaptureOutput(terragruntOptions *options.TerragruntOptions, args ...string) (string, error) { + return RunShellCommandAndCaptureOutput(terragruntOptions, terragruntOptions.TerraformPath, args...) +} + // Run the specified shell command with the specified arguments. Connect the command's stdin, stdout, and stderr to // the currently running app. func RunShellCommand(terragruntOptions *options.TerragruntOptions, command string, args ...string) error {