diff --git a/pkg/infra/terraform/terraform.go b/pkg/infra/terraform/terraform.go index 1381d8287d023388c65bcd15bf663c43577377c1..6a5409a0bcdce189bbc60d8d292862dcf4d4fdc6 100644 --- a/pkg/infra/terraform/terraform.go +++ b/pkg/infra/terraform/terraform.go @@ -58,8 +58,13 @@ func tfInit(dir string, platform string, target string, terraformDir string, pro ) } -func tfApply(tfFilePath string, terraformBinary string, extraOpts ...tfexec.ApplyOption) error { - tf, err := newTFExec(tfFilePath, terraformBinary) +// terraform apply +func tfApply(dir string, platform string, stage Stage, terraformDir string, applyOpts ...tfexec.ApplyOption) 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.") } @@ -69,7 +74,7 @@ func tfApply(tfFilePath string, terraformBinary string, extraOpts ...tfexec.Appl // tf.SetStderr() tf.SetLogger(newPrintfer()) - err = tf.Apply(context.Background(), extraOpts...) + err = tf.Apply(context.Background(), applyOpts...) return errors.Wrap(err, "failed to apply Terraform.") }