Contributing to Homelab Infrastructure¶
Thank you for your interest in contributing to this project. This document provides guidelines for contributing.
Development Environment¶
Prerequisites¶
- Docker installed on your machine
- SSH key configured for server access
- Terraform Cloud account (for state management)
Setup¶
- Clone the repository:
- Install dependencies:
- Build and enter the development container:
Container Workspace¶
- Workspace root:
/srv - SSH keys:
~/.sshmounted for Git and server access - Kubernetes config:
container/root/.kube/config
Code Style Guidelines¶
Terraform¶
- Use snake_case for resource names and variables
- Use
.tftplextension for Terraform templates - Pin Helm chart versions in
helm_releaseresources - Include type, description, and default for all variables
- Add validation blocks where appropriate
Ansible¶
- Follow role-based structure:
tasks/,templates/,defaults/ - Use
.j2extension for Jinja2 templates - Use kebab-case for playbook file names
- Use snake_case for variable names
Naming Conventions¶
- Resources: Use consistent prefixes (e.g.,
gitlab_,prometheus_,minio_) - Domains: Follow pattern
service.domain.local
Pre-commit Hooks¶
This project uses pre-commit hooks to ensure code quality. Always run before committing:
The following hooks are configured:
| Hook | Purpose |
|---|---|
ansible-lint |
Validate Ansible playbooks and roles |
terraform_fmt |
Format Terraform files |
terraform_validate |
Validate Terraform configuration |
terraform_trivy |
Security scanning for Terraform |
terraform_tflint |
Lint Terraform files |
detect-private-key |
Prevent committing private keys |
gitleaks |
Detect secrets in code |
docs-drift |
Doc coverage, path citations, nav orphans, no em dash in any tracked text file, and no hard-wrapped Markdown paragraph. En dashes, U+2013, are allowed and correct in ranges like 30–60 min |
Pull Request Process¶
- Create a feature branch from
main:
-
Make your changes following the code style guidelines.
-
Run pre-commit hooks:
-
Test your changes in the container environment.
-
Commit your changes with a descriptive message:
-
Push to your fork and create a pull request.
-
Describe your changes in the PR description:
- What problem does this solve?
- How was it tested?
- Any breaking changes?
Adding New Modules¶
Terraform Module¶
- Create directory:
stage2/<module-name>/ - Create required files:
main.tfor<service>.tf- Main resourcesvariables.tf- Module variables (if needed)provider.tf- Provider configuration (if needed)templates/- Template files (if needed)docs/stage2/<module-name>.md- Module documentation, plus amkdocs.ymlnav entry- Add module to
stage2/main.tfwith appropriate dependencies - Add enable variable to
stage2/variables.tfif optional
Ansible Role¶
- Create directory:
stage1/roles/<role-name>/ - Create required files:
tasks/main.yml- Task definitionsdefaults/main.yml- Default variablestemplates/- Jinja2 templates (if needed)- Add role to appropriate playbook in
stage1/
Documentation Style¶
Line Wrapping¶
One line per paragraph, list item and quoted line. Never hard wrap prose: a reflowed paragraph arrives in review as a rewritten block and git blame then points at the reflow instead of the edit. Turn on soft wrap in your editor; .editorconfig and .markdownlint.json already disable the line-length rules that push you the other way. The docs-drift hook rejects a wrap.
Mermaid Diagrams¶
Never set fill: or color: in a classDef. Material renders diagrams into a closed shadow root and paints label text from the active palette, so a hardcoded color: is silently dropped and a hardcoded fill: then clashes with whichever theme the reader is using. Leave both to the theme and mark nodes with the border only:
| Class | classDef |
Use for |
|---|---|---|
danger |
stroke:#e53935,stroke-width:3px |
Destructive or disruptive: reboots, drains |
shared |
stroke:#b9770e,stroke-width:2px |
Re-entered from more than one caller |
optional |
stroke-dasharray:5 3 |
Gated by a flag, or populated at runtime |
done |
stroke:#388e3c,stroke-width:2px |
Terminal success state |
aux |
stroke:#78909c,stroke-dasharray:2 2 |
Not a cluster node: localhost, external, artifacts |
Most nodes should carry no class at all. Mark only what a reader would otherwise miss.
Security Guidelines¶
- Never commit secrets - Store them in Bitwarden Secrets Manager (see Bitwarden secrets); the container injects them at runtime
- Never commit
.envfiles - The gitignored.envholds onlyBWS_ACCESS_TOKEN/BWS_PROJECT_ID - Use SSH keys - Never commit private keys
- Pin versions - Always pin tool and chart versions
Questions?¶
If you have questions about contributing, please open an issue for discussion.