Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 557
mltsy Avatar asked Nov 19 '25 13:11

mltsy


2 Answers

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. 🎉

like image 153
mltsy Avatar answered Nov 22 '25 03:11

mltsy


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

like image 32
Polymerase Avatar answered Nov 22 '25 03:11

Polymerase



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!