Is it possible to use `.gitattributes` to limit what is packaged/downloaded for a module?

We’ve got some terraform modules (1 public and a load private).

For the public one, we’d like to slim down the exact content downloaded to be just the relevant code for the module.

Currently, all the tests, and pipeline related code is also downloaded.

With other git based repos, the use of .gitattributes is used. For PHP, there’s a lean-package-validator app that helps remove standard things that have no bearing on usage of the module.

Whilst this is a minor amount being reduced … in this module … it also means small amounts of bandwidth being saved repeatedly, as well as non used content not being stored in a consumer’s setup.

1 Like

The answer would depend on which of the very many kinds of module sources you are using to distribute your modules. (see Module Sources | Terraform | HashiCorp Developer)

However the most commonly used ones do not have any packaging step, and instead directly tell the Terraform client to clone a certain Git repository.

Since the the Git protocol doesn’t allow cloning only a subtree of a repository, this means what you are asking for is not possible when using the commonly used ways of distributing Terraform modules.

1 Like