diff options
author | Julien Dessaux | 2023-06-18 00:31:32 +0200 |
---|---|---|
committer | Julien Dessaux | 2023-06-18 00:31:32 +0200 |
commit | 3d60272592090125f0ea4a9a9fa2df7470c88e34 (patch) | |
tree | bb558e03b12c71e37e130c6b618f87bf3d8d689c /internal/provider/provider.go | |
parent | Initial import (diff) | |
download | terraform-provider-eventline-3d60272592090125f0ea4a9a9fa2df7470c88e34.tar.gz terraform-provider-eventline-3d60272592090125f0ea4a9a9fa2df7470c88e34.tar.bz2 terraform-provider-eventline-3d60272592090125f0ea4a9a9fa2df7470c88e34.zip |
Implemented projects datasource
Diffstat (limited to '')
-rw-r--r-- | internal/provider/provider.go | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/internal/provider/provider.go b/internal/provider/provider.go new file mode 100644 index 0000000..c29a915 --- /dev/null +++ b/internal/provider/provider.go @@ -0,0 +1,80 @@ +package provider + +import ( + "context" + "fmt" + + "git.adyxax.org/adyxax/terraform-eventline/internal/evcli" + "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" +) + +type Provider struct { + version string +} + +var _ provider.Provider = &Provider{} // Ensure provider defined types fully satisfy framework interfaces. +func New(version string) func() provider.Provider { + return func() provider.Provider { + return &Provider{ + version: version, + } + } +} + +type ProviderModel struct { + ApiKey types.String `tfsdk:"api_key"` + Endpoint types.String `tfsdk:"endpoint"` +} + +func (p *Provider) Metadata(ctx context.Context, req provider.MetadataRequest, resp *provider.MetadataResponse) { + resp.TypeName = "eventline" + resp.Version = p.version +} + +func (p *Provider) Schema(ctx context.Context, req provider.SchemaRequest, resp *provider.SchemaResponse) { + resp.Schema = schema.Schema{ + Attributes: map[string]schema.Attribute{ + "api_key": schema.StringAttribute{ + MarkdownDescription: "Eventline's api key", + Required: true, + Sensitive: true, + }, + "endpoint": schema.StringAttribute{ + MarkdownDescription: "Eventline's HTTP endpoint", + Required: true, + }, + }, + } +} + +func (p *Provider) Configure(ctx context.Context, req provider.ConfigureRequest, resp *provider.ConfigureResponse) { + var data ProviderModel + resp.Diagnostics.Append(req.Config.Get(ctx, &data)...) + if resp.Diagnostics.HasError() { + return + } + config := evcli.Config{API: evcli.APIConfig{Endpoint: data.Endpoint.ValueString()}} + client, err := evcli.NewClient(&config) + if err != nil { + resp.Diagnostics.AddError("new api client", fmt.Sprintf("Unable to instanciate eventline api client, got error: %s", err)) + return + } + client.APIKey = data.ApiKey.ValueString() + + resp.DataSourceData = client + resp.ResourceData = client +} + +func (p *Provider) Resources(ctx context.Context) []func() resource.Resource { + return []func() resource.Resource{} +} + +func (p *Provider) DataSources(ctx context.Context) []func() datasource.DataSource { + return []func() datasource.DataSource{ + NewProjectsDataSource, + } +} |