terraform cloud doesn't upload local modules

Created on 24 Sep 2019  路  9Comments  路  Source: hashicorp/terraform

Terraform Version

0.12.9

Terraform Configuration Files

application/main.tf
modules/gke/main.tf

application/main.tf

module "test" {
  source = "../modules/gke"
}

modules/gke/main.tf

resource "random_id" "number" {
  byte_length = 4
}
output "out" {
  value = random_id.number.id
}

Debug Output

Output:
2019/09/24 17:47:05 [DEBUG] Using modified User-Agent: Terraform/0.12.9 TFC/27a9bd569a
Initializing modules...
- test in 

Error: Unreadable module directory

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

Error: Failed to read module directory

Module directory  does not exist or cannot be read.

Error: Unreadable module directory

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

Error: Failed to read module directory

Module directory  does not exist or cannot be read.

Expected Behavior

During development phase i would run terraform plan and terraform apply on the local repo from my laptop. I would expect locally developed modules to be pushed upstream.

Actual Behavior

It looks like terraform cloud pushes modules from .terraform/modules/ directory. If module source is a local reference then there will be no files copied to .terraform/modules/. modules.json looks something like this

{"Modules":[{"Key":"test","Source":"../modules/gke","Dir":"../modules/gke"},{"Key":"","Source":"","Dir":"../modules/gke"}]}

Steps to Reproduce

  1. terraform plan

Additional Context

This is all done with terraform cloud

backenremote bug v0.12

Most helpful comment

I ran into this. Setting a working directory in the workspace settings fixed this for me. I think, setting a working directory tells terraform to upload the entire repo instead of just the local directory.

All 9 comments

I ran into this. Setting a working directory in the workspace settings fixed this for me. I think, setting a working directory tells terraform to upload the entire repo instead of just the local directory.

@dsansot-ru setting working-directory and trigger-prefixes did fix my problem. Thank you!
If this is not a bug I would recommend updating the documentation with an example.

For some reason it seems that terraform cloud behaviour has changed from when I created a module and set of workspaces a few weeks ago to now.

A few weeks ago the General Settings for my workspaces defaulted to Local, now they seem to be defaulting to Remote, which causes the following erros on terraform plan but not terraform init:

Setup failed: Failed terraform init (exit 1): <nil>

Output:
2019/09/27 22:46:54 [DEBUG] Using modified User-Agent: Terraform/0.12.6 TFC/f2eb5615d6
Initializing modules...

- ecsCluster in 
Error: Unreadable module directory

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


Error: Failed to read module directory

Module directory  does not exist or cannot be read.


Error: Unreadable module directory

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


Error: Failed to read module directory

Module directory  does not exist or cannot be read.

can you help me understand what do you mean by setting working directory in workspace settings

We have throw-away workspace environments based on feature branches that are created dynamically via the cli. Is there a way to programmatically set "working directory"? Is there a way to configure "working directory" via the backend config? In its current state, it is unrealistic for us to manually update "working directory" for every feature branch.

I am having the same behavior with version 0.13.1, with terraform state in terraform cloud, during development the repos are not connected via VCS but I am running the commands manually.

terraform init runs fine but no modules are uploaded in the .terraform directory with the modules.json file pointing to the relative paths.

terraform plan fails:


Error: Unreadable module directory

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


Error: Failed to read module directory

Module directory  does not exist or cannot be read.


Error: Unreadable module directory

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


Error: Failed to read module directory

Module directory  does not exist or cannot be read.

@marko7460 and @dsansot-ru I am stuck badly and I am not able to find any refrences to working-directory and trigger-prefixes in any documentation.

Appreciate it if you could confirm what exact directory in your above example did you enter in your Workspace Settings? Did you enter ./application/ as the working directory?

@AllanXu49, it's been awhile, so it is a bit fuzzy, and I don't think we have any workspaces set up that would hit this issue...

But, what I believe I meant when you go to Terraform Cloud->Workspaces->->Settings->General, if the workspace has remote execution mode set, then there is a field "Terraform Working Directory" that you can set.

I don't know what trigger-prefixes refers to.

Or just switch to Local in your T Cloud workspace. Settings -> General -> Local. For the directory, use the directory you are running your module against. ie Root -> Dev -> Main; Modules -> Servers ; Network . If you are running in Dev main.tf. change pwd to Dev. I may be wrong

Was this page helpful?
0 / 5 - 0 ratings