Skip to content

git clean deletes module folders when removing .terraform directory #19628

@pmcevoy

Description

@pmcevoy

Terraform Version

Terraform v0.11.10

Also note that this is Windows 10, with git version 2.19.1.windows.1

Expected Behavior

I have authored some modules in a local git repo. Modules are in one path, and terraform files in another path. When I git clean the repo, I expect only .terraform folder to be removed

Actual Behavior

Module files are deleted from the filesystem when the .terraform dir is removed

Steps to Reproduce

From a clean git repo containing terraform modules in one path, and terraform files in another such as:

├───Environment
│   └───DingDev
│       ├───Core
│       ├───Dev
│       └───Networks
└───Modules
    ├───Stripe
    ├───Vpc
    └───Vpn

1 terraform init in (say) the Dev folder which contains .tf files importing modules from the Modules folder

 [master ≡]> terraform init
Initializing modules...
- module.pink
  Getting source "../../../Modules/Stripe"

2 git clean -fxd to remove the .terraform directory:

[master ≡]> git clean -fxd
Removing .terraform/
  1. Discover that all the files in ../../../Modules/Stripe have been removed:
 [master ≡ +0 ~0 -2 !]> git status
On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        deleted:    ../../../Modules/Stripe/inputs.tf
        deleted:    ../../../Modules/Stripe/main.tf

no changes added to commit (use "git add" and/or "git commit -a")

Additional Context

This is my .gitignore:

terraform.tfvars
terraform.tfstate
*.backup
.terraform
*.swp

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions