Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEAT]: Support github_release_asset data source #2513

Open
1 task done
mdb opened this issue Dec 13, 2024 · 0 comments · May be fixed by #2514
Open
1 task done

[FEAT]: Support github_release_asset data source #2513

mdb opened this issue Dec 13, 2024 · 0 comments · May be fixed by #2514
Labels
Status: Triage This is being looked at and prioritized Type: Feature New feature or request

Comments

@mdb
Copy link
Contributor

mdb commented Dec 13, 2024

Describe the need

A github_release_asset data source would enable users to natively fetch and/or read GitHub release assets in Terraform.

For example, imagine a owner/repo GitHub release with various *.json file assets. To read those *.json files' contents via a github_release_asset data source, I'm imagining something akin to the following (although, it would be useful to support additional/alternative arguments beyond just id too, and perhaps even the option to download the asset):

data "github_release" "latest" {
  repository  = "owner"
  owner       = "repo"
  retrieve_by = "latest"
}

data "github_release_asset" "release_assets" {
  count = length(data.github_release.latest.assets)
  url   = data.github_release.latest.assets[count.index].url
}

output "release_assets" {
  value = data.github_release_asset.release_assets.*.body
}

However, currently, without a github_release_asset data source, it's necessary to utilize suboptimal workarounds, such as the use of the http provider and some not-ideal mechanism (such as a var.github_token) for providing a GitHub token:

data "github_release" "latest" {
  repository  = "owner"
  owner       = "repo"
  retrieve_by = "latest"
}

data "http" "release_assets" {
  count = length(data.github_release.latest.assets)
  url   = data.github_release.latest.assets[count.index].url

  request_headers = {
    Accept        = "application/octet-stream"
    Authorization = "Bearer ${var.github_token}"
  }
}

output "release_assets" {
  value = data.http.release_assets.*.body
}

Note that, in addition to requiring the use of an additional provider (i.e. the http provider), the use of the var.github_token creates a few complications:

  1. It's necessary to ensure it's not printed in plain text in logs, Terraform state, etc.
  2. If its value is generated dynamically via a GitHub app -- and if plan and apply are divided across distinct phases run on different CI/CD compute infrastructure, each with their own distinct var.github_token-generation -- then the token's value can change across each phase, resulting in Error: Can't change variable when applying a saved plan during apply.

So, a github_release_asset data source would be very helpful!

SDK Version

No response

API Version

No response

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@mdb mdb added Status: Triage This is being looked at and prioritized Type: Feature New feature or request labels Dec 13, 2024
mdb added a commit to mdb/terraform-provider-github that referenced this issue Dec 14, 2024
This addresses issue integrations#2513 and adds support for a `github_release_asset`
data source.

Example of passing acceptance tests:

```
$ GITHUB_ORGANIZATION=mdb GITHUB_OWNER=mdb
GITHUB_TEMPLATE_REPOSITORY=terraputs
GITHUB_TEMPLATE_REPOSITORY_RELEASE_ASSET_ID=206493547
GITHUB_TEMPLATE_REPOSITORY_RELEASE_ASSET_NAME=checksums.txt 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 (5.20s)
    --- PASS:
TestAccGithubReleaseAssetDataSource/queries_specified_asset_ID (5.20s)
        --- SKIP:
TestAccGithubReleaseAssetDataSource/queries_specified_asset_ID/with_an_anonymous_account
(0.00s)
        --- PASS:
TestAccGithubReleaseAssetDataSource/queries_specified_asset_ID/with_an_individual_account
(2.57s)
        --- PASS:
TestAccGithubReleaseAssetDataSource/queries_specified_asset_ID/with_an_organization_account
(2.62s)
PASS
ok      github.com/integrations/terraform-provider-github/v6/github
5.688s
```

Signed-off-by: Mike Ball <[email protected]>
@mdb mdb linked a pull request Dec 14, 2024 that will close this issue
4 tasks
mdb added a commit to mdb/terraform-provider-github that referenced this issue Dec 17, 2024
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 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Triage This is being looked at and prioritized Type: Feature New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant