Score:0

Terraform init error: Failed to download module (local changes would be overwritten)

cd flag

I have a brand-new local Terraform project that I have just cloned from gitlab. 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:

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.

What am I missing?

Score:1
in flag

It seems like you are having the same issue mentioned here, which is more of a Git behaviour then Terraform. Try adding the short-term workaround mentioned in this Github issue (by adding --depth in your module source.

However, if it's running multiple git commands in series that exacerbates this problem then a short-term workaround (until this can be addressed upstream in Git) might be to set the query argument depth=1 in your source address, like github.com/foo/bar?ref=v1.2.3&depth=1. In the current implementation it happens that Terraform implements shallow clone mode by running git clone --depth=1 --branch=v1.2.3, which avoids the need for the separate checkout step although I don't recall off the top of my head whether Git will accept what looks like a tag name as a valid --branch= in this context, or whether it specifically requires a refs/heads/... reference.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.