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 per-module terraform fixtures #1914

Merged
merged 7 commits into from
Dec 29, 2023
Merged

Allow per-module terraform fixtures #1914

merged 7 commits into from
Dec 29, 2023

Conversation

juliocc
Copy link
Collaborator

@juliocc juliocc commented Dec 10, 2023

This PR introduces "terraform fixtures" which allow defining common terraform resources (or modules) that are deployed together with a given example. This allows:

  • Describing all the required infrastructure for a given example
  • Reusing common infrastructure used by more than one example (e.g. instance groups in the load balancing modules)
  • Not polluting examples with repetitive boilerplate

@juliocc juliocc mentioned this pull request Dec 10, 2023
4 tasks
Copy link
Collaborator

@wiktorn wiktorn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really love this one! One comment to consider - in README.md, maybe instead of putting fixtures at the end, let's keep them after examples and before TFDOC, and name the section something like Definitions of the modules used in the examples to make it easy discoverable.

@ludoo
Copy link
Collaborator

ludoo commented Dec 10, 2023

Julio, as we discussed I would much prefer to centralize fixtures instead of having a lot of them scattered around modules, which will become

  • one more cognitive hurdle for any module changes
  • a maintenance nightmare eventually as the provider, resources, and our understanding and use of fixtures evolve

So while this is nice, I am starting to strongly feel that we're focusing too much on the tooling and too little on the actual code. :) So unless we have a way of centralziing fixtures not at the module level, but at the repo level, this is a -1 from me. :)

BTW I also completely share your PoV in a different PR that with e2e, examples are starting to become cryptic. You and I both know the primary use of examples is to show module usage not to run e2e tests, and if usability starts becoming impaired we will need to start removing tooling. Can we find a way of reminding this to all our collaborators?

Edit: it's a fine balance, but now we're tipping too far on the tooling side and losing our initial focus.

@wiktorn for visibility

@wiktorn
Copy link
Collaborator

wiktorn commented Dec 10, 2023

BTW I also completely share your PoV in a different PR that with e2e, examples are starting to become cryptic. You and I both know the primary use of examples is to show module usage not to run e2e tests, and if usability starts becoming impaired we will need to start removing tooling. Can we find a way of reminding this to all our collaborators?

I totally agree on the purpose of the examples, though I like to extend this definition, not to only show the module usage per se, but how it is used in the context of other modules.

Indeed, maybe now we are leaning too much over developer comfort over usability of examples. I think that by following a naming convention we can achieve both goals:

  • Use defined module names in fixtures, that derive from module names in the repository. I.e define module "net-address" for modules/net-address. If we need more instances of modules, use -a, -b, etc. suffixes.

The result is, that it is easy to comprehend, which module output goes where on the other's module inputs.

The other thing we can do is to generate links in README.md to fixtures used, so it is easy to glue full example. WDYT?

@ludoo
Copy link
Collaborator

ludoo commented Dec 10, 2023

The other thing we can do is to generate links in README.md to fixtures used, so it is easy to glue full example. WDYT?

Yep, I mentioned it above and it seems a great idea and really easy to do via tfdoc. Links or even better expandables, I liked the one you and Julio showed a few days ago.

@juliocc
Copy link
Collaborator Author

juliocc commented Dec 10, 2023

First of all this is an initial draft to start the discussion before we invest more time in all the e2e. Nothing here is set in stone and we can change (or discard) things as needed.

Julio, as we discussed I would much prefer to centralize fixtures instead of having a lot of them scattered around modules, which will become

I rushed this PR a bit because of #1913 and didn't fully document the two options I implemented:

  • Inlining the fixture directly in the README file using the tftest-fixture directive. This method keeps the code close the example but also becomes a bit unmaintainable IMO
  • Dropping a terraform file fixtures in tests/fixtures and then reference it from examples. This method is a bit cleaner requires extra tooling to make fixtures easy to discover.

I started with the first method and then brainstorming with @ludoo we came up with the second idea. Both have pros and cons and I'm still not sure which one is better yet.

the primary use of examples is to show module usage

Agreed 100%. That's why I opened this PR so we can start discussing. My intention was to ping you both on Monday but you both were faster than me ;)

The other thing we can do is to generate links in README.md to fixtures used, so it is easy to glue full example. WDYT?

@ludoo and I discussed something similar. Let's first decide if we want fixtures at all and then we can figure out how to make them easy to discover.

@juliocc juliocc force-pushed the jccb/example-fixtures branch 2 times, most recently from c67838b to f4f12e4 Compare December 19, 2023 15:37
@wiktorn
Copy link
Collaborator

wiktorn commented Dec 26, 2023

@juliocc I allowed myself to move the test to global file, and change naming of the module.

Other notable changes:

  • while preparing test directory, copy symlinks instead of copying of the contents (should reduce the IO during the tests, as we will not copy repo multiple times)
  • create a fixtures folder with symlinks to root directory and variables.tf, to make the development of fixtures easier. My assumption is that here, it won't be a big problem for Windows-based developers

I'd love to get this merged soon, so others can base their work on fixtures.

EDIT: actually, creating symlinks instead of deep-copy makes tests run 20+% slower than with deep copy. Reverted those changes and left a comment for future self.

@juliocc juliocc force-pushed the jccb/example-fixtures branch from eec3597 to 890f543 Compare December 29, 2023 08:09
@github-actions github-actions bot added the on:tools New or changed tool label Dec 29, 2023
@juliocc juliocc marked this pull request as ready for review December 29, 2023 09:32
@juliocc juliocc requested a review from wiktorn December 29, 2023 09:33
@juliocc juliocc enabled auto-merge (squash) December 29, 2023 09:42
@juliocc juliocc merged commit fde7b76 into master Dec 29, 2023
@juliocc juliocc deleted the jccb/example-fixtures branch December 29, 2023 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
on:tools New or changed tool
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants