Skip to content

feat: add basic tests for local variables #65

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

Merged
merged 5 commits into from
Jun 27, 2025
Merged

Conversation

westonplatter
Copy link
Member

what

  • generate basic tests for logic performed in locals { ... }
  • test the generated userdata.sh script.

westonplatter and others added 3 commits June 26, 2025 15:32
…s validation

- Add comprehensive test for local.userdata templatefile rendering
- Add test for tailscaled_extra_flags in userdata template
- Add mock providers with plan-time overrides for reliable testing
- Fix primary_tag test assertion to match actual local variable behavior

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@westonplatter westonplatter requested a review from a team as a code owner June 26, 2025 22:40
@westonplatter westonplatter requested a review from oycyc June 26, 2025 22:40
gberenice
gberenice previously approved these changes Jun 27, 2025
Copy link
Member

@gberenice gberenice left a comment

Choose a reason for hiding this comment

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

Looks great!

Comment on lines 86 to 90
vpc_id = "vpc-test123"
subnet_ids = ["subnet-test123"]
namespace = "test"
name = "tailscale"
tailscaled_extra_flags = ["--state=mem:", "--verbose=1"]
Copy link
Contributor

Choose a reason for hiding this comment

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

We could put the variables that are used in all three test units in the top level variables {} block, like the vpc_id subnet_ids namespace and name, they're all the same in every unit. Only different variabel that would live in each individual block would be like tailscaled_extra_flags or the additional_tags in the tests above.

Example here: https://developer.hashicorp.com/terraform/language/tests#variable-references

On the topic of AI, even though I previously explicitly passed in this documentation, it still didn't get it right on the first go. I had to lead it to the path of understanding it 😓

Copy link
Member Author

@westonplatter westonplatter Jun 27, 2025

Choose a reason for hiding this comment

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

Oh, nice idea. I didn't know I could have shared and test specific variables. I'll give it a shot.

Making a note to bake this into the prompt we share in the upcoming MP article.

Copy link
Member Author

Choose a reason for hiding this comment

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

@oycyc pushed up changes implementing your suggestion.

Consolidate shared variables (vpc_id, subnet_ids, namespace, name) into a
top-level variables block while keeping test-specific variables in individual
run blocks. This follows Terraform testing best practices and reduces
configuration duplication.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Contributor

@oycyc oycyc left a comment

Choose a reason for hiding this comment

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

LGTM!

@westonplatter westonplatter merged commit 75fd25c into main Jun 27, 2025
5 checks passed
@westonplatter westonplatter deleted the feat/try-adding-tests branch June 27, 2025 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants