2023-06-18 00:31:32 +02:00
|
|
|
package provider
|
|
|
|
|
|
|
|
import (
|
|
|
|
"context"
|
|
|
|
"fmt"
|
|
|
|
|
2023-06-19 00:05:58 +02:00
|
|
|
"git.adyxax.org/adyxax/terraform-provider-eventline/external/evcli"
|
2023-06-18 00:31:32 +02:00
|
|
|
"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
|
|
|
|
}
|
2023-06-18 17:41:38 +02:00
|
|
|
config := evcli.APIConfig{Endpoint: data.Endpoint.ValueString(), Key: data.ApiKey.ValueString()}
|
2023-06-18 00:31:32 +02:00
|
|
|
client, err := evcli.NewClient(&config)
|
|
|
|
if err != nil {
|
2023-06-19 00:14:41 +02:00
|
|
|
resp.Diagnostics.AddError("new api client", fmt.Sprintf("Unable to instantiate eventline api client, got error: %s", err))
|
2023-06-18 00:31:32 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
resp.DataSourceData = client
|
|
|
|
resp.ResourceData = client
|
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Provider) Resources(ctx context.Context) []func() resource.Resource {
|
2023-06-18 17:01:35 +02:00
|
|
|
return []func() resource.Resource{
|
2023-09-24 01:23:50 +02:00
|
|
|
NewIdentityResource,
|
2023-06-18 17:01:35 +02:00
|
|
|
NewProjectResource,
|
|
|
|
}
|
2023-06-18 00:31:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
func (p *Provider) DataSources(ctx context.Context) []func() datasource.DataSource {
|
|
|
|
return []func() datasource.DataSource{
|
2023-07-31 00:31:43 +02:00
|
|
|
NewIdentitiesDataSource,
|
2023-06-25 00:33:39 +02:00
|
|
|
NewJobsDataSource,
|
2023-08-01 00:32:23 +02:00
|
|
|
NewProjectDataSource,
|
2023-06-18 00:31:32 +02:00
|
|
|
NewProjectsDataSource,
|
|
|
|
}
|
|
|
|
}
|