From b9cf0ae7b4a128abebcd836a4e6419db1ff19515 Mon Sep 17 00:00:00 2001 From: liu-hm19 Date: Thu, 28 Mar 2024 11:26:32 +0800 Subject: [PATCH] fix: terraform installation (#971) --- pkg/cmd/build/util.go | 4 ++-- pkg/cmd/init/init.go | 2 +- pkg/engine/runtime/terraform/install.go | 14 +++++++++++--- test/e2e/kusionctl_test.go | 2 +- 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/pkg/cmd/build/util.go b/pkg/cmd/build/util.go index 984fadb5..1f73e14a 100644 --- a/pkg/cmd/build/util.go +++ b/pkg/cmd/build/util.go @@ -22,10 +22,10 @@ import ( func IntentWithSpinner(o *builders.Options, proj *v1.Project, stack *v1.Stack, ws *v1.Workspace) (*v1.Intent, error) { var sp *pterm.SpinnerPrinter if o.NoStyle { - fmt.Printf("Generating Intent in the Stack %s...\n", stack.Name) + fmt.Printf("Generating Spec in the Stack %s...\n", stack.Name) } else { sp = &pretty.SpinnerT - sp, _ = sp.Start(fmt.Sprintf("Generating Intent in the Stack %s...", stack.Name)) + sp, _ = sp.Start(fmt.Sprintf("Generating Spec in the Stack %s...", stack.Name)) } // style means color and prompt here. Currently, sp will be nil only when o.NoStyle is true diff --git a/pkg/cmd/init/init.go b/pkg/cmd/init/init.go index 96b8af73..06565112 100644 --- a/pkg/cmd/init/init.go +++ b/pkg/cmd/init/init.go @@ -43,7 +43,7 @@ func NewCmd() *cobra.Command { } cmd.Flags().StringVarP(&o.ProjectDir, "target", "t", "", - i18n.T("specify the target direcotry")) + i18n.T("specify the target directory")) return cmd } diff --git a/pkg/engine/runtime/terraform/install.go b/pkg/engine/runtime/terraform/install.go index ff20581a..dcbef9b5 100644 --- a/pkg/engine/runtime/terraform/install.go +++ b/pkg/engine/runtime/terraform/install.go @@ -36,7 +36,7 @@ func (installer *CLIInstaller) CheckAndInstall() error { break } - if i == installer.Intent.Resources.Len() { + if i == installer.Intent.Resources.Len()-1 { return nil } } @@ -56,7 +56,15 @@ func (installer *CLIInstaller) CheckAndInstall() error { // check whether the terraform executable binary has been installed. func checkTerraformExecutable() error { - if err := exec.Command("terraform", "--version").Run(); err == nil { + // select the executable file name according to the operating system. + var executable string + if runtime.GOOS == "windows" { + executable = "terraform.exe" + } else { + executable = "terraform" + } + + if err := exec.Command(executable, "--version").Run(); err == nil { return nil } @@ -65,7 +73,7 @@ func checkTerraformExecutable() error { return err } - execPath := filepath.Join(installDir, "terraform") + execPath := filepath.Join(installDir, executable) if err := exec.Command(execPath, "--version").Run(); err != nil { return err } diff --git a/test/e2e/kusionctl_test.go b/test/e2e/kusionctl_test.go index 125fe239..e57b734f 100644 --- a/test/e2e/kusionctl_test.go +++ b/test/e2e/kusionctl_test.go @@ -12,7 +12,7 @@ import ( path := filepath.Join(GetWorkDir(), "konfig", "example", "service-multi-stack", "dev") output, err := ExecKusionWithWorkDir("kusion build", path) gomega.Expect(err).ShouldNot(gomega.HaveOccurred()) - gomega.Expect(output).To(gomega.ContainSubstring("Generating Intent")) + gomega.Expect(output).To(gomega.ContainSubstring("Generating Spec")) }) }) })*/