title: How can I get the relative path of the current director up to an arbitrary parent dir?
body: <p>This is not a module just a workspace.</p>
  <p>Folder structure:</p>
  <pre><code>workspace1
      - workspace2
      - workspace3
          - workspace4
      - workspace5
  </code></pre>
  <p>If I CD into workspace for the full path is: <code>/Users/me/my-files/terraform/workspace1/workspace3/workspace4</code></p>
  <p>How can I use terraform functions to be able to get just the path <code>workspace1/workspace3/workspace4</code></p>
  <p>Is there a way I can get the full path (<a href="https://www.terraform.io/docs/configuration/functions/abspath.html" rel="nofollow noreferrer">https://www.terraform.io/docs/configuration/functions/abspath.html</a>) and then trim out everything before workspace1? perhaps replace() can do that? There are many more features in the latest TF version though I want to check there isn't a feature that makes this easy I could not find in the docs.</p>
  <pre><code># trying to use capture groups doesn't seem to work (just outputs full path)
  locals {
    test = replace(
      abspath(path.root),
      &quot;/(.*)(workspace1.*)&quot;,
      &quot;$2&quot;
    )
  }
  output &quot;test&quot; { value = &quot;${local.test}&quot; 
  </code></pre>
  <h2>Edit</h2>
  <p>This match should work but it's not supported:</p>
  <pre><code>      test = replace(
          abspath(path.root),
          &quot;/.+?(?=workspace1)/&quot;,
          &quot;$1&quot;
  unsupported Perl syntax: `(?=`.
  </code></pre>