You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Most module developers use a pattern where their repo root has a directory examples/ which contains root modules that are examples of how to use their module. It would be great if terraform test (tft) tightly integrated with this paradigm.
Today we use either terratest or tft to validate our example root modules which validates both functionality and "documentation" (examples are a form of docs). However, in order to do this, the module calls in each example refer to the module with source = "../..". That allows developers to test changes using their test suite by referencing the local module code. However, its confusing to module users who often anticipate that an example should be copy-paste-able. It also encourages users to clone the repos vs using the terraform registry.
Attempted Solutions
We've tried to get around this by posting comments above our examples source to also include a reference to the registry location to clue our users that ../.. isnt appropriate but still get the benefit of referencing examples in test. We then symlink to the example dir for terraform test (not necessary with terratest).
Ideally, we could have examples reference their entry in the registry but still be able to test. Perhaps terraform test could have an option to override a module's source. Then you could have an example hardcode its registry location but have your tests adjust that to ../.. (or whatever is appropriate).
@drewmullen - is this feature request still relevant with the finalised testing framework? We certainly don't support overwriting module sources as part of the test command, but I think that you wouldn't want to structure terraform tests in a way that you'd need to do that given the new command?
@liamcervante thanks for considering this request. There is currently no way, that i am aware of, to both test your example/ dir examples & have them properly documented in the TF Registry. I understand the desire to have a hard stance on source interpolation but that is the only solution I can think of.
You can see the convo i linked above in references for a little more context if thats helpful.
liamcervante
changed the title
feature/ terraform test should tightly integrate with the examples/ pattern found in module developmentterraform test: Allow overriding of module sources
Dec 10, 2024
Current Terraform Version
Use-cases
Most module developers use a pattern where their repo root has a directory
examples/
which contains root modules that are examples of how to use their module. It would be great ifterraform test
(tft) tightly integrated with this paradigm.Today we use either terratest or tft to validate our example root modules which validates both functionality and "documentation" (examples are a form of docs). However, in order to do this, the module calls in each example refer to the module with
source = "../.."
. That allows developers to test changes using their test suite by referencing the local module code. However, its confusing to module users who often anticipate that an example should be copy-paste-able. It also encourages users to clone the repos vs using the terraform registry.Attempted Solutions
We've tried to get around this by posting comments above our examples source to also include a reference to the registry location to clue our users that
../..
isnt appropriate but still get the benefit of referencing examples in test. We then symlink to the example dir for terraform test (not necessary with terratest).Proposal
Ideally, we could have examples reference their entry in the registry but still be able to test. Perhaps
terraform test
could have an option to override a module's source. Then you could have an example hardcode its registry location but have your tests adjust that to../..
(or whatever is appropriate).References
The text was updated successfully, but these errors were encountered: