Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Git module sources within Terraform Test run blocks #36271

Open
ndouglas opened this issue Jan 6, 2025 · 3 comments
Open

Allow Git module sources within Terraform Test run blocks #36271

ndouglas opened this issue Jan 6, 2025 · 3 comments
Labels
enhancement new new issue not yet triaged terraform test

Comments

@ndouglas
Copy link
Contributor

ndouglas commented Jan 6, 2025

Terraform Version

Terraform v1.9.5
on darwin_arm64

Use Cases

I have a number of reusable Terraform modules developed in a specific GitHub repository (.../cie-terraform-modules) to implement patterns that recur in our infrastructure across multiple projects.

Some of these modules are for repetitive infrastructure tasks (e.g. a Lambda function with the Datadog serverless extension, TLS CA certs for our intranet, etc already configured). Some others are for tasks that may be very small but have nonetheless proven useful in tests (e.g. generating a random string for an environment name, creating a temporary directory to hold files, etc).

The problem is that Git does not appear to be supported, returning the error "Only local or registry module sources are currently supported from within test run blocks."

Note: Terraform test files only support local and registry modules within the source attribute.

(from https://developer.hashicorp.com/terraform/language/tests)

So, TL;DR: I would like to be able to use Terraform modules from Git repositories in run blocks.

Attempted Solutions

I create a module in the local repository to wrap the module from the Git repository. It consists only of a variables.tf, outputs.tf, main.tf, and a file with the module { } block that relays the variables and outputs.

This works but creates a rather fragile coupling that needs to be updated whenever the API of the upstream module changes. It's also a bit confusing if you see such-and-such-module does not provide such-and-such-output, but you look at the upstream module and it very much does -- it just wasn't added into the "wrapper" module.

Proposal

Permit run blocks to support Git module sources.

References

No response

@ndouglas ndouglas added enhancement new new issue not yet triaged labels Jan 6, 2025
@crw
Copy link
Contributor

crw commented Jan 6, 2025

Thanks for this feature request! If you are viewing this issue and would like to indicate your interest, please use the 👍 reaction on the issue description to upvote this issue. We also welcome additional use case descriptions. Thanks again!

@Mjb141
Copy link

Mjb141 commented Jan 7, 2025

I want to see this ASAP. The workaround (create a local module that just calls the remote Git module) scales poorly when you have 10+ modules combined.

Given that the module block supports Git sources elsewhere I'm a little surprised this wasn't provided by default? Why was it omitted?

@ndouglas
Copy link
Contributor Author

ndouglas commented Jan 7, 2025

🤷🏻 The only comment I found in the code doesn't explain why it wouldn't be provided.

Might be worth mentioning that OpenTofu mentions no similar restriction:

The source attribute points to the directory of the module to load or any other module source.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement new new issue not yet triaged terraform test
Projects
None yet
Development

No branches or pull requests

4 participants