Skip to content

Commit 72d7098

Browse files
committed
Update docs files
Signed-off-by: Timo Sand <timo.sand@f-secure.com>
1 parent da53fc5 commit 72d7098

File tree

3 files changed

+64
-13
lines changed

3 files changed

+64
-13
lines changed

ARCHITECTURE.md

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ terraform-provider-github/
6565
│ └── transport.go # Custom HTTP transport with ETag caching
6666
6767
├── ARCHITECTURE.md # This file - implementation guide
68-
├── MAINTAINERS.md # Maintainers, decision log, contributors
68+
├── MAINTAINERS.md # Maintainers and contributors
6969
└── CONTRIBUTING.md # How to contribute
7070
```
7171

@@ -301,7 +301,7 @@ func resourceGithubExampleDelete(ctx context.Context, d *schema.ResourceData, me
301301
```go
302302
func resourceExampleRead(ctx context.Context, d *schema.ResourceData, m any) diag.Diagnostics {
303303
meta := m.(*Owner)
304-
// REST API client (go-github v82)
304+
// REST API client (go-github)
305305
client := meta.v3client
306306

307307
// GraphQL client (for queries not available in REST)
@@ -326,7 +326,7 @@ if err != nil {
326326
var ghErr *github.ErrorResponse
327327
if errors.As(err, &ghErr) {
328328
if ghErr.Response.StatusCode == http.StatusNotFound {
329-
log.Printf("[INFO] Removing %s from state because it no longer exists", name)
329+
tflog.Info(ctx, "Removing resource from state because it no longer exists", map[string]any{"name": name})
330330
d.SetId("")
331331
return nil
332332
}
@@ -446,10 +446,21 @@ func resourceExampleCreate(ctx context.Context, d *schema.ResourceData, meta any
446446

447447
### Test Structure
448448

449+
Use `ConfigStateChecks` for post-apply state assertions and `ConfigPlanChecks` for plan-level assertions (e.g., verifying `ForceNew` triggers). These replace the legacy `Check:` + `resource.ComposeTestCheckFunc` pattern.
450+
449451
```go
452+
import (
453+
"github.com/hashicorp/terraform-plugin-testing/compare"
454+
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
455+
"github.com/hashicorp/terraform-plugin-testing/knownvalue"
456+
"github.com/hashicorp/terraform-plugin-testing/plancheck"
457+
"github.com/hashicorp/terraform-plugin-testing/statecheck"
458+
"github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
459+
)
460+
450461
func TestAccGithubExample(t *testing.T) {
451-
452-
t.Run("creates resource without error", func(t *testing.T) {
462+
463+
t.Run("creates resource without error", func(t *testing.T) {
453464
randomID := acctest.RandStringFromCharSet(5, acctest.CharSetAlphaNum)
454465
testResourceName := fmt.Sprintf("%s%s", testResourcePrefix, randomID)
455466
config := fmt.Sprintf(`
@@ -464,16 +475,42 @@ func TestAccGithubExample(t *testing.T) {
464475
Steps: []resource.TestStep{
465476
{
466477
Config: config,
467-
Check: resource.ComposeTestCheckFunc(
468-
resource.TestCheckResourceAttr( "github_example.test", "name", testResourceName ),
469-
),
478+
ConfigStateChecks: []statecheck.StateCheck{
479+
// Verify computed values are populated
480+
statecheck.ExpectKnownValue("github_example.test", tfjsonpath.New("etag"), knownvalue.NotNull()),
481+
statecheck.ExpectKnownValue("github_example.test", tfjsonpath.New("node_id"), knownvalue.NotNull()),
482+
// Compare computed values across resources
483+
statecheck.CompareValuePairs("github_example.test", tfjsonpath.New("repo_id"), "github_repository.test", tfjsonpath.New("repo_id"), compare.ValuesSame()),
484+
},
485+
},
486+
},
487+
})
488+
})
489+
490+
t.Run("forces new when field changes", func(t *testing.T) {
491+
// ... config steps ...
492+
493+
resource.Test(t, resource.TestCase{
494+
PreCheck: func() { skipUnauthenticated(t) },
495+
ProviderFactories: providerFactories,
496+
Steps: []resource.TestStep{
497+
{Config: configBefore},
498+
{
499+
Config: configAfter,
500+
ConfigPlanChecks: resource.ConfigPlanChecks{
501+
PreApply: []plancheck.PlanCheck{
502+
plancheck.ExpectResourceAction("github_example.test", plancheck.ResourceActionDestroyBeforeCreate),
503+
},
504+
},
470505
},
471506
},
472507
})
473508
})
474509
}
475510
```
476511

512+
> **Legacy pattern:** Existing tests may still use `Check: resource.ComposeTestCheckFunc(...)`. New tests should use `ConfigStateChecks` and `ConfigPlanChecks` instead. See `data_source_github_ip_ranges_test.go` for a real-world example.
513+
477514
### Test Modes
478515

479516
Use `skipUnauthenticated(t)`, `skipUnlessHasOrgs(t)`, `skipUnlessHasPaidOrgs(t)`, `skipUnlessEnterprise(t)`, `skipUnlessMode(t, testModes...)` functions to run tests in appropriate contexts:
@@ -537,10 +574,8 @@ The following resources are deprecated and will be removed in future versions:
537574

538575
### Pending go-github Updates
539576

540-
Several features are blocked waiting for go-github v68+:
577+
The following features are blocked waiting for upstream changes in [google/go-github#3364](https://github.com/google/go-github/issues/3364) (adds `assignment`, `parent_team_id`, `parent_team_slug` fields):
541578

542-
- `data_source_github_organization_repository_role.go:56`
543-
- `resource_github_organization_repository_role.go:102`
544579
- `data_source_github_organization_role_users.go:41`
545580
- `data_source_github_organization_role_teams.go:51`
546581

@@ -564,6 +599,10 @@ Several features are blocked waiting for go-github v68+:
564599
| `expandStringList([]any)` | Convert to `[]string` |
565600
| `flattenStringList([]string)` | Convert to `[]any` |
566601
| `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 |
567606

568607
### Naming Conventions
569608

@@ -614,6 +653,14 @@ Several features are blocked waiting for go-github v68+:
614653

615654
**Reference:** <https://github.com/integrations/terraform-provider-github/issues/2709#issuecomment-3811466444>
616655

656+
#### Migrate to `terraform-plugin-testing`
657+
658+
**Decision:** Migrate from the SDK testing package (`github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource`) to `terraform-plugin-testing` (`github.com/hashicorp/terraform-plugin-testing`). Use `ConfigStateChecks` and `ConfigPlanChecks` as the preferred assertion patterns, replacing `Check:` + `resource.ComposeTestCheckFunc`.
659+
660+
**Rationale:** `terraform-plugin-testing` is the standalone testing framework that decouples test utilities from the SDK. `ConfigStateChecks` and `ConfigPlanChecks` provide type-safe, composable assertions with better error messages.
661+
662+
**Reference:** <https://developer.hashicorp.com/terraform/plugin/testing>
663+
617664
#### No Local Git CLI Support
618665

619666
**Decision:** Do not support using local git CLI to operate on repositories; use purely API operations.

CONTRIBUTING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ Once you have the repository cloned, there's a couple of additional steps you'll
5353

5454
### Local Development Iteration
5555

56-
1. Write a test describing what you will fix. See [`github_label`](./github/resource_github_issue_label_test.go) for an example format.
57-
2. Run your test and observe it fail. Enabling debug output allows for observing the underlying requests and responses made as well as viewing state (search `STATE:`) generated during the acceptance test run.
56+
1. Write a test describing what you will fix. See [`github_ip_ranges`](./github/data_source_github_ip_ranges_test.go) for an example using the preferred `ConfigStateChecks` pattern, and [ARCHITECTURE.md](ARCHITECTURE.md#test-structure) for full guidance.
57+
2. Run your test and observe it fail. Enabling debug output allows for observing the underlying requests and responses made during the acceptance test run.
5858

5959
```sh
6060
TF_LOG=DEBUG make testacc T=TestAccGithubIssueLabel

MAINTAINERS.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,7 @@ This document lists the current maintainers of the Terraform Provider for GitHub
1717
| Name | GitHub |
1818
| --------------- | -------------------------------------------- |
1919
| Keegan Campbell | [@kfcampbell](https://github.com/kfcampbell) |
20+
21+
## Contributors
22+
23+
See the full list of contributors on [GitHub](https://github.com/integrations/terraform-provider-github/graphs/contributors).

0 commit comments

Comments
 (0)