-
Notifications
You must be signed in to change notification settings - Fork 2
Description
Bug Report: get_plan_json fails because spacelift.plan.json is missing in Spacelift runner environment
Summary
The SpaceforgePlugin.get_plan_json() helper method consistently fails in a standard Spacelift runner environment because the expected file spacelift.plan.json does not exist. The runner only provides the binary plan file (spacelift.plan).
Expected Behavior
Calling self.get_plan_json() should automatically return the parsed JSON content of the current Terraform/OpenTofu plan, either by reading a pre-existing JSON file or converting the binary plan on demand.
Actual Behavior
The method returns None and logs an error: spacelift.plan.json does not exist.
Evidence
- File Listing: Debugging output from the plugin execution in a Spacelift runner shows the file
spacelift.planexists in the workspace root, butspacelift.plan.jsonis absent.(Overmind) Files in /mnt/workspace/source: ..., .terraform, spacelift.plan (Overmind) spacelift.plan.json does not exist. - Framework Code: The implementation of
get_plan_jsoninspaceforge/plugin.pysimply attempts to readspacelift.plan.jsonwithout any fallback logic to convert the binary plan.def get_plan_json(self) -> Optional[Dict[str, Any]]: plan_json = f"{self._workspace_root}/spacelift.plan.json" if not os.path.exists(plan_json): self.logger.error("spacelift.plan.json does not exist.") return None # ...
- Test Gap: The unit test
test_should_return_plan_data_when_plan_file_existspasses because it manually writes a JSON file to the test directory, masking the fact that the real environment doesn't provide it. - Workaround Required: To make the plugin work, we had to manually implement a fallback in the plugin code that detects the available IAC tool (
terraformortofu) and runsshow -json spacelift.plan.
Impact
Any plugin developers relying on get_plan_json() as documented will find it broken in production unless Spacelift is specifically configured to generate that JSON artifact (which is not the default).
Suggested Fix
Update SpaceforgePlugin.get_plan_json() to:
- Check for
spacelift.plan.jsonfirst. - If missing, check for
spacelift.plan. - If binary plan exists, convert it using
terraform show -json(ortofu) and return the parsed result.