Skip to content

[FEAT]: Support github_release_asset data source #2513

@mdb

Description

@mdb

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Status: TriageThis is being looked at and prioritizedType: FeatureNew feature or request

    Type

    No type

    Projects

    Status

    ✅ Done

    Status

    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions