Adds validation for slo_id #1221
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fix #1144
Fix: Add client-side validation for Kibana SLO
slo_idfieldSummary
I've implemented client-side validation for the
slo_idfield in the Kibana SLO resource to prevent invalid values from reaching the API and causing confusing 400 errors.Problem
Previously, the
slo_idfield lacked validation on the provider side, allowing invalid values like "supdawg" (only 7 characters) to pass through to the Kibana API. This resulted in unhelpful 400 Bad Request errors from the server instead of clear validation feedback at plan time.As mentioned in the GitHub issue #1144, users (me!) currently experience:
Solution
This PR adds validation to the
slo_idfield that enforces the Kibana API requirements:Changes
1. Schema Validation (
internal/kibana/slo.go)regexpimport for character validation (follows existing codebase patterns, for exampleuser.go)validation.All():validation.StringLenBetween(8, 48)ensures IDs are between 8-48 charactersvalidation.StringMatch()with regex^[a-zA-Z0-9_-]+$ensures only letters, numbers, hyphens, and underscores2. Test Coverage (
internal/kibana/slo_test.go)TestSloIdValidation()to verify both valid and invalid casesTestAccResourceSloValidation()with scenarios for:getSLOConfigWithInvalidSloId()for test configuration generation3. Documentation Updated
make docs-generateto reflect the new validation requirementsValidation Examples
The validation now catches these scenarios at plan time:
Testing
All tests pass successfully:
The fix follows the existing codebase patterns (similar to validation in
user.go) and uses the established SDK v2 validation framework, so no migration to plugin framework was needed.Impact
This change improves the user experience by: