Terraform Test should be able to reference hcl config from example dirs

its very common for a module to have an examples directory where various scenarios for the module usage are. it would be brilliant to have terraform test be able to actually test those examples.

currently this is possible using symbolic links, it works great! however, it would be cool to see this become a full feature!

Hi @drewmullen1! Thanks for sharing this suggestion.

I’ve considered this too, and would like to include something like this in a later iteration of the testing experiment.

An interesting quirk to consider here is that “normal” test configurations, in the currently-used tests directory, typically refer to the module under test as source = "../../" so that Terraform will always use the directory in the same package rather than trying to download the module over the network somehow. However, good examples typically show what a user of the module would need to include in their configuration, and therefore will show a remote registry address or other remote module source address, which means that without any special workaround for this terraform test would try to test the currently-published version of the module, rather than the one in the current working directory.

I expect we can find a suitable set of conventions to make examples useful in both contexts, such as somehow telling terraform test the source address of the module under test so that it can “pretend” it’s just a local module even if specified with an absolute address, but that’ll be part of the design work to figure out how to incorporate examples into the test harness.

yeah good point. we have our examples currently set to ../.. so it didnt bother us. however, youre right about many module repos setting source to the registry