From 420324d74fdd542ca07bad9c89ce662062ba5a37 Mon Sep 17 00:00:00 2001 From: jianli-97 Date: Wed, 21 Jun 2023 10:19:37 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E8=BF=9Bterraform=20destroy=E5=87=BD?= =?UTF-8?q?=E6=95=B0tfDestroy,=E5=A2=9E=E5=8A=A0tfInit=E9=98=B6=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/infra/terraform/terraform.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/pkg/infra/terraform/terraform.go b/pkg/infra/terraform/terraform.go index 6a5409a..5d36b01 100644 --- a/pkg/infra/terraform/terraform.go +++ b/pkg/infra/terraform/terraform.go @@ -78,8 +78,13 @@ func tfApply(dir string, platform string, stage Stage, terraformDir string, appl return errors.Wrap(err, "failed to apply Terraform.") } -func tfDestroy(tfFilePath string, terraformBinary string, extraOpts ...tfexec.DestroyOption) error { - tf, err := newTFExec(tfFilePath, terraformBinary) +// terraform destroy +func tfDestroy(dir string, platform string, stage Stage, terraformDir string, destroyOpts ...tfexec.DestroyOption) error { + if err := tfInit(dir, platform, stage.Name(), terraformDir, stage.Providers()); err != nil { + return err + } + + tf, err := newTFExec(dir, terraformDir) if err != nil { return errors.Wrap(err, "failed to create a new tfexec.") } @@ -89,6 +94,8 @@ func tfDestroy(tfFilePath string, terraformBinary string, extraOpts ...tfexec.De // tf.SetStderr() tf.SetLogger(newPrintfer()) - err = tf.Destroy(context.Background(), extraOpts...) - return errors.Wrap(err, "failed to apply Terraform.") + return errors.Wrap( + tf.Destroy(context.Background(), destroyOpts...), + "failed doing terraform destroy.", + ) } -- Gitee