Error: Failed to download module (local changes would be overwritten)

I have a brand-new local git project that I have just cloned. I have not made any changes to the code, but when I run terraform init I get the following error, repeated for every module in the project:

Downloading git::https://<gitlab address> for <module name>...

Error: Failed to download module

Could not download module " <module name>"
(<filename>.tf:<line #>) source code from
"git::<gitlab address>":
error downloading
'<gitlab address>':
C:\Program Files\Git\cmd\git.exe exited with 1: error: Your local changes to
the following files would be overwritten by checkout:
        README.md
Please commit your changes or stash them before you switch branches.
Aborting

Every module download fails on the same file: README.md. Again, I have made no changes to any files in the project.

My initial thought was that this might be related to a line-endling issue: I am using Windows, and the module files in the remote repository were created on a Mac. To address this, I ran the command git config --global core.autocrlf true
(following the recommendations here

I then deleted the .terraform folder and re-ran terraform init, but got the same set of errors.

It’s possible this is purely a git issue, unrelated to terraform, but I have not been able to find any information on possible causes in the git forums, so I thought I’d try here.

Hi @bob.devivo!

This is indeed an error from Git rather than from Terraform, which Terraform is just capturing and returning to you verbatim.

It is a good question though why README.md is appearing to Git as modified when Terraform asks Git to update the local copy of the module to reflect a different commit.

You might be able to get more information here by switching into the directory where Terraform has cached the repository and running git status, git diff, or other such Git commands to ask Git what differences it can see between the working directory and the most recent commit.

You can find this directory as one of the subdirectories under .terraform/modules, which is the directory where current versions of Terraform cache module packages retrieved over the network. For a git:: source, that directory should itself be a git work tree that you can run normal Git commands in. (Terraform itself is also running normal Git commands in that directory, including the one that returned this error.)

Thanks, this led me to an error in the source code of the module that was creating the problem.