'Terraform cloud failing when referencing module using relative local path

I have a repository with several separate configs which share some modules, and reference those modules using relative paths that look like ../../modules/rabbitmq. The directories are setup like this:

tf/
  configs/
    thing-1/
    thing-2/
  modules/
    rabbitmq/
    cluster/
    ...

The configs are setup with a remote backend to use TF Cloud for runs and state:

terraform {
  backend "remote" {
    hostname     = "app.terraform.io"
    organization = "my-org"

    workspaces {
      prefix = "config-1-"
    }
  }
}

Running terraform init works fine. When I try to run terrform plan locally, it gives me an error saying:

Initializing modules...
- rabbitmq in 

Error: Unreadable module directory

Unable to evaluate directory symlink: lstat ../../modules: no such file or
directory

...as if the modules directory isn't being uploaded to TF Cloud or something. What gives?



Solution 1:[1]

It turns out the problem was (surprise, surprise!) it was not uploading the modules directory to TF Cloud. This is because neither the config nor the TF Cloud workspace settings contained any indication that this config folder was part of a larger filesystem. The default is to upload just the directory from which you are running terraform (and all of its contents).

To fix this, I had to visit the "Settings > General" page for the given workspace in Terraform Cloud, and change the Terraform Working Directory setting to specify the path of the config, relative to the relevant root directory - in this case: tf/configs/config-1

After that, running terraform plan displays a message indicating which parent directory it will upload in order to convey the entire context relevant to the workspace. ?

Solution 2:[2]

Update @mlsy answer with a screenshot. Using Terraform Cloud with free account. Resolving module source to using local file system.

terraform version
Terraform v1.1.7
on linux_amd64

Workspace Settings

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 mltsy
Solution 2