From 29839f245b50f64835adaaf4b469a67b2e6bf5f1 Mon Sep 17 00:00:00 2001 From: Stoyan Rachev Date: Fri, 5 Nov 2021 18:24:53 +0200 Subject: [PATCH] Upgrade terraform to 0.15.5 --- build/alicloud/TF_VERSION | 2 +- build/all/TF_VERSION | 2 +- build/aws/TF_VERSION | 2 +- build/azure/TF_VERSION | 2 +- build/equinixmetal/TF_VERSION | 2 +- build/gcp/TF_VERSION | 2 +- build/openstack/TF_VERSION | 2 +- build/slim/TF_VERSION | 2 +- pkg/terraformer/terraformer.go | 5 ++--- pkg/terraformer/terraformer_test.go | 12 ++++++------ test/e2e/binary/binary_test.go | 12 ++++++------ test/utils/fake-terraform/main.go | 20 +++++++++++++++----- test/utils/objects.go | 2 +- 13 files changed, 38 insertions(+), 29 deletions(-) diff --git a/build/alicloud/TF_VERSION b/build/alicloud/TF_VERSION index ecf56ca4..1282fff5 100644 --- a/build/alicloud/TF_VERSION +++ b/build/alicloud/TF_VERSION @@ -1 +1 @@ -0.14.11 +0.15.5 diff --git a/build/all/TF_VERSION b/build/all/TF_VERSION index ecf56ca4..1282fff5 100644 --- a/build/all/TF_VERSION +++ b/build/all/TF_VERSION @@ -1 +1 @@ -0.14.11 +0.15.5 diff --git a/build/aws/TF_VERSION b/build/aws/TF_VERSION index ecf56ca4..1282fff5 100644 --- a/build/aws/TF_VERSION +++ b/build/aws/TF_VERSION @@ -1 +1 @@ -0.14.11 +0.15.5 diff --git a/build/azure/TF_VERSION b/build/azure/TF_VERSION index ecf56ca4..1282fff5 100644 --- a/build/azure/TF_VERSION +++ b/build/azure/TF_VERSION @@ -1 +1 @@ -0.14.11 +0.15.5 diff --git a/build/equinixmetal/TF_VERSION b/build/equinixmetal/TF_VERSION index ecf56ca4..1282fff5 100644 --- a/build/equinixmetal/TF_VERSION +++ b/build/equinixmetal/TF_VERSION @@ -1 +1 @@ -0.14.11 +0.15.5 diff --git a/build/gcp/TF_VERSION b/build/gcp/TF_VERSION index ecf56ca4..1282fff5 100644 --- a/build/gcp/TF_VERSION +++ b/build/gcp/TF_VERSION @@ -1 +1 @@ -0.14.11 +0.15.5 diff --git a/build/openstack/TF_VERSION b/build/openstack/TF_VERSION index ecf56ca4..1282fff5 100644 --- a/build/openstack/TF_VERSION +++ b/build/openstack/TF_VERSION @@ -1 +1 @@ -0.14.11 +0.15.5 diff --git a/build/slim/TF_VERSION b/build/slim/TF_VERSION index ecf56ca4..1282fff5 100644 --- a/build/slim/TF_VERSION +++ b/build/slim/TF_VERSION @@ -1 +1 @@ -0.14.11 +0.15.5 diff --git a/pkg/terraformer/terraformer.go b/pkg/terraformer/terraformer.go index ccf6d021..39781504 100644 --- a/pkg/terraformer/terraformer.go +++ b/pkg/terraformer/terraformer.go @@ -237,6 +237,7 @@ func (t *Terraformer) executeTerraform(ctx context.Context, command Command, par if command == StateReplaceProvider { args = append(args, strings.Split(string(command), " ")...) } else { + args = append(args, "-chdir="+t.paths.ConfigDir) args = append(args, string(command)) } @@ -258,11 +259,9 @@ func (t *Terraformer) executeTerraform(ctx context.Context, command Command, par if command == StateReplaceProvider { args = append(args, params...) - } else { - args = append(args, t.paths.ConfigDir) } - log.Info("executing terraform", "command", command, "args", strings.Join(args[1:], " ")) + log.Info("executing terraform", "command", command, "args", strings.Join(args, " ")) tfCmd := exec.Command(TerraformBinary, args...) logBuffer := &bytes.Buffer{} diff --git a/pkg/terraformer/terraformer_test.go b/pkg/terraformer/terraformer_test.go index f437820d..6144e8d1 100644 --- a/pkg/terraformer/terraformer_test.go +++ b/pkg/terraformer/terraformer_test.go @@ -241,7 +241,7 @@ var _ = Describe("Terraformer", func() { Eventually(logBuffer).Should(gbytes.Say("successfully stored terraform state")) Expect(paths.TerminationMessagePath).To(testutils.BeFileWithContents(And( - ContainSubstring("args: init"), + ContainSubstring("init"), ContainSubstring("some terraform error"), )), "termination log should contain all terraform logs") }) @@ -261,7 +261,7 @@ var _ = Describe("Terraformer", func() { Eventually(logBuffer).Should(gbytes.Say("successfully stored terraform state")) Expect(paths.TerminationMessagePath).To(testutils.BeFileWithContents(And( - ContainSubstring("args: apply"), + ContainSubstring("apply"), ContainSubstring("doing some long running IaaS ops"), ContainSubstring("some terraform error"), )), "termination log should contain all terraform logs") @@ -280,7 +280,7 @@ var _ = Describe("Terraformer", func() { Eventually(logBuffer).Should(gbytes.Say("successfully stored terraform state")) Expect(paths.TerminationMessagePath).To(testutils.BeFileWithContents(And( - ContainSubstring("args: destroy"), + ContainSubstring("destroy"), ContainSubstring("doing some long running IaaS ops"), ContainSubstring("some terraform error"), )), "termination log should contain all terraform logs") @@ -299,7 +299,7 @@ var _ = Describe("Terraformer", func() { Eventually(logBuffer).Should(gbytes.Say("successfully stored terraform state")) Expect(paths.TerminationMessagePath).To(testutils.BeFileWithContents(And( - ContainSubstring("args: validate"), + ContainSubstring("validate"), ContainSubstring("doing some long running IaaS ops"), ContainSubstring("some terraform error"), )), "termination log should contain all terraform logs") @@ -327,8 +327,8 @@ var _ = Describe("Terraformer", func() { Eventually(logBuffer).Should(gbytes.Say("successfully stored terraform state")) Expect(paths.TerminationMessagePath).To(testutils.BeFileWithContents(And( - Not(ContainSubstring("args: validate")), - ContainSubstring("args: plan"), + Not(ContainSubstring("validate")), + ContainSubstring("plan"), ContainSubstring("doing some long running IaaS ops"), ContainSubstring("some terraform error"), )), "termination log should contain all terraform logs") diff --git a/test/e2e/binary/binary_test.go b/test/e2e/binary/binary_test.go index ec848fc8..7780d647 100644 --- a/test/e2e/binary/binary_test.go +++ b/test/e2e/binary/binary_test.go @@ -430,7 +430,7 @@ var _ = Describe("terraformer", func() { It("should return exit code from terraform init", func() { runExitCodeTest("apply", 12) Expect(paths.TerminationMessagePath).To(testutils.BeFileWithContents(And( - ContainSubstring("args: init"), + ContainSubstring("init"), ContainSubstring("some terraform error"), )), "termination log should contain all terraform logs") }) @@ -449,7 +449,7 @@ var _ = Describe("terraformer", func() { It("should return exit code from terraform apply", func() { runExitCodeTest("apply", 42) Expect(paths.TerminationMessagePath).To(testutils.BeFileWithContents(And( - ContainSubstring("args: apply"), + ContainSubstring("apply"), ContainSubstring("doing some long running IaaS ops"), ContainSubstring("some terraform error"), )), "termination log should contain all terraform logs") @@ -457,7 +457,7 @@ var _ = Describe("terraformer", func() { It("should return exit code from terraform destroy", func() { runExitCodeTest("destroy", 43) Expect(paths.TerminationMessagePath).To(testutils.BeFileWithContents(And( - ContainSubstring("args: destroy"), + ContainSubstring("destroy"), ContainSubstring("doing some long running IaaS ops"), ContainSubstring("some terraform error"), )), "termination log should contain all terraform logs") @@ -465,7 +465,7 @@ var _ = Describe("terraformer", func() { It("should return exit code from terraform validate", func() { runExitCodeTest("validate", 44) Expect(paths.TerminationMessagePath).To(testutils.BeFileWithContents(And( - ContainSubstring("args: validate"), + ContainSubstring("validate"), ContainSubstring("doing some long running IaaS ops"), ContainSubstring("some terraform error"), )), "termination log should contain all terraform logs") @@ -482,8 +482,8 @@ var _ = Describe("terraformer", func() { It("should return exit code from terraform plan", func() { runExitCodeTest("validate", 45) Expect(paths.TerminationMessagePath).To(testutils.BeFileWithContents(And( - Not(ContainSubstring("args: validate")), - ContainSubstring("args: plan"), + Not(ContainSubstring("validate")), + ContainSubstring("plan"), ContainSubstring("doing some long running IaaS ops"), ContainSubstring("some terraform error"), )), "termination log should contain all terraform logs") diff --git a/test/utils/fake-terraform/main.go b/test/utils/fake-terraform/main.go index 80a37467..21ad903d 100644 --- a/test/utils/fake-terraform/main.go +++ b/test/utils/fake-terraform/main.go @@ -26,9 +26,10 @@ func main() { fmt.Println("some terraform output") fmt.Println("args: " + strings.Join(os.Args[1:], " ")) - exitCode := getExpectedExitCode() + command := getCommand(os.Args[1:]) + exitCode := getExpectedExitCode(command) - if sleepDuration != "" && (len(os.Args) <= 1 || os.Args[1] != "init") { + if sleepDuration != "" && command != "init" { done := make(chan struct{}) defer close(done) @@ -60,7 +61,17 @@ func main() { os.Exit(exitCode) } -func getExpectedExitCode() int { +func getCommand(args []string) string { + if len(args) < 2 { + return "" + } + if strings.HasPrefix(args[0], "-chdir=") { + return args[1] + } + return args[0] + " " + args[1] +} + +func getExpectedExitCode(command string) int { if expectedExitCodes == "" { return 0 } @@ -73,11 +84,10 @@ func getExpectedExitCode() int { } exitCodes := strings.Split(expectedExitCodes, ",") - if len(exitCodes) == 0 || len(os.Args) <= 1 || os.Args[1] == "" { + if len(exitCodes) == 0 || command == "" { return 0 } - command := os.Args[1] for _, e := range exitCodes { if strings.HasPrefix(e, command+"=") { code, err := strconv.Atoi(strings.TrimPrefix(e, command+"=")) diff --git a/test/utils/objects.go b/test/utils/objects.go index 7076f702..531359d9 100644 --- a/test/utils/objects.go +++ b/test/utils/objects.go @@ -70,7 +70,7 @@ func PrepareTestObjects(ctx context.Context, c client.Client, namespacePrefix st o.StateConfigMap = &corev1.ConfigMap{ ObjectMeta: metav1.ObjectMeta{Name: "tf-state", Namespace: o.Namespace}, Data: map[string]string{ - StateKey: `{"terraform_version":"0.14.11"}`, + StateKey: `{"terraform_version":"0.15.5"}`, }, } err = o.client.Create(ctx, o.StateConfigMap)