Files
terraform-provider-artifactapi/internal/provider/provider.go
T
unkinben b26e651d45
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/pre-commit Pipeline was successful
feat: add artifactapi_remote_github_rpm resource
The artifactapi server gains a github_rpm remote type that exposes a GitHub
repo's releases as a metadata-only yum repository (synthesized repodata, no
precache, downloads redirected to a backend remote). Surface it through the
provider so these remotes are declarable as code alongside the other types.

- Register the github_rpm remote resource (artifactapi_remote_github_rpm),
  reusing the shared remoteResource plumbing; add the NewRemoteGitHubRPM
  constructor to match its siblings.
- Generalize the releases_remote attribute description: it now names the
  backend remote that serves download bytes for both the terraform remote
  (URL rewriting) and the github_rpm remote (302 redirect of .rpm downloads).
- Document the type and add an example wiring a github_rpm remote to a generic
  github.com releases_remote.

Tests cover the resource metadata type name, the constructor, and mapping of
package_type/base_url/releases_remote/patterns through the API model; the
resource-count and expected-types assertions are updated.

Depends on the github_rpm API surface in artifactapi (separate PR). Cut a
minor release (make minor) once merged.
2026-08-10 20:57:26 +10:00

86 lines
2.4 KiB
Go

package provider
import (
"context"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/provider"
"github.com/hashicorp/terraform-plugin-framework/provider/schema"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/types"
)
var _ provider.Provider = &ArtifactAPIProvider{}
type ArtifactAPIProvider struct {
version string
}
type artifactAPIProviderModel struct {
Endpoint types.String `tfsdk:"endpoint"`
}
func New(version string) func() provider.Provider {
return func() provider.Provider {
return &ArtifactAPIProvider{version: version}
}
}
func (p *ArtifactAPIProvider) Metadata(_ context.Context, _ provider.MetadataRequest, resp *provider.MetadataResponse) {
resp.TypeName = "artifactapi"
resp.Version = p.version
}
func (p *ArtifactAPIProvider) Schema(_ context.Context, _ provider.SchemaRequest, resp *provider.SchemaResponse) {
resp.Schema = schema.Schema{
Description: "Manage ArtifactAPI remotes and virtual repositories.",
Attributes: map[string]schema.Attribute{
"endpoint": schema.StringAttribute{
Description: "The ArtifactAPI server endpoint URL (e.g. https://artifactapi.example.com).",
Required: true,
},
},
}
}
func (p *ArtifactAPIProvider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) {
var config artifactAPIProviderModel
resp.Diagnostics.Append(req.Config.Get(ctx, &config)...)
if resp.Diagnostics.HasError() {
return
}
client := newAPIClient(config.Endpoint.ValueString())
resp.DataSourceData = client
resp.ResourceData = client
}
func (p *ArtifactAPIProvider) Resources(_ context.Context) []func() resource.Resource {
return []func() resource.Resource{
newRemoteResource("generic"),
newRemoteResource("docker"),
newRemoteResource("helm"),
newRemoteResource("pypi"),
newRemoteResource("npm"),
newRemoteResource("rpm"),
newRemoteResource("alpine"),
newRemoteResource("puppet"),
newRemoteResource("terraform"),
newRemoteResource("goproxy"),
newRemoteResource("github_rpm"),
NewVirtualResource,
NewLocalTerraformResource,
NewLocalPyPIResource,
NewLocalRPMResource,
NewLocalDockerResource,
NewLocalGenericResource,
}
}
func (p *ArtifactAPIProvider) DataSources(_ context.Context) []func() datasource.DataSource {
return []func() datasource.DataSource{
NewRemoteDataSource,
NewVirtualDataSource,
}
}