Skip to content

feat: add github_release_asset data source#2514

Merged
stevehipwell merged 20 commits intointegrations:mainfrom
mdb:mdb/gh-release-asset
Jan 29, 2026
Merged

feat: add github_release_asset data source#2514
stevehipwell merged 20 commits intointegrations:mainfrom
mdb:mdb/gh-release-asset

Conversation

@mdb
Copy link
Contributor

@mdb mdb commented Dec 14, 2024

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

Updated testing, per feedback from @deiga :

$ 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

Resolves #2513


Before the change?

  • The provider did not support a github_release_asset data source

After the change?

  • The provider supports a github_release_asset data source

Pull request checklist

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)

Does this introduce a breaking change?

No.

Please see our docs on breaking changes to help!

  • Yes
  • No

@mdb mdb force-pushed the mdb/gh-release-asset branch from dac6b1b to 696957f Compare December 17, 2024 13:27
@mdb mdb marked this pull request as ready for review December 17, 2024 13:28
@mdb
Copy link
Contributor Author

mdb commented May 4, 2025

Hi @lafrenierejm - This has been waiting on reviews for ~6 months. Is there anything I can do to help steward this along to get it reviewed, merged, and released?

@mdb
Copy link
Contributor Author

mdb commented May 5, 2025

Hi @kfcampbell - I believe you've merged/released other PRs. Is there anything I can do to help steward this along to get it reviewed, merged, and released? Thanks!

@mdb
Copy link
Contributor Author

mdb commented Dec 19, 2025

@deiga Given your help reviewing PR #2515, would you mind reviewing this as well? Thanks!

@deiga
Copy link
Collaborator

deiga commented Dec 20, 2025

Hey @mdb 👋

Thanks for the contribution!

The changes look good for the most part.
I have a few requests for you:

  • Could you elaborate the headers change? The comment wasn't enough for me to understand what is happening.
  • I wonder if it'd be possible to get a test for the headers change which ensures that it doesn't break any behaviour?
  • We're moving towards Context-aware provider functions, could you refactor the Schemata to use ReadContext?
  • We're also going to start using documentation generating from resource/data source Descriptions. Could you ensure that all necessary info is in the different Description fields of the Schemata?

@mdb mdb force-pushed the mdb/gh-release-asset branch 2 times, most recently from 9b364b5 to 2407ae3 Compare December 21, 2025 11:58
mdb added a commit to mdb/terraform-provider-github that referenced this pull request Dec 21, 2025
Per request of @deiga (integrations#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 <mikedball@gmail.com>
@mdb
Copy link
Contributor Author

mdb commented Dec 21, 2025

Thanks for the quick response @deiga !

  • Could you elaborate the headers change? The comment wasn't enough for me to understand what is happening.

I've added a comment linking to corresponding context over in google/go-github#3392 (and note that this is fixed in go-github/v68 (Admittedly, this is all a bit foggy for me -- it's been over a year since I opened this PR as well as since I opened google/go-github#3392)).

  • I wonder if it'd be possible to get a test for the headers change which ensures that it doesn't break any behaviour?

I added unit tests. Does that address your concern?

  • We're moving towards Context-aware provider functions, could you refactor the Schemata to use ReadContext?

Done!

  • We're also going to start using documentation generating from resource/data source Descriptions. Could you ensure that all necessary info is in the different Description fields of the Schemata?

Done!

@mdb
Copy link
Contributor Author

mdb commented Jan 4, 2026

@deiga 👋 Gentle nudge! Have I addressed your concerns in the response above?

@deiga
Copy link
Collaborator

deiga commented Jan 5, 2026

@mdb Thanks for the changes! These look good!

I realized that this PR won't land at least before v6.10.0 and there is a major test refactor coming in there. Would you be available to rebase on top of #2986 and conform your TestAcc* with those changes?

mdb added a commit to mdb/terraform-provider-github that referenced this pull request Jan 8, 2026
Per request of @deiga (integrations#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 <mikedball@gmail.com>
@mdb mdb force-pushed the mdb/gh-release-asset branch from d5e51a6 to 0cdd8e1 Compare January 8, 2026 14:38
mdb added a commit to mdb/terraform-provider-github that referenced this pull request Jan 8, 2026
Per code review feedback from @deiga (integrations#2514 (comment)),
this updates the github_release_asset data source tests to use the new
testing patterns implemented in integrations#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 <mikedball@gmail.com>
@mdb
Copy link
Contributor Author

mdb commented Jan 8, 2026

@mdb Thanks for the changes! These look good!

I realized that this PR won't land at least before v6.10.0 and there is a major test refactor coming in there. Would you be available to rebase on top of #2986 and conform your TestAcc* with those changes?

@deiga Thanks! I pushed a commit doing so. How's that look?

mdb added a commit to mdb/terraform-provider-github that referenced this pull request Jan 8, 2026
Per request of @deiga (integrations#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 <mikedball@gmail.com>
mdb added a commit to mdb/terraform-provider-github that referenced this pull request Jan 8, 2026
Per code review feedback from @deiga (integrations#2514 (comment)),
this updates the github_release_asset data source tests to use the new
testing patterns implemented in integrations#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 <mikedball@gmail.com>
@mdb mdb force-pushed the mdb/gh-release-asset branch from 0cdd8e1 to 102ba5d Compare January 8, 2026 14:40
mdb added a commit to mdb/terraform-provider-github that referenced this pull request Jan 9, 2026
Per request of @deiga (integrations#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 <mikedball@gmail.com>
mdb added a commit to mdb/terraform-provider-github that referenced this pull request Jan 9, 2026
Per code review feedback from @deiga (integrations#2514 (comment)),
this updates the github_release_asset data source tests to use the new
testing patterns implemented in integrations#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 <mikedball@gmail.com>
@mdb mdb force-pushed the mdb/gh-release-asset branch from 102ba5d to 83ab3d7 Compare January 9, 2026 13:12
@mdb mdb requested a review from deiga January 9, 2026 13:12
Copy link
Collaborator

@deiga deiga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! @stevehipwell what do you think about the test variable additions?

Copy link
Collaborator

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR @mdb, I've added some review comments.

@github-project-automation github-project-automation bot moved this from 👀 In review to 🏗 In progress in 🧰 Octokit Active Jan 12, 2026
mdb added a commit to mdb/terraform-provider-github that referenced this pull request Jan 12, 2026
Per request of @deiga (integrations#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 <mikedball@gmail.com>
@mdb mdb requested a review from stevehipwell January 27, 2026 18:16
@stevehipwell
Copy link
Collaborator

@mdb it looks like you've got failing tests.

@mdb
Copy link
Contributor Author

mdb commented Jan 28, 2026

@mdb it looks like you've got failing tests.

@stevehipwell Doh, thanks! I've pushed a fix.

Copy link
Collaborator

@stevehipwell stevehipwell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@stevehipwell
Copy link
Collaborator

@mdb could you please rebase this so we can get it merged?

mdb added 20 commits January 29, 2026 08:04
This addresses issue integrations#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 <mikedball@gmail.com>
Per request of @deiga (integrations#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 <mikedball@gmail.com>
Per code review feedback from @deiga (integrations#2514 (comment)),
this updates the github_release_asset data source tests to use the new
testing patterns implemented in integrations#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 <mikedball@gmail.com>
…l pattern

Per code review feedback (integrations#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 <mikedball@gmail.com>
Use idiomatic `:=` pattern over `var`-pre-defined variables, per
code review feedback from @stevehipwell:

integrations#2514 (comment)

Signed-off-by: Mike Ball <mikedball@gmail.com>
…Func

This inlines `resource.ComposeTestCheckFunc` to improve readability
(rather than define it as a variable), per code review feedback from @stevehipwell:

integrations#2514 (comment)

Signed-off-by: Mike Ball <mikedball@gmail.com>
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 <mikedball@gmail.com>
…Providers

Per code review feedback from @deiga, this removes unnecessary Providers
configuration from the data_source_github_release_asset tests.

integrations#2514 (comment)

Signed-off-by: Mike Ball <mikedball@gmail.com>
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:

integrations#2514 (comment)

Signed-off-by: Mike Ball <mikedball@gmail.com>
Per code review feedback from @stevehipwell (integrations#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 <mikedball@gmail.com>
This fixes a copy/paste bug; updated_at is now correctly set on the data source.

Signed-off-by: Mike Ball <mikedball@gmail.com>
Per code review feedback from @stevehipwell (integrations#2514 (review)),
this makes the release asset download optional, controlled by a `download_body`
attribute, and off by default.

Signed-off-by: Mike Ball <mikedball@gmail.com>
…ttributes

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:
integrations#2514 (comment)

Signed-off-by: Mike Ball <mikedball@gmail.com>
Per code review feedback from @stevehipwell
(integrations#2514 (comment)),
this ensures `file` is base64-encoded.

Signed-off-by: Mike Ball <mikedball@gmail.com>
Per code review feedback from @stevehipwell, this changes `download_file`/`file`
to `download_file_contents`/`file_contents`, respectively:
integrations#2514 (comment)

Signed-off-by: Mike Ball <mikedball@gmail.com>
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: integrations#2514 (comment)

Signed-off-by: Mike Ball <mikedball@gmail.com>
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 <mikedball@gmail.com>
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 <mikedball@gmail.com>
@mdb
Copy link
Contributor Author

mdb commented Jan 29, 2026

@mdb could you please rebase this so we can get it merged?

@stevehipwell Done!

Copy link

@felipebraga felipebraga left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll open a new PR removing it.

return diag.FromErr(err)
}

req.Header.Set("Accept", "application/octet-stream")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set and Accept header causes the http request to return 406 Not Acceptable.

req.Header.Set("Accept", "application/octet-stream")

Suggested change
req.Header.Set("Accept", "application/octet-stream")

repository = "example-repository"
owner = "example-owner"
asset_id = 12345
download_file = true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
download_file = true
download_file_contents = true

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

New data source Type: Feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEAT]: Support github_release_asset data source

5 participants