Skip to content

Commit 14fc4ec

Browse files
committed
Update docs to be more useful
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
1 parent 831f72f commit 14fc4ec

File tree

3 files changed

+122
-22
lines changed

3 files changed

+122
-22
lines changed

ARCHITECTURE.md

Lines changed: 92 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ This document serves as a guide for contributors implementing new features and r
1414
- [Schema Field Guidelines](#schema-field-guidelines)
1515
- [ID Patterns](#id-patterns)
1616
- [Implementation Patterns](#implementation-patterns)
17+
- [Authentication](#authentication)
1718
- [CRUD Function Signatures](#crud-function-signatures)
1819
- [Accessing the API Client](#accessing-the-api-client)
1920
- [Error Handling](#error-handling)
@@ -28,6 +29,7 @@ This document serves as a guide for contributors implementing new features and r
2829
- [Gotchas \& Known Issues](#gotchas--known-issues)
2930
- [API Preview Headers](#api-preview-headers)
3031
- [Deprecated Resources](#deprecated-resources)
32+
- [Deprecated Data Sources](#deprecated-data-sources)
3133
- [Known Limitations](#known-limitations)
3234
- [Workarounds in Code](#workarounds-in-code)
3335
- [Pending go-github Updates](#pending-go-github-updates)
@@ -39,6 +41,7 @@ This document serves as a guide for contributors implementing new features and r
3941
- [Use StateUpgraders for State Migrations](#use-stateupgraders-for-state-migrations)
4042
- [Explicit Authentication Configuration](#explicit-authentication-configuration)
4143
- [Transport Layer Rework](#transport-layer-rework)
44+
- [Migrate to `terraform-plugin-testing`](#migrate-to-terraform-plugin-testing)
4245
- [No Local Git CLI Support](#no-local-git-cli-support)
4346
- [2025](#2025)
4447
- [Replace `log` Package with `tflog`](#replace-log-package-with-tflog)
@@ -62,7 +65,7 @@ terraform-provider-github/
6265
│ ├── util.go # Core utilities (ID parsing, validation)
6366
│ ├── util_*.go # Domain utilities (rules, labels, etc.)
6467
│ │
65-
│ └── transport.go # Custom HTTP transport with ETag caching
68+
│ └── transport.go # HTTP transports: ETag caching, rate limiting, retries
6669
6770
├── ARCHITECTURE.md # This file - implementation guide
6871
├── MAINTAINERS.md # Maintainers and contributors
@@ -269,6 +272,17 @@ id, err := buildID(escapeIDPart(part1), part2)
269272

270273
## Implementation Patterns
271274

275+
### Authentication
276+
277+
The provider resolves credentials using the following fallback chain (first match wins):
278+
279+
1. **Token**`token` attribute or `GITHUB_TOKEN` env var
280+
2. **GitHub App**`app_auth` block with `id`, `installation_id`, and `pem_file`
281+
3. **GitHub CLI** — Falls back to `gh auth token` if neither token nor app_auth is set
282+
4. **Anonymous** — Read-only access when no credentials are available
283+
284+
All authentication configuration is handled in `config.go`. See the [Explicit Authentication Configuration](#explicit-authentication-configuration) decision for design rationale.
285+
272286
### CRUD Function Signatures
273287

274288
```go
@@ -513,7 +527,16 @@ func TestAccGithubExample(t *testing.T) {
513527
514528
### Test Modes
515529

516-
Use `skipUnauthenticated(t)`, `skipUnlessHasOrgs(t)`, `skipUnlessHasPaidOrgs(t)`, `skipUnlessEnterprise(t)`, `skipUnlessMode(t, testModes...)` functions to run tests in appropriate contexts:
530+
Use these skip functions to run tests in appropriate contexts:
531+
532+
- `skipUnauthenticated(t)` — skips if anonymous mode
533+
- `skipUnlessHasOrgs(t)` — requires organization, team, or enterprise mode
534+
- `skipUnlessHasPaidOrgs(t)` — requires team or enterprise mode (paid orgs)
535+
- `skipUnlessEnterprise(t)` — requires enterprise mode
536+
- `skipUnlessHasAppInstallations(t)` — requires GitHub App installations
537+
- `skipUnlessEMUEnterprise(t)` — requires EMU enterprise
538+
- `skipIfEMUEnterprise(t)` — skips if EMU enterprise
539+
- `skipUnlessMode(t, testModes...)` — generic mode check
517540

518541
| Mode | Environment Variables Required |
519542
| -------------- | -------------------------------------- |
@@ -525,15 +548,24 @@ Use `skipUnauthenticated(t)`, `skipUnlessHasOrgs(t)`, `skipUnlessHasPaidOrgs(t)`
525548
### Running Tests
526549

527550
```bash
528-
# Run specific test
551+
# Run specific acceptance test
529552
make testacc T=TestAccGithubExample
553+
554+
# Run unit tests (non-acceptance)
555+
make test
556+
557+
# With coverage
558+
make testacc T=TestAccGithubExample COV=true
559+
560+
# Clean up leaked test resources (repos, teams prefixed with tf-acc-test-)
561+
make sweep
530562
```
531563

532564
### Debugging Tests
533565

534566
```bash
535567
# With debug logging
536-
TF_LOG=DEBUG make testacc T=TestAccGithubExample
568+
TF_LOG=DEBUG make testacc T=TestAccGithubExample
537569
```
538570

539571
---
@@ -555,12 +587,21 @@ The following resources are deprecated and will be removed in future versions:
555587
| -------------------------------------------- | ------------------------------------------------- |
556588
| `github_organization_security_manager` | `github_organization_role_team` |
557589
| `github_organization_custom_role` | `github_organization_repository_role` |
590+
| `github_organization_role_team_assignment` | `github_organization_role_team` |
558591
| `github_repository_deployment_branch_policy` | `github_repository_environment_deployment_policy` |
559592
| `github_organization_project` | None (Classic Projects API removed) |
560593
| `github_project_card` | None (Classic Projects API removed) |
561594
| `github_project_column` | None (Classic Projects API removed) |
562595
| `github_repository_project` | None (Classic Projects API removed) |
563596

597+
### Deprecated Data Sources
598+
599+
| Deprecated Data Source | Replacement |
600+
| ---------------------------------------------- | --------------------------------------------------- |
601+
| `github_organization_custom_role` | `github_organization_repository_role` |
602+
| `github_organization_security_managers` | `github_organization_role_teams` |
603+
| `github_repository_deployment_branch_policies` | `github_repository_environment_deployment_policies` |
604+
564605
### Known Limitations
565606

566607
- **Branch Protection `contexts`**: Deprecated, use the `checks` array instead
@@ -585,24 +626,58 @@ The following features are blocked waiting for upstream changes in [google/go-gi
585626

586627
### Common Utilities
587628

629+
**ID Parsing & Building** (`util.go`):
630+
631+
| Function | Purpose |
632+
| -------------------- | ---------------------------------------------- |
633+
| `buildID(parts...)` | Create composite ID (e.g., `"a:b"`, `"a:b:c"`) |
634+
| `parseID2(id)` | Parse two-part composite ID |
635+
| `parseID3(id)` | Parse three-part composite ID |
636+
| `parseID4(id)` | Parse four-part composite ID |
637+
| `escapeIDPart(part)` | Escape colons in ID parts |
638+
| `buildChecksumID(v)` | Create MD5-based checksum ID from string slice |
639+
640+
**Error Handling & Validation** (`util.go`):
641+
588642
| Function | Purpose |
589643
| ----------------------------------------------------------- | ---------------------------------------------- |
590-
| `buildID(parts...)` | Create composite ID (e.g., `"a:b"`, `"a:b:c"`) |
591-
| `parseID2(id)` | Parse two-part composite ID |
592-
| `parseID3(id)` | Parse three-part composite ID |
593-
| `parseID4(id)` | Parse four-part composite ID |
594-
| `escapeIDPart(part)` | Escape colons in ID parts |
595644
| `wrapErrors([]error)` | Convert errors to diagnostics |
596645
| `checkOrganization(meta)` | Verify org context |
597-
| `getTeamID(ctx, meta, idOrSlug)` | Resolve team ID from ID or slug |
598-
| `getTeamSlug(ctx, meta, idOrSlug)` | Resolve team slug from ID or slug |
599-
| `expandStringList([]any)` | Convert to `[]string` |
600-
| `flattenStringList([]string)` | Convert to `[]any` |
601646
| `deleteResourceOn404AndSwallow304OtherwiseReturnError(...)` | Handle 404/304 responses |
602-
| `diffRepository` | `CustomizeDiffFunc`: force replacement on repo ID change |
603-
| `diffSecret` | `CustomizeDiffFunc`: detect remote secret drift via timestamps |
604-
| `diffSecretVariableVisibility` | `CustomizeDiffFunc`: validate `selected_repository_ids` vs `visibility` |
605-
| `diffTeam` | `CustomizeDiffFunc`: force new resource on team ID change |
647+
| `validateValueFunc(values)` | Create enum validator from allowed values |
648+
| `validateSecretNameFunc` | Validate GitHub secret naming rules |
649+
| `caseInsensitive()` | `DiffSuppressFunc` for case-insensitive fields |
650+
| `isArchivedRepositoryError(err)` | Detect archived repo 403 errors |
651+
652+
**Data Conversion** (`util.go`):
653+
654+
| Function | Purpose |
655+
| ----------------------------- | --------------------- |
656+
| `expandStringList([]any)` | Convert to `[]string` |
657+
| `flattenStringList([]string)` | Convert to `[]any` |
658+
659+
**Team & Repository Resolution** (`util_team.go`, `util_v4_repository.go`):
660+
661+
| Function | Purpose |
662+
| ---------------------------------- | ------------------------------------ |
663+
| `getTeamID(ctx, meta, idOrSlug)` | Resolve team ID from ID or slug |
664+
| `getTeamSlug(ctx, meta, idOrSlug)` | Resolve team slug from ID or slug |
665+
| `getRepositoryID(name, meta)` | Resolve repository node ID from name |
666+
667+
**Permission Mapping** (`util_permissions.go`):
668+
669+
| Function | Purpose |
670+
| --------------------------- | ---------------------------------------------------------- |
671+
| `getPermission(permission)` | Normalize permission names (`read``pull`, `write``push`) |
672+
673+
**CustomizeDiffFuncs** (`util_diff.go`):
674+
675+
| Function | Purpose |
676+
| ------------------------------ | -------------------------------------------------- |
677+
| `diffRepository` | Force replacement on repo ID change |
678+
| `diffSecret` | Detect remote secret drift via timestamps |
679+
| `diffSecretVariableVisibility` | Validate `selected_repository_ids` vs `visibility` |
680+
| `diffTeam` | Force new resource on team ID change |
606681

607682
### Naming Conventions
608683

CONTRIBUTING.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,17 @@ The following provider development overrides are set in the CLI configuration:
144144

145145
See the [Environment Variable Reference](#environment-variable-reference) below for the full list of configuration options.
146146

147-
There are also a small amount of unit tests in the provider. Due to the nature of the provider, such tests are currently only recommended for exercising functionality completely internal to the provider. These may be executed by running `make test`.
147+
There are also a small number of unit tests in the provider. Due to the nature of the provider, such tests are currently only recommended for exercising functionality completely internal to the provider. These may be executed by running `make test`.
148+
149+
### Cleaning Up Test Resources
150+
151+
Acceptance tests create real GitHub resources prefixed with `tf-acc-test-`. If tests fail or are interrupted, these resources may be left behind. Run the sweeper to clean them up:
152+
153+
```sh
154+
make sweep
155+
```
156+
157+
This removes leaked test repositories and teams matching the `tf-acc-test-` prefix.
148158

149159
### GitHub Organization
150160

README.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,26 @@
11
# Terraform Provider GitHub
2-
=========================
32

43
<img src="https://cloud.githubusercontent.com/assets/98681/24211275/c4ebd04e-0ee8-11e7-8606-061d656a42df.png" width="72" height="">
54

65
<img src="https://raw.githubusercontent.com/hashicorp/terraform-website/d841a1e5fca574416b5ca24306f85a0f4f41b36d/content/source/assets/images/logo-terraform-main.svg" width="300px">
76

8-
This project is used to manipulate GitHub resources (repositories, teams, files, etc.) using Terraform. Its Terraform Registry page can be found [here](https://registry.terraform.io/providers/integrations/github/).
7+
This provider manages GitHub resources — repositories, teams, branch protections, actions secrets/variables, organization settings, rulesets, deploy keys, webhooks, and more — using Terraform. It supports both GitHub.com and GitHub Enterprise Server via the REST and GraphQL APIs.
8+
9+
See the [GitHub Provider page on the Terraform Registry](https://registry.terraform.io/providers/integrations/github/) for installation and documentation.
10+
11+
## Quick Start
12+
13+
```hcl
14+
provider "github" {
15+
owner = "my-org"
16+
}
17+
18+
resource "github_repository" "example" {
19+
name = "example-repo"
20+
description = "Managed by Terraform"
21+
visibility = "private"
22+
}
23+
```
924

1025
## Requirements
1126

@@ -14,11 +29,11 @@ This project is used to manipulate GitHub resources (repositories, teams, files,
1429

1530
## Usage
1631

17-
Detailed documentation for the GitHub provider can be found [here](https://registry.terraform.io/providers/integrations/github).
32+
Comprehensive documentation for the GitHub Terraform provider is available on the [Terraform Registry – GitHub Provider page](https://registry.terraform.io/providers/integrations/github).
1833

1934
## Contributing
2035

21-
Detailed documentation for contributing to the GitHub provider can be found [here](CONTRIBUTING.md).
36+
For instructions on how to contribute to the GitHub Terraform provider, see the [Contributing Guide](CONTRIBUTING.md).
2237

2338
## Roadmap
2439

0 commit comments

Comments
 (0)