|
1 | 1 | # terraform-gitlab-drift |
2 | | -CLI tool to find GitLab resources missing from your Terraform code |
| 2 | + |
| 3 | +[](https://github.com/xMoelletschi/terraform-gitlab-drift/actions/workflows/ci.yml) |
| 4 | +[](https://github.com/xMoelletschi/terraform-gitlab-drift/releases) |
| 5 | +[](LICENSE) |
| 6 | + |
| 7 | +Detect GitLab resources not managed by Terraform and generate Terraform code to bring them under management. |
| 8 | + |
| 9 | +Uses the [GitLab Terraform Provider](https://registry.terraform.io/providers/gitlabhq/gitlab/latest/docs) resource definitions. |
| 10 | + |
| 11 | +## Features |
| 12 | + |
| 13 | +- 🔍 **Drift Detection**: Scan GitLab groups and projects to identify resources not managed by Terraform |
| 14 | +- 📝 **Code Generation**: Automatically generate Terraform code for unmanaged resources |
| 15 | +- 🔄 **Diff Comparison**: Show differences between existing and generated Terraform configurations |
| 16 | +- 🐳 **Docker-ready**: Designed for CI/CD pipeline |
| 17 | + |
| 18 | +## Quick Start |
| 19 | + |
| 20 | +### Local Installation |
| 21 | + |
| 22 | +```bash |
| 23 | +go install github.com/xMoelletschi/terraform-gitlab-drift@latest |
| 24 | +terraform-gitlab-drift scan --group my-group |
| 25 | +``` |
| 26 | + |
| 27 | +## GitLab CI Usage |
| 28 | + |
| 29 | +### Basic Drift Check |
| 30 | + |
| 31 | +```yaml |
| 32 | +drift-check: |
| 33 | + image: ghcr.io/xmoelletschi/terraform-gitlab-drift:latest |
| 34 | + script: |
| 35 | + - terraform-gitlab-drift scan --group $CI_PROJECT_ROOT_NAMESPACE |
| 36 | +``` |
| 37 | +
|
| 38 | +## Configuration |
| 39 | +
|
| 40 | +### Command-line Flags |
| 41 | +
|
| 42 | +| Flag | Environment Variable | Default | Description | |
| 43 | +| ----------------- | -------------------- | -------------------- | ------------------------------------------------- | |
| 44 | +| `--gitlab-token` | `GITLAB_TOKEN` | - | GitLab API token (required) | |
| 45 | +| `--gitlab-url` | - | `https://gitlab.com` | GitLab instance URL | |
| 46 | +| `--group` | - | - | Top-level group to scan (required for gitlab.com) | |
| 47 | +| `--terraform-dir` | - | `.` | Path to Terraform directory | |
| 48 | +| `--overwrite` | - | `false` | Overwrite files in terraform directory | |
| 49 | +| `--show-diff` | - | `true` | Show diff between generated and existing files | |
| 50 | +| `--verbose`, `-v` | - | `false` | Enable verbose (debug) logging | |
| 51 | +| `--json` | - | `false` | Output logs in JSON format | |
| 52 | + |
| 53 | +### Supported Resources |
| 54 | + |
| 55 | +- ✅ GitLab Groups ([`gitlab_group`](https://registry.terraform.io/providers/gitlabhq/gitlab/latest/docs/resources/group)) |
| 56 | +- ✅ GitLab Projects ([`gitlab_project`](https://registry.terraform.io/providers/gitlabhq/gitlab/latest/docs/resources/project)) |
| 57 | +- 🚧 More resources coming soon |
| 58 | + |
| 59 | +## Contributing |
| 60 | + |
| 61 | +Contributions are welcome! Please: |
| 62 | + |
| 63 | +1. Fork the repository |
| 64 | +2. Create a feature branch (`git checkout -b feature/amazing-feature`) |
| 65 | +3. Push to the branch (`git push origin feature/amazing-feature`) |
| 66 | +4. Open a Pull Request |
| 67 | + |
| 68 | +Please make sure to: |
| 69 | + |
| 70 | +- Add tests for new features |
| 71 | +- Update documentation as needed |
| 72 | +- Ensure CI checks pass |
| 73 | + |
| 74 | +## License |
| 75 | + |
| 76 | +This project is licensed under the Apache License 2.0 - see the [LICENSE](LICENSE) file for details. |
| 77 | + |
| 78 | +## Acknowledgments |
| 79 | + |
| 80 | +Built with: |
| 81 | + |
| 82 | +- [Cobra](https://github.com/spf13/cobra) - CLI framework |
| 83 | +- [GitLab Go SDK](https://gitlab.com/gitlab-org/api/client-go) - GitLab API client |
| 84 | +- [HCL](https://github.com/hashicorp/hcl) - Terraform configuration parsing |
| 85 | + |
| 86 | +--- |
| 87 | + |
| 88 | +**Note**: This tool is not affiliated with HashiCorp or GitLab. |
0 commit comments