From 7ed39b254e526bf6063c9d94776197ca257e1d1d Mon Sep 17 00:00:00 2001 From: eding Date: Sun, 26 Jul 2026 21:02:24 +0200 Subject: [PATCH] fix: use absolute Terraform plan path --- internal/bootstrap/bootstrap.go | 9 ++++++++- internal/bootstrap/bootstrap_test.go | 7 +++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/internal/bootstrap/bootstrap.go b/internal/bootstrap/bootstrap.go index 90e12c6..575c5e0 100644 --- a/internal/bootstrap/bootstrap.go +++ b/internal/bootstrap/bootstrap.go @@ -564,7 +564,10 @@ func (r Runner) reconcileTerraform(terraformDir string) error { return err } } - planPath := filepath.Join(terraformDir, r.Config.ClusterID+".tfplan") + planPath, err := terraformPlanPath(terraformDir, r.Config.ClusterID) + if err != nil { + return err + } defer os.Remove(planPath) if err := utils.RunCommandInDirEnv(terraformDir, environment, "terraform", "plan", "-input=false", "-out="+planPath); err != nil { return err @@ -572,6 +575,10 @@ func (r Runner) reconcileTerraform(terraformDir string) error { return utils.RunCommandInDirEnv(terraformDir, environment, "terraform", "apply", "-input=false", "-auto-approve", planPath) } +func terraformPlanPath(terraformDir, clusterID string) (string, error) { + return filepath.Abs(filepath.Join(terraformDir, clusterID+".tfplan")) +} + func installSOPSKey(dir string, cfg config.Config) error { if _, err := os.Stat(cfg.SOPS.AgeKeyPath); err != nil { return fmt.Errorf("read SOPS age identity: %w", err) diff --git a/internal/bootstrap/bootstrap_test.go b/internal/bootstrap/bootstrap_test.go index 22f2cf5..67ef04f 100644 --- a/internal/bootstrap/bootstrap_test.go +++ b/internal/bootstrap/bootstrap_test.go @@ -159,3 +159,10 @@ func TestRenderTerraformTFVarsIsStableAndRedactsToken(t *testing.T) { t.Fatalf("Terraform rendering is not deterministic or redacted: %s", first) } } + +func TestTerraformPlanPathIsAbsolute(t *testing.T) { + path, err := terraformPlanPath(filepath.Join("maidn-workspace", "terraform"), "cluster") + if err != nil || !filepath.IsAbs(path) { + t.Fatalf("Terraform plan path is not absolute: %q, %v", path, err) + } +}