Terraform module from git repo - how to exclude directories from being cloned by terraform init?

We have a terraform module developed and kept it inside a repo and people access it by putting below in their main.tf

module "standard_ingress" {
   source = "git::https://xxx.xx.xx/scm/xxxx/xxxx-terraform-eks-ingress-module.git?ref=master"

When they do terraform init whole repo is being cloned to folder (~/.terraform/modules/standard_ingress)

We have some non terraform module related folders as well in the same repo and same branch. Is there a way, we can make terraform init exclude those folders being cloned.


The design of Git itself, means you can’t clone just a subtree of a repository.

Git has some limited options for only checking out parts of a repository after a clone, but there’s no way to interface with them through the automatic fetching provided by Terraform.

Splitting up your Git repository is probably the right way to go here.