Acceptance Test Error: Failed to read module directory

I wrote some acceptance tests for my terraform provider plugin. Running them with the following command worked perfectly:

TF_ACC=1 go test ./... -v -parallel=4

Recently I updated my project to use the new v2 of the Terraform-Plugin-SDK. Now whenever I run my acceptance tests I get the following errors (I simplified the output):

Step 1/n error: Error running second post-apply plan:
Error: Failed to read file

The file
"$(TMPDIR)/tftest443/work874/config340/terraform_plugin_test.tf"
could not be read

Error: Failed to read directory for module

The source directory
$(TMPDIR)/tftest443/work874/config340
could not be read

It also seems to be somewhat random where it fails. Running the same tests again I sometimes it says the same error occurred during “running post-apply refresh”:

Step 1/n error: Error running post-apply refresh: 
        Error: Failed to read module directory
        
        Module directory
        $(TMPDIR)/tftest178/work507/config547
        does not exist or cannot be read.

The most confusing part: The resources are correctly created, updated and destroyed during the test.

Why do my tests keep throwing these errors although they succeed in creating the test resources? And what do I need to change to make them work again?

It might be the case that parallel execution creates some sort of race condition and things get deleted.

All of the large codebases i’ve worked on didn’t have parallel integration tests, because dependency on webservice you have no full control of makes isolation extremely difficult and not worth it.

This sounds like a bug to me, and I’d love a bug report. Please make sure to include the version of Terraform, the version of the SDK, and the operating system you’re using, and a reproduction case if possible, and we’ll get to the bottom of it. Sorry for the issues. :frowning:

Also, to be clear: It literally says $(TMPDIR), right? That’s not you modifying the path?

After some experimenting I just found out that this issue is related to the default temp directory that the testing framework uses to maintain config- and state-files for the acceptance tests.

Per default the directory stored under the environment variable TMPDIR is used. On macOS it is /var/folders/{random 2 letters}/{random string}/T/.
I think the bug is connected to the path length of generated config/state files being too long for the OS (Unix domain socket path limit “UNIX_PATH_MAX” is 108).

Creating a custom temporary folder in the working directory and setting TF_ACC_TEMP_DIR to it is a work-around for this problem.

1 Like

That’s upsetting! I’m glad there’s a workaround, we’re going to have to investigate some potential fixes for this so we can solve it without using environment variable workarounds. I appreciate you opening the bug on GitHub, and we’ll definitely keep it updated as we figure out how we want to address this.

1 Like

@paddy bug is there - https://github.com/hashicorp/terraform-plugin-sdk/issues/598