From 01176024dfea4bf8c64d41558b234b9e7bb142e6 Mon Sep 17 00:00:00 2001 From: Sergiu Ghitea <28300158+sergiught@users.noreply.github.com> Date: Thu, 10 Aug 2023 12:30:57 +0200 Subject: [PATCH] Minor tweaks --- internal/cli/terraform.go | 29 ++++++++++------------------- 1 file changed, 10 insertions(+), 19 deletions(-) diff --git a/internal/cli/terraform.go b/internal/cli/terraform.go index 068d5a5cd..1071f1685 100644 --- a/internal/cli/terraform.go +++ b/internal/cli/terraform.go @@ -3,7 +3,6 @@ package cli import ( "context" "errors" - "fmt" "os" "os/exec" "path" @@ -94,18 +93,16 @@ func generateTerraformCmdRun(cli *cli, inputs *terraformInputs) func(cmd *cobra. } if terraformProviderCredentialsAreAvailable() { - if err := generateTerraformResourceConfig(cmd.Context(), inputs.OutputDIR); err != nil { - return err + if err := generateTerraformResourceConfig(cmd.Context(), inputs.OutputDIR); err == nil { + cli.renderer.Infof("Terraform resource config files generated successfully in: %q", inputs.OutputDIR) + cli.renderer.Infof( + "Review the config and generate the terraform state by running: \n\n cd %s && ./terraform apply", + inputs.OutputDIR, + ) + cli.renderer.Newline() + + return nil } - - cli.renderer.Infof("Terraform resource config files generated successfully in: %q", inputs.OutputDIR) - cli.renderer.Infof( - "Review the config and generate the terraform state by running: \n\n cd %s && ./terraform apply", - inputs.OutputDIR, - ) - cli.renderer.Newline() - - return nil } cli.renderer.Infof("Terraform resource import files generated successfully in: %q", inputs.OutputDIR) @@ -252,13 +249,7 @@ func generateTerraformResourceConfig(ctx context.Context, outputDIR string) erro // -generate-config-out flag is not supported by terraform-exec, so we do this through exec.Command. cmd := exec.CommandContext(ctx, execPath, "plan", "-generate-config-out=generated.tf") cmd.Dir = absoluteOutputPath - output, err := cmd.CombinedOutput() - if err != nil { - fmt.Printf("%s", output) - return err - } - - return nil + return cmd.Run() } func terraformProviderCredentialsAreAvailable() bool {