-
Notifications
You must be signed in to change notification settings - Fork 13
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
Conversation
…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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great!
tests/locals.tftest.hcl
Outdated
vpc_id = "vpc-test123" | ||
subnet_ids = ["subnet-test123"] | ||
namespace = "test" | ||
name = "tailscale" | ||
tailscaled_extra_flags = ["--state=mem:", "--verbose=1"] |
There was a problem hiding this comment.
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 😓
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
what
locals { ... }
userdata.sh
script.