Overview
Proper validation prevents configuration errors that can cause service failures or security vulnerabilities. This guide covers tools and techniques for validating the SGIVU config repository.YAML Syntax Validation
Using yamllint
Theyamllint tool checks YAML syntax and formatting:
Validating Configuration Files
yamllint Configuration
Create a.yamllint file in the repository root to customize validation rules:
Adjust rules based on your team’s coding standards. The above configuration is more lenient than yamllint defaults.
Testing Configuration Locally
Starting the Config Server
Before testing, ensure the Config Server is running and pointing to your local repository:Verifying Config Server Setup
Check that the Config Server can access the Git repository:Testing Configuration Retrieval
Testing Service Configurations
Use curl to fetch configuration and verify it’s correct:Understanding the Response
The Config Server returns merged configuration from base and profile-specific files:Configuration from profile-specific files (e.g.,
-dev.yml) overrides values from base files.Validating Specific Properties
Extracting Property Values
Usejq to extract specific properties for validation:
Validating Required Properties
Create a validation script to check that required properties are set:Pre-Commit Validation
Git Pre-Commit Hook
Automate validation before commits using a Git hook:This hook runs automatically before every commit, preventing invalid YAML from being committed.
Pre-Merge Validation Checklist
Before merging configuration changes to main:YAML Syntax
- All YAML files pass
yamllintvalidation - Indentation is consistent (2 spaces)
- No trailing whitespace
- Proper quoting for special characters
Security
- No plain-text secrets or passwords
- All sensitive values use
${VAR_NAME}placeholders - Environment variables are documented
-
.envfiles are in.gitignore
Configuration
- Required properties are present for each service
- Port numbers don’t conflict
- Service URLs are correct for the environment
- Profile-specific overrides are intentional
Testing
- Config Server can retrieve configuration
- Target service starts with new configuration
- Application functionality works as expected
- Health checks pass
Testing Configuration Changes
Local Development Workflow
Test with Config Server
If using a local file-based Config Server, refresh it:Then verify the change:
Common Validation Errors
YAML Syntax Errors
Indentation Error
Indentation Error
Error:Cause: Inconsistent indentation or missing space after colon.Fix:
Unquoted Special Characters
Unquoted Special Characters
Error:Cause: Special characters in values need quoting.Fix:
Duplicate Keys
Duplicate Keys
Error:Cause: Same key defined multiple times at the same level.Fix: Remove or merge the duplicate keys.
Configuration Errors
Missing Required Property
Missing Required Property
Symptom: Service fails to start with error like:Solution: Add the required property or provide a default value:
Environment Variable Not Resolved
Environment Variable Not Resolved
Symptom: Service uses literal
${VAR_NAME} instead of the value.Solution:- Verify the environment variable is set
- Check that Spring Boot can access it
- Provide a default value:
${VAR_NAME:default_value}
Automated Validation in CI/CD
GitHub Actions Example
Add automated validation to your CI pipeline:Best Practices
Validate Early
Run yamllint before committing. Use pre-commit hooks to enforce this.
Test Locally
Always test configuration changes with Config Server and target services before pushing.
Automate Checks
Use CI/CD pipelines to automatically validate all configuration changes.
Document Changes
Explain why configuration changed in commit messages and pull requests.
Use Version Control
Leverage Git history to track configuration changes over time.
Review Together
Require peer review for production configuration changes.
Related Resources
Security
Validate that secrets are not committed
Configuration Refresh
Apply validated changes without restarts
Testing Changes
Comprehensive guide to testing configuration
Troubleshooting
Debug configuration issues