Files
terraform-provider-artifactapi/internal/provider/provider.go
T
unkinben 2653c34f94
ci/woodpecker/push/build Pipeline was successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
feat: add artifactapi_local_terraform resource type
New resource for creating local terraform registries in ArtifactAPI
(repo_type=local, package_type=terraform). These repos host providers
directly rather than proxying an upstream registry.

Schema is minimal: just name and description — no upstream-specific
fields like base_url, caching TTLs, or auth.
2026-06-22 23:30:21 +10:00

81 lines
2.3 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"),
NewVirtualResource,
NewLocalTerraformResource,
}
}
func (p *ArtifactAPIProvider) DataSources(_ context.Context) []func() datasource.DataSource {
return []func() datasource.DataSource{
NewRemoteDataSource,
NewVirtualDataSource,
}
}