|
| 1 | +# AGENTS.md |
| 2 | + |
| 3 | +## Project Overview |
| 4 | + |
| 5 | +Terraform provider for Harness that enables infrastructure-as-code management of Harness CD and NextGen platform resources. This provider allows automation of applications, pipelines, environments, services, connectors, feature flags, GitOps configurations, and AutoStopping rules. |
| 6 | + |
| 7 | +## Build System |
| 8 | + |
| 9 | +- **Language**: Go 1.24 |
| 10 | +- **Build tool**: Make |
| 11 | +- **Build command**: `make build` |
| 12 | +- **Install locally**: `make install` |
| 13 | +- **Clean**: `make clean` |
| 14 | + |
| 15 | +## Testing |
| 16 | + |
| 17 | +- **Run all unit tests**: `make test` |
| 18 | +- **Run acceptance tests**: `make testacc` (requires HARNESS_* environment variables) |
| 19 | +- **Run tests with coverage**: `make test-coverage` |
| 20 | +- **Run single test file**: `go test -v ./internal/service/platform/connector/... -run TestAccResourceConnector` |
| 21 | +- **Run single test case**: `go test -v ./path/to/package -run TestFunctionName` |
| 22 | + |
| 23 | +### Acceptance Tests |
| 24 | + |
| 25 | +Acceptance tests create real resources in Harness. Required environment variables: |
| 26 | +- `HARNESS_ACCOUNT_ID` |
| 27 | +- `HARNESS_API_KEY` |
| 28 | +- `HARNESS_PLATFORM_API_KEY` |
| 29 | + |
| 30 | +## Linting & Formatting |
| 31 | + |
| 32 | +- **Format code**: `make fmt` |
| 33 | +- **Check formatting**: `make fmt-check` |
| 34 | +- **Run vet**: `make vet` |
| 35 | +- **Run linter**: `make lint` (uses golangci-lint) |
| 36 | +- **Run all checks**: `make check` (fmt-check + vet) |
| 37 | + |
| 38 | +## Git Workflow |
| 39 | + |
| 40 | +- **Commit format**: `type: [JIRA-TICKET]: Description` |
| 41 | + - Types: `feat`, `fix`, `chore`, `refactor`, `docs`, `test` |
| 42 | + - Jira prefixes: DBOPS, CDS, CCM, IAC, PL, AH, and others |
| 43 | + - Example: `feat: [DBOPS-2019]: Add usePercona field support in schema resource` |
| 44 | +- **Default branch**: `main` |
| 45 | + |
| 46 | +## DOs |
| 47 | + |
| 48 | +- Always run `make check` before committing to verify formatting and static analysis |
| 49 | +- Add changelog entries in `.changelog/` for user-facing changes (see README for format) |
| 50 | +- Run `make test` to ensure unit tests pass before pushing |
| 51 | +- Follow existing code patterns in the codebase |
| 52 | +- Use descriptive commit messages with Jira ticket references |
| 53 | +- Run `make docs` after modifying resource schemas to regenerate documentation |
| 54 | +- Use `make dev-setup` when setting up the development environment for the first time |
| 55 | + |
| 56 | +## DON'Ts |
| 57 | + |
| 58 | +- Never force push to main/master |
| 59 | +- Never commit secrets, .env files, or credentials |
| 60 | +- Never run `make sweep` without explicit confirmation - it destroys test resources and can be dangerous if misconfigured |
| 61 | +- Never skip code quality checks before committing |
| 62 | +- Never modify generated documentation files in `docs/` directly - regenerate with `make docs` |
| 63 | + |
| 64 | +## Commands to Never Run |
| 65 | + |
| 66 | +- `git push --force origin main` |
| 67 | +- `git push --force origin master` |
| 68 | +- `git commit --no-verify` or `git push --no-verify` |
| 69 | +- `make sweep` (without explicit user confirmation) |
| 70 | +- `rm -rf /` or any destructive recursive deletes |
| 71 | + |
| 72 | +## Project Structure |
| 73 | + |
| 74 | +``` |
| 75 | +terraform-provider-harness/ |
| 76 | +├── main.go # Provider entry point |
| 77 | +├── Makefile # Build, test, and development commands |
| 78 | +├── go.mod # Go module definition |
| 79 | +├── internal/ # Internal packages (not importable externally) |
| 80 | +│ ├── provider/ # Terraform provider configuration |
| 81 | +│ ├── service/ # Resource implementations by service |
| 82 | +│ │ ├── cd/ # First Generation CD resources |
| 83 | +│ │ ├── cd_nextgen/ # NextGen CD resources |
| 84 | +│ │ ├── chaos/ # Chaos Engineering resources |
| 85 | +│ │ ├── pipeline/ # Pipeline resources |
| 86 | +│ │ ├── platform/ # Platform resources (connectors, secrets, etc.) |
| 87 | +│ │ └── service_discovery/ # Service discovery resources |
| 88 | +│ ├── acctest/ # Acceptance test utilities |
| 89 | +│ ├── sweep/ # Resource sweepers for test cleanup |
| 90 | +│ ├── test/ # Test utilities |
| 91 | +│ └── utils/ # Utility functions |
| 92 | +├── docs/ # Generated Terraform documentation |
| 93 | +├── examples/ # Example Terraform configurations |
| 94 | +├── templates/ # Documentation templates |
| 95 | +├── scripts/ # Build and utility scripts |
| 96 | +├── helpers/ # Helper utilities |
| 97 | +└── .changelog/ # Changelog entries for releases |
| 98 | +``` |
| 99 | + |
| 100 | +## Important Packages |
| 101 | + |
| 102 | +These are the most actively developed areas based on recent commit history: |
| 103 | + |
| 104 | +- `internal/service/platform/` - Platform resources (connectors, secrets, users, etc.) |
| 105 | +- `internal/service/cd_nextgen/` - NextGen CD resources (environments, services, infrastructure) |
| 106 | +- `internal/service/pipeline/` - Pipeline resources |
| 107 | +- `internal/acctest/` - Acceptance test utilities |
| 108 | + |
| 109 | +## Resource Development Guidelines |
| 110 | + |
| 111 | +When creating or modifying Terraform resources: |
| 112 | + |
| 113 | +1. **Schema Definition**: Define resource schema in the resource file with clear descriptions |
| 114 | +2. **CRUD Operations**: Implement Create, Read, Update, Delete functions |
| 115 | +3. **Testing**: Write both unit tests and acceptance tests |
| 116 | +4. **Documentation**: Schema descriptions auto-generate docs via `make docs` |
| 117 | +5. **Changelog**: Add entry in `.changelog/<PR_NUMBER>.txt` |
| 118 | + |
| 119 | +## Dependencies |
| 120 | + |
| 121 | +Key dependencies (from go.mod): |
| 122 | +- `github.com/harness/harness-go-sdk` - Harness Go SDK |
| 123 | +- `github.com/harness/harness-openapi-go-client` - Harness OpenAPI client |
| 124 | +- `github.com/hashicorp/terraform-plugin-sdk/v2` - Terraform Plugin SDK |
| 125 | +- `github.com/stretchr/testify` - Testing utilities |
| 126 | + |
| 127 | +## Language-Specific Guidelines |
| 128 | + |
| 129 | +This is a Go codebase. Follow Go conventions: |
| 130 | +- Use `gofmt` for formatting (handled by `make fmt`) |
| 131 | +- Follow effective Go guidelines |
| 132 | +- Use meaningful variable and function names |
| 133 | +- Handle errors explicitly |
| 134 | +- Write table-driven tests where appropriate |
0 commit comments