Commit ff4889f
authored
feat: add github_release_asset data source (#2514)
* feat: add github_release_asset data source
This addresses issue #2513 and adds support for a `github_release_asset`
data source.
Example of passing acceptance tests:
```
GITHUB_ORGANIZATION=mterwill \
GITHUB_OWNER=mterwill \
TF_ACC=1 \
go test -v ./... -run ^TestAccGithubReleaseAssetDataSource
? github.com/integrations/terraform-provider-github/v6 [no test files]
=== RUN TestAccGithubReleaseAssetDataSource
=== RUN TestAccGithubReleaseAssetDataSource/queries_specified_asset_ID
=== RUN TestAccGithubReleaseAssetDataSource/queries_specified_asset_ID/with_an_anonymous_account
provider_utils.go:51: GITHUB_TOKEN environment variable should be empty
provider_utils.go:74: Skipping TestAccGithubReleaseAssetDataSource/queries_specified_asset_ID/with_an_anonymous_account which requires anonymous mode
=== RUN TestAccGithubReleaseAssetDataSource/queries_specified_asset_ID/with_an_individual_account
=== RUN TestAccGithubReleaseAssetDataSource/queries_specified_asset_ID/with_an_organization_account
--- PASS: TestAccGithubReleaseAssetDataSource (11.65s)
--- PASS: TestAccGithubReleaseAssetDataSource/queries_specified_asset_ID (11.65s)
--- SKIP: TestAccGithubReleaseAssetDataSource/queries_specified_asset_ID/with_an_anonymous_account (0.00s)
--- PASS: TestAccGithubReleaseAssetDataSource/queries_specified_asset_ID/with_an_individual_account (8.90s)
--- PASS: TestAccGithubReleaseAssetDataSource/queries_specified_asset_ID/with_an_organization_account (2.75s)
PASS
ok github.com/integrations/terraform-provider-github/v6/github 12.434s
```
Signed-off-by: Mike Ball <[email protected]>
* chore(config): test previewHeaderInjectorTransport.RoundTrip
Per request of @deiga (#2514 (comment)),
this adds tests for previewHeaderInjectorTransport.RoundTrip logic
around application/octest-stream header handling.
See google/go-github#3392 for context.
Signed-off-by: Mike Ball <[email protected]>
* chore: github_release_asset data source tests use new test patterns
Per code review feedback from @deiga (#2514 (comment)),
this updates the github_release_asset data source tests to use the new
testing patterns implemented in #2986
This was tested via:
```
$ TF_ACC=1 \
go test -v ./... -run ^TestAccGithubReleaseAssetDataSource
? github.com/integrations/terraform-provider-github/v6 [no test files]
=== RUN TestAccGithubReleaseAssetDataSource
=== RUN TestAccGithubReleaseAssetDataSource/queries_specified_asset_ID
--- PASS: TestAccGithubReleaseAssetDataSource (5.91s)
--- PASS: TestAccGithubReleaseAssetDataSource/queries_specified_asset_ID (5.91s)
PASS
ok github.com/integrations/terraform-provider-github/v6/github 6.788s
```
Signed-off-by: Mike Ball <[email protected]>
* chore(data_source_github_release_asset): use if err := ...; err != nil pattern
Per code review feedback (#2514 (comment)) from @stevehipwell, this tweaks the
`data_source_github_release_asset` to use the `if err := ...; err != nil` pattern
towards the goal of improving readability.
Signed-off-by: Mike Ball <[email protected]>
* chore(data_source_github_release_asset): improve terseness
Use idiomatic `:=` pattern over `var`-pre-defined variables, per
code review feedback from @stevehipwell:
#2514 (comment)
Signed-off-by: Mike Ball <[email protected]>
* chore(data_source_github_release_asset_test): inline ComposeTestCheckFunc
This inlines `resource.ComposeTestCheckFunc` to improve readability
(rather than define it as a variable), per code review feedback from @stevehipwell:
#2514 (comment)
Signed-off-by: Mike Ball <[email protected]>
* chore(data_source_github_release_asset): source config from acc_test.go
Per code review feedback from @stevehipwell, this simplifies test
configuration:
- source test configuration from `testAccConf`, as done elsewhere
- remove the ability to override test configuration via `GH_TEST_*` env vars;
this is arguably premature optimization and can be added to `acc_test.go` if
it's needed in the future
Signed-off-by: Mike Ball <[email protected]>
* chore(data_source_github_release_asset): remove unnecessary TestCase.Providers
Per code review feedback from @deiga, this removes unnecessary Providers
configuration from the data_source_github_release_asset tests.
#2514 (comment)
Signed-off-by: Mike Ball <[email protected]>
* fix(data_source_github_release_asset): use composite ID
To protect against the possibility that release asset IDs are not
globally unique across GitHub, this configures the use of a 3-part
composite ID when tracking `data_source_github_release_asset` instances
in TF state.
This addresses code review feedback from @deiga:
#2514 (comment)
Signed-off-by: Mike Ball <[email protected]>
* fix(data_source_github_release_asset): avoid client mutation
Per code review feedback from @stevehipwell (#2514 (comment)),
this avoids the use of `client.Repositories.DownloadReleaseAsset` out of
concern the function modifies the GitHub client state which could cause
unexpected behaviour in Terraform.
Signed-off-by: Mike Ball <[email protected]>
* fix(data_source_github_release_asset): properly set updated_at
This fixes a copy/paste bug; updated_at is now correctly set on the data source.
Signed-off-by: Mike Ball <[email protected]>
* feat(data_source_github_release_asset): make download configurable
Per code review feedback from @stevehipwell (#2514 (review)),
this makes the release asset download optional, controlled by a `download_body`
attribute, and off by default.
Signed-off-by: Mike Ball <[email protected]>
* chore(data_source_github_release_asset): use `download_file`/`file` attributes
Replace `download_body` argument and `body` attributes w/ `download_file`/`file`,
respectively, towards the goal of improving the data source interface.
This addresses code review feedback from @stevehipwell:
#2514 (comment)
Signed-off-by: Mike Ball <[email protected]>
* fix(data_source_github_release_asset): base64 encode `file`
Per code review feedback from @stevehipwell
(#2514 (comment)),
this ensures `file` is base64-encoded.
Signed-off-by: Mike Ball <[email protected]>
* chore(data_source_github_release_asset): adjust file contents attributes
Per code review feedback from @stevehipwell, this changes `download_file`/`file`
to `download_file_contents`/`file_contents`, respectively:
#2514 (comment)
Signed-off-by: Mike Ball <[email protected]>
* chore(data_source_github_release_asset): improve acc test
This improves the `data_source_github_release_asset` acceptance tests to
be more TF-focused via use of the `base64decode` function, per code
review request of @stevehipwell: #2514 (comment)
Signed-off-by: Mike Ball <[email protected]>
* chore(data_source_github_release_asset_test): appease linting
This commits the result of `gofumpt`, as per lint failures in:
https://github.com/integrations/terraform-provider-github/actions/runs/21232219897/job/61621068985?pr=2514
Signed-off-by: Mike Ball <[email protected]>
* chore(config_test): appease lint errors
This appeases lint warnings in `github/config_test.go`:
https://github.com/integrations/terraform-provider-github/actions/runs/21232219897/job/61621068985?pr=2514
Signed-off-by: Mike Ball <[email protected]>
* chore(config): address staticcheck errors
This addresses the following staticcheck error (seen in https://github.com/integrations/terraform-provider-github/actions/runs/21232219897/job/61621068985?pr=2514):
```
Error: github/config.go:196:13: QF1001: could apply De Morgan's law (staticcheck)
```
Signed-off-by: Mike Ball <[email protected]>
* fix(config_test): use canonical HTTP header names in expectedHeaders
Go's http.Header canonicalizes header names (e.g., X-GitHub-Api-Version
becomes X-Github-Api-Version). The test's unexpected header check was
failing because it compared canonical names against non-canonical keys
in the expectedHeaders map.
Signed-off-by: Mike Ball <[email protected]>
---------
Signed-off-by: Mike Ball <[email protected]>1 parent d1de3e9 commit ff4889f
7 files changed
Lines changed: 585 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
49 | 49 | | |
50 | 50 | | |
51 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
52 | 55 | | |
53 | 56 | | |
54 | 57 | | |
| |||
105 | 108 | | |
106 | 109 | | |
107 | 110 | | |
108 | | - | |
109 | | - | |
110 | | - | |
111 | | - | |
112 | | - | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
113 | 121 | | |
114 | 122 | | |
115 | 123 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
189 | 189 | | |
190 | 190 | | |
191 | 191 | | |
192 | | - | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
193 | 197 | | |
194 | 198 | | |
195 | 199 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
| |||
300 | 302 | | |
301 | 303 | | |
302 | 304 | | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
| 447 | + | |
| 448 | + | |
| 449 | + | |
| 450 | + | |
| 451 | + | |
| 452 | + | |
| 453 | + | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
| 459 | + | |
| 460 | + | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
| 475 | + | |
| 476 | + | |
| 477 | + | |
| 478 | + | |
| 479 | + | |
| 480 | + | |
| 481 | + | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
| 492 | + | |
| 493 | + | |
| 494 | + | |
| 495 | + | |
| 496 | + | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
0 commit comments