Skip to content

spacelift.plan.json is not actually created and therefore get_plan_json doesn't work #48

@dylanratcliffe

Description

@dylanratcliffe

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

  1. File Listing: Debugging output from the plugin execution in a Spacelift runner shows the file spacelift.plan exists in the workspace root, but spacelift.plan.json is absent.
    (Overmind) Files in /mnt/workspace/source: ..., .terraform, spacelift.plan
    (Overmind) spacelift.plan.json does not exist.
    
  2. Framework Code: The implementation of get_plan_json in spaceforge/plugin.py simply attempts to read spacelift.plan.json without 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
        # ...
  3. Test Gap: The unit test test_should_return_plan_data_when_plan_file_exists passes because it manually writes a JSON file to the test directory, masking the fact that the real environment doesn't provide it.
  4. Workaround Required: To make the plugin work, we had to manually implement a fallback in the plugin code that detects the available IAC tool (terraform or tofu) and runs show -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:

  1. Check for spacelift.plan.json first.
  2. If missing, check for spacelift.plan.
  3. If binary plan exists, convert it using terraform show -json (or tofu) and return the parsed result.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions