fix: use absolute Terraform plan path
This commit is contained in:
parent
189c79fad0
commit
7ed39b254e
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue