
Detect GitLab resources not managed by Terraform and generate Terraform code to bring them under management.
Uses the GitLab Terraform Provider resource definitions.
Features
- 🔍 Drift Detection: Scan GitLab groups and projects to identify resources not managed by Terraform
- 📝 Code Generation: Automatically generate Terraform code for unmanaged resources
- 🔄 Diff Comparison: Show differences between existing and generated Terraform configurations
- 🐳 Docker-ready: Designed for CI/CD pipeline
Quick Start
Local Installation
go install github.com/xMoelletschi/terraform-gitlab-drift@latest
terraform-gitlab-drift scan --group my-group
GitLab CI Usage
Basic Drift Check
drift-check:
image: ghcr.io/xmoelletschi/terraform-gitlab-drift:latest
script:
- terraform-gitlab-drift scan --group $CI_PROJECT_ROOT_NAMESPACE
Configuration
Command-line Flags
| Flag |
Environment Variable |
Default |
Description |
--gitlab-token |
GITLAB_TOKEN |
- |
GitLab API token (required) |
--gitlab-url |
- |
https://gitlab.com |
GitLab instance URL |
--group |
- |
- |
Top-level group to scan (required for gitlab.com) |
--terraform-dir |
- |
. |
Path to Terraform directory |
--overwrite |
- |
false |
Overwrite files in terraform directory |
--show-diff |
- |
true |
Show diff between generated and existing files |
--verbose, -v |
- |
false |
Enable verbose (debug) logging |
--json |
- |
false |
Output logs in JSON format |
Supported Resources
Contributing
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature)
- Push to the branch (
git push origin feature/amazing-feature)
- Open a Pull Request
Please make sure to:
- Add tests for new features
- Update documentation as needed
- Ensure CI checks pass
License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
Acknowledgments
Built with:
Note: This tool is not affiliated with HashiCorp or GitLab.