Implementing a Domain Validator for Terraform Provider
Overview
This is my fourth pull request for the open-source project terraform-provider-validatefx.
The issue (#34) asked for a new is_domain
validator to check domain name formats such as example.com
.
The goal was straightforward: follow RFC 952 and RFC 1123 to ensure the validator accurately recognizes valid domain names while rejecting malformed inputs.
Implementation
The validator (domain.go
) checks:
- Overall length (max 253 characters)
- FQDN support (trailing dot allowed)
- Label validation (1–63 characters, no leading or trailing hyphen)
- Character restrictions (letters, digits, hyphens only)
- TLD rules (no all-numeric top-level domains)
- Proper handling for null, empty, and unknown values
A simple regex was used for label verification:
^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?$
Testing
A total of 24 test cases were added in domain_test.go
, covering:
- Valid domains (simple, subdomains, deep hierarchies)
- Invalid domains (double dots, invalid chars, too long)
- Edge cases (empty string, unknown values, FQDN)
The tests run in parallel and verify both pass and fail messages for accuracy.
Example
I also added a Terraform example (main.tf
) containing nine test inputs — four valid and five invalid — showing how users can apply the new validator in real configurations.
Development Process
- Created a feature branch:
feature/domain-validator
- Followed the same structure as existing validators (
email
,uuid
) - Used
go fmt
for formatting and confirmed successful build and tests - Committed with clear messages:
- add domain validator
- add tests for domain validator
- add example for domain validator
What I Learned
Even though the task was similar to my previous validator work, it reinforced best practices in:
- Following RFC standards
- Writing consistent, well-tested code
- Keeping PRs small and focused
- Maintaining a clean commit history
Reflection
This contribution may seem minor, but it added another essential validator to the Terraform ValidateFX provider.
Step by step, each pull request builds experience, improves confidence, and strengthens understanding of open-source collaboration.
Top comments (0)