Add artifactapi_remote_github_deb resource
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful

Add the metadata-only Debian/apt analog of artifactapi_remote_github_rpm,
exposing a GitHub repo's release .deb assets as a synthesized apt repository
with downloads redirected to a backing releases_remote.

- Register newRemoteResource("github_deb") and add NewRemoteGitHubDeb ctor
- Bump provider resource count 19 -> 20 and add the type name to test lists
- Add modelToAPI/metadata/constructor test coverage for github_deb
- Document github_deb in README and add an examples/ main.tf (goodtune/ghp)
This commit is contained in:
2026-08-11 22:12:10 +10:00
parent 5ee3a1d3d6
commit 25b72fd1ac
6 changed files with 96 additions and 5 deletions
+1
View File
@@ -69,6 +69,7 @@ func (p *ArtifactAPIProvider) Resources(_ context.Context) []func() resource.Res
newRemoteResource("terraform"),
newRemoteResource("goproxy"),
newRemoteResource("github_rpm"),
newRemoteResource("github_deb"),
NewVirtualResource,
NewLocalTerraformResource,
NewLocalPyPIResource,
+3 -2
View File
@@ -66,8 +66,8 @@ func TestProvider_Resources(t *testing.T) {
p := &ArtifactAPIProvider{version: "1.0.0"}
resources := p.Resources(context.Background())
// 12 remote resource types + 1 virtual + local_terraform/pypi/rpm/deb/docker/generic = 19
expectedCount := 19
// 13 remote resource types + 1 virtual + local_terraform/pypi/rpm/deb/docker/generic = 20
expectedCount := 20
if len(resources) != expectedCount {
t.Fatalf("expected %d resources, got %d", expectedCount, len(resources))
}
@@ -108,6 +108,7 @@ func TestProvider_Resources_ContainsExpectedTypes(t *testing.T) {
"artifactapi_remote_terraform",
"artifactapi_remote_goproxy",
"artifactapi_remote_github_rpm",
"artifactapi_remote_github_deb",
"artifactapi_virtual",
"artifactapi_local_terraform",
"artifactapi_local_pypi",
+2 -1
View File
@@ -68,6 +68,7 @@ func NewRemotePuppet() resource.Resource { return &remoteResource{packageType
func NewRemoteTerraform() resource.Resource { return &remoteResource{packageType: "terraform"} }
func NewRemoteGoProxy() resource.Resource { return &remoteResource{packageType: "goproxy"} }
func NewRemoteGitHubRPM() resource.Resource { return &remoteResource{packageType: "github_rpm"} }
func NewRemoteGitHubDeb() resource.Resource { return &remoteResource{packageType: "github_deb"} }
func (r *remoteResource) Metadata(_ context.Context, req resource.MetadataRequest, resp *resource.MetadataResponse) {
resp.TypeName = req.ProviderTypeName + "_remote_" + r.packageType
@@ -147,7 +148,7 @@ func (r *remoteResource) Schema(_ context.Context, _ resource.SchemaRequest, res
ElementType: types.StringType,
},
"releases_remote": schema.StringAttribute{
Description: "Name of a backend remote that serves the actual download bytes. Used by the terraform remote (download URL rewriting) and the github_rpm remote (302 redirect of .rpm downloads to a generic github.com remote).",
Description: "Name of a backend remote that serves the actual download bytes. Used by the terraform remote (download URL rewriting) and the github_rpm/github_deb remotes (302 redirect of .rpm/.deb downloads to a generic github.com remote).",
Optional: true, Computed: true, Default: stringdefault.StaticString(""),
},
"upstream_dial_timeout": schema.Int64Attribute{
+30
View File
@@ -410,6 +410,7 @@ func TestRemoteResource_Metadata(t *testing.T) {
{"pypi", "artifactapi_remote_pypi"},
{"npm", "artifactapi_remote_npm"},
{"github_rpm", "artifactapi_remote_github_rpm"},
{"github_deb", "artifactapi_remote_github_deb"},
}
for _, tt := range tests {
@@ -453,6 +454,34 @@ func TestModelToAPI_GitHubRPM(t *testing.T) {
}
}
func TestModelToAPI_GitHubDeb(t *testing.T) {
ctx := context.Background()
r := &remoteResource{packageType: "github_deb"}
model := remoteResourceModel{
Name: types.StringValue("acme-tools"),
BaseURL: types.StringValue("https://api.github.com/repos/acme/tools"),
ReleasesRemote: types.StringValue("github"),
MutableTTL: types.Int64Value(3600),
Patterns: stringsToList(ctx, []string{`.*_amd64\.deb$`}),
}
api := r.modelToAPI(ctx, model)
if api.PackageType != "github_deb" {
t.Errorf("PackageType: expected github_deb, got %s", api.PackageType)
}
if api.BaseURL != "https://api.github.com/repos/acme/tools" {
t.Errorf("BaseURL: got %s", api.BaseURL)
}
if api.ReleasesRemote != "github" {
t.Errorf("ReleasesRemote: expected github, got %s", api.ReleasesRemote)
}
if len(api.Patterns) != 1 || api.Patterns[0] != `.*_amd64\.deb$` {
t.Errorf("Patterns: got %v", api.Patterns)
}
}
func TestRemoteResource_Schema(t *testing.T) {
r := &remoteResource{packageType: "docker"}
req := resource.SchemaRequest{}
@@ -493,6 +522,7 @@ func TestNewRemoteResource_Constructors(t *testing.T) {
{"terraform", func() resource.Resource { return NewRemoteTerraform() }, "terraform"},
{"goproxy", func() resource.Resource { return NewRemoteGoProxy() }, "goproxy"},
{"github_rpm", func() resource.Resource { return NewRemoteGitHubRPM() }, "github_rpm"},
{"github_deb", func() resource.Resource { return NewRemoteGitHubDeb() }, "github_deb"},
}
for _, tt := range tests {