My First Open Source Contribution: Implementing a Credit Card Validator for Terraform Provider
How It Started
I recently found an interesting GitHub project — terraform-provider-validatefx, a Terraform provider that adds validation functions for HCL. One open issue (#37) asked for a credit card validator. It looked like a great opportunity to learn and make my first open-source pull request.
Understanding the Project
Before coding, I learned how a Terraform Provider works:
- Terraform is an “Infrastructure as Code” tool by HashiCorp.
- Providers are plugins that extend Terraform with new resources or functions.
-
ValidateFX provides validation helpers (like
validatefx_email()
orvalidatefx_uuid()
).
Implementing the Validator
Each validator follows the same pattern:
- Implement the
frameworkvalidator.String
interface. - Add descriptions.
- Write
ValidateString()
for actual checks.
I implemented the Luhn algorithm to validate card numbers:
- Remove spaces and hyphens.
- Ensure 13–19 digits and numeric only.
- Reject all zeros.
- Perform Luhn checksum validation.
Writing Tests
I added comprehensive tests for:
✅ Valid cards (Visa, MasterCard, Amex)
✅ Formatted inputs (spaces, hyphens)
❌ Invalid cases (checksum, wrong length, letters, all zeros)
and edge cases (empty, null, unknown).
Technical Challenges
-
Line endings: Git detected false changes → fixed with
core.autocrlf
. - Integration tests: some Docker tests failed due to existing repo issues.
-
Unimplemented functions: the repo references
validatefx_email()
etc., so I focused only on the validator logic.
What I Learned
Technical:
- Terraform Plugin Framework basics.
- Luhn algorithm logic.
- Cross-platform setup and test-driven development.
Collaboration:
- Reading existing patterns before adding code.
- Scoping work to one issue.
- Communicating clearly in PRs.
Result
My PR included:
- 1 new validator file
- 1 complete test file
- Full Luhn-based validation logic
Takeaways
This first contribution taught me both coding and collaboration.
If you want to start with open source:
- Pick a small, well-defined issue.
- Understand the project first.
- Write clear tests.
- Be patient — every issue is a learning opportunity.
Top comments (0)