title: Reference output from an online nested module within a nested module
body: <p>I have the following file structure:</p>
  <pre><code>├── lambda
  │   ├── main.tf
  ├── main.tf
  </code></pre>
  <p><code>main.tf</code> creates the <code>my_custom_lambda_function</code> module off of the <code>lambda</code> folder.</p>
  <pre><code>module &quot;my_custom_lambda_function&quot; {
    source = &quot;./lambda&quot;
    function_name = &quot;some-name&quot;
  }
  </code></pre>
  <p>Then, I have a nested module within <code>lambda</code> that refers to an online module:</p>
  <pre><code># lambda/main.tf
  variable &quot;function_name&quot; {
    type = string
  }
  
  module &quot;lambda_template&quot; {
    source = &quot;terraform-aws-modules/lambda/aws&quot;
    function_name = &quot;{var.function_name}&quot;
  }
  </code></pre>
  <p>I need to access an output in the module <code>module.lambda_template</code> from <code>module.my_custom_lambda_function</code>. However, when I try to do this:</p>
  <pre><code># lambda/main.tf
  output &quot;function_arn&quot; {
    value = module.lambda_template.this_lambda_function_arn
  }
  </code></pre>
  <p>I get the following error:</p>
  <pre><code>No module call named &quot;lambda_function&quot; is declared in the root module.
  </code></pre>
  <p>Which makes sense, because this syntax is referring to a module within the root. But I want to access the module that is <strong>relative to the module that I'm currently on</strong>. I have not yet found a way to do this. Something like:</p>
  <pre><code># lambda/main.tf
  output &quot;function_arn&quot; {
    value = module.${this}.module.lambda_function.this_lambda_function_arn
  }
  </code></pre>
  <p>Where the value of <code>this</code> would be <code>my_custom_lambda_function</code>.</p>
  <p>This code is not valid syntax, but it expresses what I need. Is there a way to do this within Terraform?</p>