Skip to main content

Variable for project root in mounted file relative path configs

I’m trying to create an autoattach context with a mounted file that goes in the working directory. The default working directory is /mnt/workspace/source. But, this can be changed if the stack has a custom project root.

Workaround
Problem
Status: 🗑️ Archived2 comments

Log in to comment and vote

Comments2

  • Black Breeze

    •

    Dec 6, 2025

    This is already available as TF_VAR_spacelift_project_root environment variable. For more background on what’s available, please refer to this document.

    • Coffee Mug

      •

      Dec 8, 2025

      How do I use the environment variable in the path of a mounted file?

      I tried using $TF_VAR_spacelift_project_root in the relative path, but this resulted in a directory with that as the literal name.

      ```

      resource "spacelift_mounted_file" "variables" { context_id = spacelift_context.this.id relative_path = "$TF_VAR_spacelift_project_root/context_variables.tf" content = filebase64("${path.module}/context_files/context_variables.tf") }
      ```

      ```
      [01KBZXS37N2HJVFXGF4HWJGTTR] Initializing workspace with 1 custom hook...

      total 47

      drwxrwxrwx    2 spacelift root            34 Dec  8 23:53 $TF_VAR_spacelift_project_root

      drwxrwxrwx    5 spacelift root         16384 Dec  8 23:53 .

      drwxr-xr-x    1 root     root            23 Dec  8 23:53 ..

      -rw-r--r--    1 spacelift spacelift     10353 Dec  8 23:53 .env_hooks_before

      -rwxrwxrwx    1 spacelift root          1983 Dec  8 23:53 environment.json

      -rwxrwxrwx    1 spacelift root         13792 Dec  8 23:53 metadata.json

      -rwxrwxrwx    1 spacelift root           615 Dec  8 23:53 sdp-app-dev_start_port_forwarding_session.sh

      drwxrwxrwx    7 spacelift root           161 Dec  8 23:53 source

      -rw-r--r--    1 spacelift spacelift      1560 Dec  8 23:53 spacelift.oidc

      drwxrwxrwx    3 spacelift root            44 Dec  8 23:53 workspace_patch
      ```