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

terraform test: Allow overriding of module sources #30734

Open
drewmullen opened this issue Mar 24, 2022 · 2 comments
Open

terraform test: Allow overriding of module sources #30734

drewmullen opened this issue Mar 24, 2022 · 2 comments
Labels
enhancement new new issue not yet triaged terraform test

Comments

@drewmullen
Copy link
Contributor

Current Terraform Version

Terraform v1.1.6
on darwin_amd64
+ provider registry.terraform.io/hashicorp/aws v4.6.0
+ provider registry.terraform.io/hashicorp/awscc v0.15.0

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 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).

module "ipv4_scope" {
  # source  = "aws-ia/ipam/aws"
  source = "../.."
  ...
}

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

  • See the discussion that kicked this off here
@liamcervante
Copy link
Member

@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?

@drewmullen
Copy link
Contributor Author

@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 liamcervante changed the title feature/ terraform test should tightly integrate with the examples/ pattern found in module development terraform test: Allow overriding of module sources Dec 10, 2024
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