Duplicate modules downloaded while using git repo as source

I’m using remote git repo as source for some of my modules. I have multiple different modules in the remote repo such as vpc , staticconfigs , datasource etc.
I refer remote repo in my module by using source git.

module jfm_static_configs {
    **source = "git@github.com:xxxx/tfv12_modules.git//modules/jfm_static_configs"**
}
module datasource {
    **source = "git@github.com:xxxx/tfv12_modules.git//modules/datasource"**
}
module vpc {
    **source = "git@github.com:xxxx/tfv12_modules.git//modules/network/vpc"**
    name = "test"
}

The remote repo contents are as below

Remote repo has different modules and I import these modules as listed above. When I do a terraform get I notice these modules in report repo are imported to .terraform folder multiple times with the different modules names as listed above.

Duplicate imported remote module & folders

This works fine with out any issues. But when my modules grow in my remote repo the no of imported folders in the .terraform folder will also grow.

Would like to understand whether I’m incorrectly referring the modules or is it the way terraform behaves which does not seem to be right. Is there a way to avoid doing this?

@roshpr my standard practice is using separate repositories per module. I believe that’s the recommended way. I know it sounds like a lot but when you start working with tagging and module versions you will want the flexibility of having different modules (repositories) at different versions.

Hope this helps.

1 Like